Commit 6550e381f0270cd53cbfcd36359119e876b33d50

Authored by Georg Hopp
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
  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 2012-02-15 09:38:32 +0100 Georg Hopp 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 2012-02-15 06:19:52 +0100 Georg Hopp 9 2012-02-15 06:19:52 +0100 Georg Hopp
6 10
@@ -33,12 +33,12 @@ CLASS(HttpRequestParser) { @@ -33,12 +33,12 @@ CLASS(HttpRequestParser) {
33 HttpRequestState state; 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 #endif /* __HTTP_REQUEST_PARSER_H__ */ 43 #endif /* __HTTP_REQUEST_PARSER_H__ */
44 44
@@ -29,7 +29,7 @@ CLASS(HttpResponseWriter) { @@ -29,7 +29,7 @@ CLASS(HttpResponseWriter) {
29 HttpResponseState state; 29 HttpResponseState state;
30 }; 30 };
31 31
32 -size_t httpResponseWriterWrite(HttpResponseWriter, int); 32 +ssize_t httpResponseWriterWrite(HttpResponseWriter, int);
33 33
34 #endif // __HTTP_RESPONSE_WRITER_H__ 34 #endif // __HTTP_RESPONSE_WRITER_H__
35 35
@@ -12,8 +12,8 @@ CLASS(HttpWorker) { @@ -12,8 +12,8 @@ CLASS(HttpWorker) {
12 HttpResponseWriter writer; 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 #endif // __HTTP_WORKER_H__ 18 #endif // __HTTP_WORKER_H__
19 19
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 3
4 #include <sys/types.h> 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 extern const struct interface i_StreamReader; 8 extern const struct interface i_StreamReader;
9 9
@@ -12,7 +12,7 @@ struct i_StreamReader { @@ -12,7 +12,7 @@ struct i_StreamReader {
12 fptr_streamReaderRead read; 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 #endif // __STREAM_READER_H__ 17 #endif // __STREAM_READER_H__
18 18
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 3
4 #include <sys/types.h> 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 extern const struct interface i_StreamWriter; 8 extern const struct interface i_StreamWriter;
9 9
@@ -12,7 +12,7 @@ struct i_StreamWriter { @@ -12,7 +12,7 @@ struct i_StreamWriter {
12 fptr_streamWriterWrite write; 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 #endif // __STREAM_WRITER_H__ 17 #endif // __STREAM_WRITER_H__
18 18
@@ -33,11 +33,12 @@ httpRequestSkip(char ** data) @@ -33,11 +33,12 @@ httpRequestSkip(char ** data)
33 for (; 0 != **data && ! isalpha(**data); (*data)++); 33 for (; 0 != **data && ! isalpha(**data); (*data)++);
34 } 34 }
35 35
36 -size_t 36 +ssize_t
37 httpRequestParserParse(HttpRequestParser this) 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 while (cont) { 43 while (cont) {
43 switch(this->state) { 44 switch(this->state) {
@@ -84,6 +85,11 @@ httpRequestParserParse(HttpRequestParser this) @@ -84,6 +85,11 @@ httpRequestParserParse(HttpRequestParser this)
84 */ 85 */
85 this->request_queue->msgs[(this->request_queue->nmsgs)++] = 86 this->request_queue->msgs[(this->request_queue->nmsgs)++] =
86 (HttpMessage)this->cur_request; 87 (HttpMessage)this->cur_request;
  88 +
  89 + if (! httpMessageHasKeepAlive((HttpMessage)this->cur_request)) {
  90 + ret = -2;
  91 + }
  92 +
87 this->cur_request = NULL; 93 this->cur_request = NULL;
88 94
89 /** 95 /**
@@ -4,16 +4,17 @@ @@ -4,16 +4,17 @@
4 #include "http/request/parser.h" 4 #include "http/request/parser.h"
5 5
6 6
7 -size_t 7 +ssize_t
8 httpRequestParserRead(HttpRequestParser this, int fd) 8 httpRequestParserRead(HttpRequestParser this, int fd)
9 { 9 {
10 size_t remaining, chunks; 10 size_t remaining, chunks;
11 char buffer[1024]; 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 if (0 < size) { 15 if (0 < size) {
16 remaining = this->buffer_used % HTTP_REQUEST_PARSER_READ_CHUNK; 16 remaining = this->buffer_used % HTTP_REQUEST_PARSER_READ_CHUNK;
  17 + remaining = HTTP_REQUEST_PARSER_READ_CHUNK - remaining;
17 chunks = this->buffer_used / HTTP_REQUEST_PARSER_READ_CHUNK; 18 chunks = this->buffer_used / HTTP_REQUEST_PARSER_READ_CHUNK;
18 19
19 /** 20 /**
@@ -37,6 +38,9 @@ httpRequestParserRead(HttpRequestParser this, int fd) @@ -37,6 +38,9 @@ httpRequestParserRead(HttpRequestParser this, int fd)
37 38
38 size = httpRequestParserParse(this); 39 size = httpRequestParserParse(this);
39 } 40 }
  41 + else {
  42 + size = (0 == size)? -2 : size;
  43 + }
40 44
41 return size; 45 return size;
42 } 46 }
@@ -16,12 +16,12 @@ @@ -16,12 +16,12 @@
16 #define _PSIZE(x) (MAX((x),RESPONSE_WRITER_MAX_BUF)) 16 #define _PSIZE(x) (MAX((x),RESPONSE_WRITER_MAX_BUF))
17 #define PSIZE _PSIZE(this->nheader+message->nbody) 17 #define PSIZE _PSIZE(this->nheader+message->nbody)
18 18
19 -size_t 19 +ssize_t
20 httpResponseWriterWrite(HttpResponseWriter this, int fd) 20 httpResponseWriterWrite(HttpResponseWriter this, int fd)
21 { 21 {
22 HttpMessageQueue respq = this->response_queue; 22 HttpMessageQueue respq = this->response_queue;
23 HttpMessage message = (HttpMessage)this->cur_response; 23 HttpMessage message = (HttpMessage)this->cur_response;
24 - size_t processed = (message)? 1 : 0; 24 + ssize_t processed = (message)? 1 : 0;
25 int cont = 1; 25 int cont = 1;
26 26
27 while (cont) { 27 while (cont) {
@@ -4,10 +4,10 @@ @@ -4,10 +4,10 @@
4 #include "http/worker.h" 4 #include "http/worker.h"
5 #include "http/request/parser.h" 5 #include "http/request/parser.h"
6 6
7 -size_t 7 +ssize_t
8 httpWorkerProcess(HttpWorker this, int fd) 8 httpWorkerProcess(HttpWorker this, int fd)
9 { 9 {
10 - size_t size; 10 + ssize_t size;
11 11
12 if (0 < (size = httpRequestParserRead(this->parser, fd))) { 12 if (0 < (size = httpRequestParserRead(this->parser, fd))) {
13 int i; 13 int i;
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 #include "http/worker.h" 3 #include "http/worker.h"
4 #include "http/response/writer.h" 4 #include "http/response/writer.h"
5 5
6 -size_t 6 +ssize_t
7 httpWorkerWrite(HttpWorker this, int fd) 7 httpWorkerWrite(HttpWorker this, int fd)
8 { 8 {
9 return httpResponseWriterWrite(this->writer, fd); 9 return httpResponseWriterWrite(this->writer, fd);
@@ -6,10 +6,10 @@ const struct interface i_StreamReader = { @@ -6,10 +6,10 @@ const struct interface i_StreamReader = {
6 1 6 1
7 }; 7 };
8 8
9 -size_t 9 +ssize_t
10 streamReaderRead(void * object, int fd) 10 streamReaderRead(void * object, int fd)
11 { 11 {
12 - size_t ret; 12 + ssize_t ret;
13 13
14 RETCALL(object, StreamReader, read, ret, fd); 14 RETCALL(object, StreamReader, read, ret, fd);
15 15
@@ -6,10 +6,10 @@ const struct interface i_StreamWriter = { @@ -6,10 +6,10 @@ const struct interface i_StreamWriter = {
6 1 6 1
7 }; 7 };
8 8
9 -size_t 9 +ssize_t
10 streamWriterWrite(void * object, int fd) 10 streamWriterWrite(void * object, int fd)
11 { 11 {
12 - size_t ret; 12 + ssize_t ret;
13 13
14 RETCALL(object, StreamWriter, write, ret, fd); 14 RETCALL(object, StreamWriter, write, ret, fd);
15 15
1 static 1 static
2 -int 2 +ssize_t
3 serverRead(Server this, unsigned int i) 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 if (NULL == (this->conns)[fd].worker) { 8 if (NULL == (this->conns)[fd].worker) {
9 loggerLog( 9 loggerLog(
@@ -14,10 +14,12 @@ serverRead(Server this, unsigned int i) @@ -14,10 +14,12 @@ serverRead(Server this, unsigned int i)
14 } 14 }
15 15
16 switch ((size = streamReaderRead((this->conns)[fd].worker, fd))) { 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 /* DROP-THROUGH */ 24 /* DROP-THROUGH */
23 25
@@ -88,6 +88,7 @@ serverRun(Server this) @@ -88,6 +88,7 @@ serverRun(Server this)
88 nreads--; 88 nreads--;
89 89
90 switch (serverRead(this, i)) { 90 switch (serverRead(this, i)) {
  91 + case -2:
91 case -1: 92 case -1:
92 serverCloseConn(this, i); 93 serverCloseConn(this, i);
93 break; 94 break;
Please register or login to post a comment