-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocket_utils.h
executable file
·93 lines (71 loc) · 1.5 KB
/
socket_utils.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef SOCK_UTILS
#define SOCK_UTILS
#define BUFFER_SIZE _IO_BUFSIZ
#define ADDR_SIZE 256
#define INF_TRUE 1
#include <libaio.h>
enum socket_state {
IDLE,
RECEIVED,
HEADER,
STATIC_FILE,
DYNAMIC_FILE,
PHP_PROCESS_START,
PHP_FINISHED_EXECUTION,
PREP_ASYNC_READ,
READ_DYNAMIC_CHUNK,
SEND_DYNAMIC_CHUNK,
FINISHED
};
enum fd_type {
STATIC,
DYNAMIC,
NOT_FOUND
};
enum connection_state {
STATE_DATA_RECEIVED,
STATE_DATA_SENT,
STATE_CONNECTION_CLOSED
};
enum http_status {
HTTP200,
HTTP404
};
enum request_method {
GET_REQUEST,
POST_REQUEST
};
struct as_connection {
int conn_socket;
char recv_buff[BUFFER_SIZE];
size_t recv_size;
size_t to_read;
char request[BUFFER_SIZE];
size_t req_size;
char conn_addr[ADDR_SIZE];
char resource_path[BUFFER_SIZE];
char *received_body;
int fd;
size_t file_size;
size_t sent_size;
enum fd_type fdtype;
enum http_status http_stat;
enum socket_state sock_state;
enum connection_state state;
enum request_method req_method;
int evfd;
int sigfd;
io_context_t ctx;
struct iocb io;
};
int as_create_socketfd(int, int);
struct as_connection* as_connection_create(int);
void as_connection_handler(int);
void as_client_request_handler(struct as_connection*);
void as_client_response_handler(struct as_connection*);
static inline int min(int a, int b) {
if (a > b)
return b;
return a;
}
#endif