-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent.c
99 lines (83 loc) · 2.11 KB
/
event.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
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
94
95
96
97
#include <stdlib.h>
#include <event.h>
#include "type.h"
#include "debug.h"
#include "event.h"
#include "fcgi.h"
static void buf_read_callback (struct bufferevent* incoming, void* arg);
static void buf_write_callback (struct bufferevent* bev, void* arg);
static void buf_error_callback (struct bufferevent* bev, short what, void* arg);
void
accept_callback (int fd, short ev, void* arg)
{
int client_fd;
struct sockaddr_in client_addr;
socklen_t client_len = sizeof client_addr;
struct fcgi* client;
printf ("a\n");
client_fd = accept (fd, (struct sockaddr*) &client_addr, &client_len);
if (client_fd < 0)
{
return;
}
printf ("b\n");
setnonblock (client_fd);
printf ("c\n");
client = calloc (1, sizeof *client);
if (client == NULL)
{
return;
}
printf ("d\n");
client->sockfd = client_fd;
client->bufev = bufferevent_new (client_fd,
buf_read_callback,
buf_write_callback,
buf_error_callback,
(void*) client);
printf ("e\n");
bufferevent_enable (client->bufev, EV_READ);
printf ("f\n");
};
static void
buf_read_callback (struct bufferevent* in, void* arg)
{
struct evbuffer *evbuf;
char* req;
size_t num;
printf ("a\n");
req = (char*) malloc (sizeof (struct frame_header));
if (NULL == req)
{
return;
}
while (sizeof (struct frame_header) ==
(num = bufferevent_read (in, req, sizeof (struct frame_header))))
{
printf ("b\n");
if (0 == fcgi_read (req, num, in))
{
// Error
return;
}
printf ("c\n");
}
//
// evbuf = evbuffer_new ();
// evbuffer_add_printf (evbuf, "You said %s \n", req);
// bufferevent_write_buffer (in, evbuf);
// evbuffer_free (evbuf);
// free (req);
};
static void
buf_write_callback (struct bufferevent* bev, void* arg)
{
};
static void
buf_error_callback (struct bufferevent* bev, short what, void* arg)
{
struct fcgi* client;
bufferevent_free (client->bufev);
close (client->sockfd);
free (client);
};