Commit 90df11c01484440dc5f4014053ff1a32ed5462ec
1 parent
0a9bca48
now each HttpRequestParser initializes its own request queue and enqueus complet…
…ed requests there. The server now gets the queue and prints completed requests.
Showing
8 changed files
with
105 additions
and
31 deletions
1 | +2012-02-07 13:41:49 +0100 Georg Hopp | |
2 | + | |
3 | + * now each HttpRequestParser initializes its own request queue and enqueus completed requests there. The server now gets the queue and prints completed requests. (HEAD, master) | |
4 | + | |
5 | +2012-02-07 11:12:30 +0100 Georg Hopp | |
6 | + | |
7 | + * started filling out a request object with the parser | |
8 | + | |
9 | +2012-02-07 09:29:59 +0100 Georg Hopp | |
10 | + | |
11 | + * porformance improvement in parsing process (no longer do alloc and free on each line) | |
12 | + | |
13 | +2012-02-07 08:52:18 +0100 Georg Hopp | |
14 | + | |
15 | + * basic request parsing (line by line) implemented | |
16 | + | |
17 | +2012-02-06 16:08:13 +0100 Georg Hopp | |
18 | + | |
19 | + * split server implementation for readability | |
20 | + | |
21 | +2012-02-06 11:35:40 +0100 Georg Hopp | |
22 | + | |
23 | + * free reader (HttpRequestParser) when connection is closed | |
24 | + | |
1 | 25 | 2012-02-06 11:20:00 +0100 Georg Hopp |
2 | 26 | |
3 | - * add StreamReader interface, modify HttpRequestParser and Server to use it (HEAD, master) | |
27 | + * add StreamReader interface, modify HttpRequestParser and Server to use it | |
4 | 28 | |
5 | 29 | 2012-02-06 11:15:00 +0100 Georg Hopp |
6 | 30 | ... | ... |
... | ... | @@ -2,8 +2,7 @@ |
2 | 2 | #define __HTTP_REQUEST_PARSER_H__ |
3 | 3 | |
4 | 4 | #include "class.h" |
5 | -//#include "http/request.h" | |
6 | -//#include "http/request_queue.h" | |
5 | +#include "http/request_queue.h" | |
7 | 6 | |
8 | 7 | #define HTTP_REQUEST_PARSER_READ_CHUNK 1024 |
9 | 8 | |
... | ... | @@ -21,7 +20,7 @@ CLASS(HttpRequestParser) { |
21 | 20 | size_t buffer_used; |
22 | 21 | size_t buffer_size; |
23 | 22 | |
24 | - //HttpRequestQueue request_queue; | |
23 | + HttpRequestQueue request_queue; | |
25 | 24 | HttpRequestState state; |
26 | 25 | }; |
27 | 26 | ... | ... |
... | ... | @@ -5,7 +5,7 @@ CLASS = class.c interface.c interface/class.c |
5 | 5 | SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c |
6 | 6 | SERVER = server.c server/run.c server/close_conn.c |
7 | 7 | LOGGER = logger.c logger/stderr.c logger/syslog.c interface/logger.c |
8 | -HTTP = interface/stream_reader.c http/request_parser.c http/request.c | |
8 | +HTTP = interface/stream_reader.c http/request_parser.c http/request.c http/request_queue.c | |
9 | 9 | |
10 | 10 | AM_CFLAGS = -Wall -I ../include/ |
11 | 11 | ... | ... |
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | #include "interface/class.h" |
12 | 12 | #include "interface/stream_reader.h" |
13 | 13 | #include "http/request.h" |
14 | -//#include "http/request_queue.h" | |
14 | +#include "http/request_queue.h" | |
15 | 15 | |
16 | 16 | static |
17 | 17 | void |
... | ... | @@ -23,7 +23,7 @@ ctor(void * _this, va_list * params) |
23 | 23 | { |
24 | 24 | HttpRequestParser this = _this; |
25 | 25 | |
26 | - //this->request_queue = va_arg(*params, HttpRequestQueue); | |
26 | + this->request_queue = new(HttpRequestQueue); | |
27 | 27 | |
28 | 28 | this->buffer = malloc(HTTP_REQUEST_PARSER_READ_CHUNK); |
29 | 29 | this->buffer[0] = 0; |
... | ... | @@ -36,6 +36,7 @@ dtor(void * _this) |
36 | 36 | HttpRequestParser this = _this; |
37 | 37 | |
38 | 38 | free(this->buffer); |
39 | + delete(&(this->request_queue)); | |
39 | 40 | } |
40 | 41 | |
41 | 42 | static |
... | ... | @@ -46,7 +47,10 @@ _clone(void * _this, void * _base) |
46 | 47 | HttpRequestParser base = _base; |
47 | 48 | size_t chunks; |
48 | 49 | |
49 | - //this->request_queue = base->request_queue; | |
50 | + /** | |
51 | + * every parser has its own queue... | |
52 | + */ | |
53 | + this->request_queue = new(HttpRequestQueue); | |
50 | 54 | this->buffer_used = base->buffer_used; |
51 | 55 | |
52 | 56 | chunks = this->buffer_used / HTTP_REQUEST_PARSER_READ_CHUNK; |
... | ... | @@ -183,10 +187,6 @@ httpRequestParserParse(HttpRequestParser this) |
183 | 187 | } |
184 | 188 | } |
185 | 189 | |
186 | - printf("method: %s\n", request->method); | |
187 | - printf("uri: %s\n", request->uri); | |
188 | - printf("version: %s\n", request->http_version); | |
189 | - | |
190 | 190 | header_idx = 0; |
191 | 191 | this->state = HTTP_REQUEST_REQEUST_LINE_DONE; |
192 | 192 | break; |
... | ... | @@ -223,16 +223,6 @@ httpRequestParserParse(HttpRequestParser this) |
223 | 223 | case HTTP_REQUEST_HEADERS_DONE: |
224 | 224 | puts("==headers done=="); |
225 | 225 | |
226 | - { | |
227 | - int i; | |
228 | - | |
229 | - for (i=0; i<header_idx; i++) { | |
230 | - printf("header-name: %s\n", (request->header)[i].name); | |
231 | - printf("header-value: %s\n", (request->header)[i].value); | |
232 | - } | |
233 | - } | |
234 | - | |
235 | - printf("%s\n", line); | |
236 | 226 | this->state = HTTP_REQUEST_DONE; |
237 | 227 | break; |
238 | 228 | |
... | ... | @@ -249,7 +239,9 @@ httpRequestParserParse(HttpRequestParser this) |
249 | 239 | cont = 0; |
250 | 240 | } |
251 | 241 | |
252 | - delete(&request); | |
242 | + this->request_queue->requests[(this->request_queue->nrequests)++] = | |
243 | + request; | |
244 | + | |
253 | 245 | this->state = HTTP_REQUEST_GARBAGE; |
254 | 246 | |
255 | 247 | break; | ... | ... |
... | ... | @@ -9,8 +9,12 @@ serverHandleAccept(Server this) |
9 | 9 | acc = socketAccept(this->sock, remoteAddr); |
10 | 10 | |
11 | 11 | if (-1 != acc->handle) { |
12 | - (this->conns)[this->nfds].sock = acc; // save the socket handle | |
13 | - (this->conns)[this->nfds].reader = clone(this->reader); // clone reader | |
12 | + //* save the socket handle | |
13 | + (this->conns)[this->nfds].sock = acc; | |
14 | + | |
15 | + //* clone reader | |
16 | + (this->conns)[this->nfds].reader = clone(this->reader); | |
17 | + | |
14 | 18 | (this->fds)[this->nfds].fd = acc->handle; |
15 | 19 | (this->fds)[this->nfds].events = POLLIN; |
16 | 20 | this->nfds++; | ... | ... |
... | ... | @@ -10,6 +10,13 @@ |
10 | 10 | #include "signalHandling.h" |
11 | 11 | #include "interface/class.h" |
12 | 12 | #include "interface/stream_reader.h" |
13 | +#include "interface/logger.h" | |
14 | + | |
15 | +//* @TODO: to be removed | |
16 | +#include "http/request.h" | |
17 | +#include "http/request_parser.h" | |
18 | +#include "http/request_queue.h" | |
19 | +//* until here | |
13 | 20 | |
14 | 21 | #undef MAX |
15 | 22 | #define MAX(x,y) ((x) > (y) ? (x) : (y)) |
... | ... | @@ -21,11 +28,18 @@ |
21 | 28 | void |
22 | 29 | serverRun(Server this) |
23 | 30 | { |
24 | - /* | |
25 | - * @TODO again...add verbosity to logger.... | |
26 | - */ | |
27 | 31 | loggerLog(this->logger, LOGGER_INFO, "service started"); |
28 | 32 | |
33 | + /** | |
34 | + * @TODO: actually this is the main loop of my server. When | |
35 | + * stuff becomes more complicated it might be feasabible to | |
36 | + * split stuff into separate processes. This will definetly | |
37 | + * involve some IPC and syncing. Right now as this is actually | |
38 | + * only a simple HTTP server implementation we go on with | |
39 | + * this single process. | |
40 | + * What we can first do to get some processing between read/write | |
41 | + * cicles is to use the poll timeout. | |
42 | + */ | |
29 | 43 | while (!doShutdown) /* until error or signal */ |
30 | 44 | { |
31 | 45 | int events; |
... | ... | @@ -46,6 +60,46 @@ serverRun(Server this) |
46 | 60 | * handle reads |
47 | 61 | */ |
48 | 62 | serverRead(this); |
63 | + | |
64 | + /** | |
65 | + * do some other processing | |
66 | + * @TODO: actually this will hard assume that our stream reader | |
67 | + * is a http parser and it has its queue...think about more | |
68 | + * generalizing here. | |
69 | + */ | |
70 | + { | |
71 | + int i; | |
72 | + | |
73 | + for (i=1; i<this->nfds; i++) { | |
74 | + int j; | |
75 | + HttpRequestQueue queue = | |
76 | + ((HttpRequestParser)(this->conns)[i].reader)->request_queue; | |
77 | + | |
78 | + for (j=0; j<queue->nrequests; j++) { | |
79 | + int k; | |
80 | + HttpRequest request = queue->requests[j]; | |
81 | + | |
82 | + printf("method: %s\n", request->method); | |
83 | + printf("uri: %s\n", request->uri); | |
84 | + printf("version: %s\n", request->http_version); | |
85 | + puts(""); | |
86 | + | |
87 | + for (k=0; k<128; k++) { | |
88 | + if (NULL == (request->header)[k].name) break; | |
89 | + printf("header-name: %s\n", (request->header)[k].name); | |
90 | + printf("header-value: %s\n", (request->header)[k].value); | |
91 | + } | |
92 | + | |
93 | + delete(&request); | |
94 | + } | |
95 | + queue->nrequests = 0; | |
96 | + } | |
97 | + } | |
98 | + | |
99 | + | |
100 | + /** | |
101 | + * handle writes | |
102 | + */ | |
49 | 103 | } |
50 | 104 | } |
51 | 105 | ... | ... |
Please
register
or
login
to post a comment