-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnection.c
57 lines (51 loc) · 1.4 KB
/
connection.c
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
#include "mimino.h"
#include "connection.h"
#include "http.h"
Connection
make_connection(int fd, Server *s, nfds_t i)
{
return (Connection) {
.fd = fd,
.pollfd = s->queue.pollfds + i,
.state = CONN_STATE_READING,
.req = NULL,
.res = NULL,
.read_tries_left = 5,
.write_tries_left = 5,
.keep_alive = 1,
.last_active = s->time_now,
};
}
void
free_connection_parts(Connection *conn)
{
if (!conn) return;
free_http_request(conn->req);
free_http_response(conn->res);
//free(conn);
}
void
print_connection(struct pollfd *pfd, Connection *conn)
{
if (!conn) {
printf("(Connection) NULL\n");
return;
}
printf("(struct pollfd) {\n");
printf(" .fd = %d,\n", pfd->fd);
printf(" .events = %0X,\n", pfd->events);
printf(" .revents = %0X,\n", pfd->revents);
printf("}\n");
printf("(Connection) {\n");
printf(" .fd = %i,\n", conn->fd);
printf(" .state = %i,\n", conn->state);
printf(" .read_tries_left = %d,\n", conn->read_tries_left);
printf(" .write_tries_left = %d,\n", conn->write_tries_left);
printf(" .keep_alive = %d,\n", conn->keep_alive);
printf(" .last_active = %ld,\n", (long) conn->last_active);
printf(" .req = ");
print_http_request(stdout, conn->req);
printf(" .res = \n");
print_http_response(stdout, conn->res);
printf("}\n");
}