-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_machine.h
64 lines (51 loc) · 1.7 KB
/
state_machine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* State machine
This is where everything happens from the connection stablishment through its
end. Every IO event (i.e., reading the queues, receiving an AMQP message from
the client or sending an AMQP to the client) leads to change the state from one
state to another, depending on what happened.
The first state is WAIT, where the state machine waits for the protocol header.
The last states are FINISHED or FAIL, depending if the execution went well or
not.
*/
#pragma once
#include <pthread.h>
#include "queue_pool.h"
/* State machine states. */
typedef enum machine_state {
/* Connection opening and closing states */
WAIT,
HEADER_RECEIVED,
WAIT_START_OK,
START_OK_RECEIVED,
WAIT_TUNE_OK,
WAIT_OPEN_CONNECTION,
OPEN_CONNECTION_RECEIVED,
CLOSE_CONNECTION_RECEIVED,
/* Channel opening and closing states */
WAIT_OPEN_CHANNEL,
OPEN_CHANNEL_RECEIVED,
CLOSE_CHANNEL_RECEIVED,
/* Functional states */
WAIT_FUNCTIONAL,
QUEUE_DECLARE_RECEIVED,
/* Publish states */
BASIC_PUBLISH_RECEIVED,
WAIT_PUBLISH_CONTENT_HEADER,
WAIT_PUBLISH_CONTENT,
/* Consume states */
BASIC_CONSUME_RECEIVED,
WAIT_VALUE_DEQUEUE,
VALUE_DEQUEUE_RECEIVED,
WAIT_CONSUME_ACK,
/* Finish states */
FINISHED,
FAIL,
/* This is not actually a state, but a constant that its value is the number
of state.
*/
NUM_STATES
} machine_state;
/* This is the main function for each connection. connfd is the file descriptor
of the socket of the connection, thread_id is the id of the current thread
and q_pool is the queue pool shared between connections. */
void state_machine_main(int connfd, int thread_id, queue_pool *q_pool);