Commit 6550e381f0270cd53cbfcd36359119e876b33d50
1 parent
20af2baa
now the separated http worker works. Changed some size_t to ssize_t as i use -1 …
…and -2 es error indicator in my server and fixed caculation of remainig buffer size in reader
Showing
15 changed files
with
50 additions
and
33 deletions
1 | +2012-02-15 12:17:00 +0100 Georg Hopp | |
2 | + | |
3 | + * now the separated http worker works. Changed some size_t to ssize_t as i use -1 and -2 es error indicator in my server and fixed caculation of remainig buffer size in reader (HEAD, master) | |
4 | + | |
1 | 5 | 2012-02-15 09:38:32 +0100 Georg Hopp |
2 | 6 | |
3 | - * separated the server completely from the http processing (HEAD, master) | |
7 | + * separated the server completely from the http processing | |
4 | 8 | |
5 | 9 | 2012-02-15 06:19:52 +0100 Georg Hopp |
6 | 10 | ... | ... |
... | ... | @@ -33,12 +33,12 @@ CLASS(HttpRequestParser) { |
33 | 33 | HttpRequestState state; |
34 | 34 | }; |
35 | 35 | |
36 | -size_t httpRequestParserRead(HttpRequestParser, int); | |
37 | -size_t httpRequestParserParse(HttpRequestParser); | |
38 | -void httpRequestParserGetBody(HttpRequestParser); | |
36 | +ssize_t httpRequestParserRead(HttpRequestParser, int); | |
37 | +ssize_t httpRequestParserParse(HttpRequestParser); | |
38 | +void httpRequestParserGetBody(HttpRequestParser); | |
39 | 39 | |
40 | -void httpRequestParserGetRequestLine(HttpRequest, char *); | |
41 | -void httpRequestParserGetHeader(HttpRequest, char *); | |
40 | +void httpRequestParserGetRequestLine(HttpRequest, char *); | |
41 | +void httpRequestParserGetHeader(HttpRequest, char *); | |
42 | 42 | |
43 | 43 | #endif /* __HTTP_REQUEST_PARSER_H__ */ |
44 | 44 | ... | ... |
... | ... | @@ -12,8 +12,8 @@ CLASS(HttpWorker) { |
12 | 12 | HttpResponseWriter writer; |
13 | 13 | }; |
14 | 14 | |
15 | -size_t httpWorkerProcess(HttpWorker, int); | |
16 | -size_t httpWorkerWrite(HttpWorker, int); | |
15 | +ssize_t httpWorkerProcess(HttpWorker, int); | |
16 | +ssize_t httpWorkerWrite(HttpWorker, int); | |
17 | 17 | |
18 | 18 | #endif // __HTTP_WORKER_H__ |
19 | 19 | ... | ... |
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | |
4 | 4 | #include <sys/types.h> |
5 | 5 | |
6 | -typedef size_t (* fptr_streamReaderRead)(void *, int fd); | |
6 | +typedef ssize_t (* fptr_streamReaderRead)(void *, int fd); | |
7 | 7 | |
8 | 8 | extern const struct interface i_StreamReader; |
9 | 9 | |
... | ... | @@ -12,7 +12,7 @@ struct i_StreamReader { |
12 | 12 | fptr_streamReaderRead read; |
13 | 13 | }; |
14 | 14 | |
15 | -extern size_t streamReaderRead(void *, int fd); | |
15 | +extern ssize_t streamReaderRead(void *, int fd); | |
16 | 16 | |
17 | 17 | #endif // __STREAM_READER_H__ |
18 | 18 | ... | ... |
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | |
4 | 4 | #include <sys/types.h> |
5 | 5 | |
6 | -typedef size_t (* fptr_streamWriterWrite)(void *, int fd); | |
6 | +typedef ssize_t (* fptr_streamWriterWrite)(void *, int fd); | |
7 | 7 | |
8 | 8 | extern const struct interface i_StreamWriter; |
9 | 9 | |
... | ... | @@ -12,7 +12,7 @@ struct i_StreamWriter { |
12 | 12 | fptr_streamWriterWrite write; |
13 | 13 | }; |
14 | 14 | |
15 | -extern size_t streamWriterWrite(void *, int fd); | |
15 | +extern ssize_t streamWriterWrite(void *, int fd); | |
16 | 16 | |
17 | 17 | #endif // __STREAM_WRITER_H__ |
18 | 18 | ... | ... |
... | ... | @@ -33,11 +33,12 @@ httpRequestSkip(char ** data) |
33 | 33 | for (; 0 != **data && ! isalpha(**data); (*data)++); |
34 | 34 | } |
35 | 35 | |
36 | -size_t | |
36 | +ssize_t | |
37 | 37 | httpRequestParserParse(HttpRequestParser this) |
38 | 38 | { |
39 | - char * line; | |
40 | - int cont = 1; | |
39 | + char * line; | |
40 | + int cont = 1; | |
41 | + ssize_t ret = this->request_queue->nmsgs; | |
41 | 42 | |
42 | 43 | while (cont) { |
43 | 44 | switch(this->state) { |
... | ... | @@ -84,6 +85,11 @@ httpRequestParserParse(HttpRequestParser this) |
84 | 85 | */ |
85 | 86 | this->request_queue->msgs[(this->request_queue->nmsgs)++] = |
86 | 87 | (HttpMessage)this->cur_request; |
88 | + | |
89 | + if (! httpMessageHasKeepAlive((HttpMessage)this->cur_request)) { | |
90 | + ret = -2; | |
91 | + } | |
92 | + | |
87 | 93 | this->cur_request = NULL; |
88 | 94 | |
89 | 95 | /** | ... | ... |
... | ... | @@ -4,16 +4,17 @@ |
4 | 4 | #include "http/request/parser.h" |
5 | 5 | |
6 | 6 | |
7 | -size_t | |
7 | +ssize_t | |
8 | 8 | httpRequestParserRead(HttpRequestParser this, int fd) |
9 | 9 | { |
10 | 10 | size_t remaining, chunks; |
11 | 11 | char buffer[1024]; |
12 | 12 | |
13 | - size_t size = read(fd, buffer, 1024); | |
13 | + ssize_t size = read(fd, buffer, 1024); | |
14 | 14 | |
15 | 15 | if (0 < size) { |
16 | 16 | remaining = this->buffer_used % HTTP_REQUEST_PARSER_READ_CHUNK; |
17 | + remaining = HTTP_REQUEST_PARSER_READ_CHUNK - remaining; | |
17 | 18 | chunks = this->buffer_used / HTTP_REQUEST_PARSER_READ_CHUNK; |
18 | 19 | |
19 | 20 | /** |
... | ... | @@ -37,6 +38,9 @@ httpRequestParserRead(HttpRequestParser this, int fd) |
37 | 38 | |
38 | 39 | size = httpRequestParserParse(this); |
39 | 40 | } |
41 | + else { | |
42 | + size = (0 == size)? -2 : size; | |
43 | + } | |
40 | 44 | |
41 | 45 | return size; |
42 | 46 | } | ... | ... |
... | ... | @@ -16,12 +16,12 @@ |
16 | 16 | #define _PSIZE(x) (MAX((x),RESPONSE_WRITER_MAX_BUF)) |
17 | 17 | #define PSIZE _PSIZE(this->nheader+message->nbody) |
18 | 18 | |
19 | -size_t | |
19 | +ssize_t | |
20 | 20 | httpResponseWriterWrite(HttpResponseWriter this, int fd) |
21 | 21 | { |
22 | 22 | HttpMessageQueue respq = this->response_queue; |
23 | 23 | HttpMessage message = (HttpMessage)this->cur_response; |
24 | - size_t processed = (message)? 1 : 0; | |
24 | + ssize_t processed = (message)? 1 : 0; | |
25 | 25 | int cont = 1; |
26 | 26 | |
27 | 27 | while (cont) { | ... | ... |
1 | 1 | static |
2 | -int | |
2 | +ssize_t | |
3 | 3 | serverRead(Server this, unsigned int i) |
4 | 4 | { |
5 | - int fd = (this->fds)[i].fd; | |
6 | - int size; | |
5 | + int fd = (this->fds)[i].fd; | |
6 | + ssize_t size; | |
7 | 7 | |
8 | 8 | if (NULL == (this->conns)[fd].worker) { |
9 | 9 | loggerLog( |
... | ... | @@ -14,10 +14,12 @@ serverRead(Server this, unsigned int i) |
14 | 14 | } |
15 | 15 | |
16 | 16 | switch ((size = streamReaderRead((this->conns)[fd].worker, fd))) { |
17 | - case 0: | |
17 | + case -2: | |
18 | 18 | /* |
19 | - * normal close: write remaining data | |
20 | - * @TODO: actually we have no remaining data here.... | |
19 | + * normal close: this must be mapped to -2 within the | |
20 | + * underlying read call. Done now in httpRequestParserRead | |
21 | + * @TODO: make sure all pending writes will be done before | |
22 | + * close. | |
21 | 23 | */ |
22 | 24 | /* DROP-THROUGH */ |
23 | 25 | ... | ... |
Please
register
or
login
to post a comment