Commit 983c93390885090d8ab933c217e836a465d67753
1 parent
f82c178b
fix seaks and hangs after adding response object (mostly not related with the re…
…sponse object but how i integated it into serverRun
Showing
6 changed files
with
32 additions
and
21 deletions
1 | +2012-02-11 12:47:01 +0100 Georg Hopp | ||
2 | + | ||
3 | + * fix seaks and hangs after adding response object (mostly not related with the response object but how i integated it into serverRun (HEAD, master) | ||
4 | + | ||
1 | 2012-02-10 19:57:57 +0100 Georg Hopp | 5 | 2012-02-10 19:57:57 +0100 Georg Hopp |
2 | 6 | ||
3 | - * started a response handler and changed serverRun to use it for its response (HEAD, master) | 7 | + * started a response handler and changed serverRun to use it for its response (origin/master, origin/HEAD) |
4 | 8 | ||
5 | 2012-02-10 12:42:04 +0100 Georg Hopp | 9 | 2012-02-10 12:42:04 +0100 Georg Hopp |
6 | 10 | ||
7 | - * fixed bug at server destructor (origin/master, origin/HEAD) | 11 | + * fixed bug at server destructor |
8 | 12 | ||
9 | 2012-02-10 09:59:41 +0100 Georg Hopp | 13 | 2012-02-10 09:59:41 +0100 Georg Hopp |
10 | 14 |
@@ -36,14 +36,14 @@ dtor(void * _this) | @@ -36,14 +36,14 @@ dtor(void * _this) | ||
36 | Server this = _this; | 36 | Server this = _this; |
37 | int i; | 37 | int i; |
38 | 38 | ||
39 | - for (i=1; i<this->nfds; i++) { | ||
40 | - /* | ||
41 | - * @TODO do some finalization...buffer handling...etc. | ||
42 | - */ | ||
43 | - delete(&(this->conns[(this->fds)[i].fd]).sock); | ||
44 | - delete(&(this->conns[(this->fds)[i].fd]).reader); | ||
45 | - if (this->conns[(this->fds)[i].fd].wbuf) | ||
46 | - free(this->conns[(this->fds)[i].fd].wbuf); | 39 | + for (i=0; i<this->nfds; i++) { |
40 | + if (this->sock->handle != (this->fds)[i].fd) { | ||
41 | + delete(&(this->conns[(this->fds)[i].fd]).sock); | ||
42 | + delete(&(this->conns[(this->fds)[i].fd]).reader); | ||
43 | + | ||
44 | + if (this->conns[(this->fds)[i].fd].wbuf) | ||
45 | + free(this->conns[(this->fds)[i].fd].wbuf); | ||
46 | + } | ||
47 | } | 47 | } |
48 | 48 | ||
49 | delete(&this->sock); | 49 | delete(&this->sock); |
@@ -11,7 +11,10 @@ serverCloseConn(Server this, unsigned int i) | @@ -11,7 +11,10 @@ serverCloseConn(Server this, unsigned int i) | ||
11 | delete(&((this->conns)[fd].sock)); | 11 | delete(&((this->conns)[fd].sock)); |
12 | delete(&((this->conns)[fd].reader)); | 12 | delete(&((this->conns)[fd].reader)); |
13 | 13 | ||
14 | - memset((this->conns)[fd].wbuf, 0, strlen((this->conns)[fd].wbuf)); | 14 | + if ((this->conns)[fd].wbuf != NULL) { |
15 | + free((this->conns)[fd].wbuf); | ||
16 | + (this->conns)[fd].wbuf = NULL; | ||
17 | + } | ||
15 | (this->conns)[fd].keep_alive = 0; | 18 | (this->conns)[fd].keep_alive = 0; |
16 | 19 | ||
17 | (this->fds)[i].events = 0; | 20 | (this->fds)[i].events = 0; |
@@ -10,7 +10,7 @@ serverRead(Server this, unsigned int i) | @@ -10,7 +10,7 @@ serverRead(Server this, unsigned int i) | ||
10 | this->logger, | 10 | this->logger, |
11 | LOGGER_INFO, | 11 | LOGGER_INFO, |
12 | "initialization error: NULL reader"); | 12 | "initialization error: NULL reader"); |
13 | - serverCloseConn(this, i); | 13 | + return -1; |
14 | } | 14 | } |
15 | 15 | ||
16 | switch ((size = streamReaderRead((this->conns)[fd].reader, fd))) { | 16 | switch ((size = streamReaderRead((this->conns)[fd].reader, fd))) { |
@@ -25,8 +25,10 @@ serverRead(Server this, unsigned int i) | @@ -25,8 +25,10 @@ serverRead(Server this, unsigned int i) | ||
25 | /* | 25 | /* |
26 | * read failure / close connection | 26 | * read failure / close connection |
27 | */ | 27 | */ |
28 | - loggerLog(this->logger, LOGGER_INFO, "connection closed..."); | ||
29 | - serverCloseConn(this, i); | 28 | + loggerLog(this->logger, LOGGER_INFO, |
29 | + "connection[%d] closed...%s", | ||
30 | + fd, | ||
31 | + inet_ntoa((((this->conns)[fd].sock)->addr).sin_addr)); | ||
30 | break; | 32 | break; |
31 | 33 | ||
32 | default: | 34 | default: |
@@ -75,13 +75,15 @@ serverRun(Server this) | @@ -75,13 +75,15 @@ serverRun(Server this) | ||
75 | */ | 75 | */ |
76 | int size; | 76 | int size; |
77 | 77 | ||
78 | - if (0 < (size=serverRead(this, i))) { | 78 | + if (0 >= (size=serverRead(this, i))) { |
79 | + serverCloseConn(this, i); | ||
80 | + } | ||
81 | + else { | ||
79 | int j; | 82 | int j; |
80 | HttpRequestQueue queue = | 83 | HttpRequestQueue queue = |
81 | ((HttpRequestParser)(this->conns)[fd].reader)->request_queue; | 84 | ((HttpRequestParser)(this->conns)[fd].reader)->request_queue; |
82 | 85 | ||
83 | for (j=0; j<queue->nrequests; j++) { | 86 | for (j=0; j<queue->nrequests; j++) { |
84 | - HttpRequest request = queue->requests[j]; | ||
85 | HttpResponse response; | 87 | HttpResponse response; |
86 | 88 | ||
87 | /** | 89 | /** |
@@ -90,20 +92,22 @@ serverRun(Server this) | @@ -90,20 +92,22 @@ serverRun(Server this) | ||
90 | */ | 92 | */ |
91 | response = httpResponse404(); | 93 | response = httpResponse404(); |
92 | 94 | ||
93 | - if (httpRequestHasKeepAlive(request)) { | 95 | + if (httpRequestHasKeepAlive(queue->requests[j])) { |
96 | + (this->conns)[fd].keep_alive = 1; | ||
94 | httpResponseHeaderSet( | 97 | httpResponseHeaderSet( |
95 | response, | 98 | response, |
96 | "Connection", | 99 | "Connection", |
97 | "Keep-Alive"); | 100 | "Keep-Alive"); |
98 | } | 101 | } |
99 | else { | 102 | else { |
103 | + (this->conns)[fd].keep_alive = 0; | ||
100 | httpResponseHeaderSet( | 104 | httpResponseHeaderSet( |
101 | response, | 105 | response, |
102 | "Connection", | 106 | "Connection", |
103 | "Close"); | 107 | "Close"); |
104 | } | 108 | } |
105 | 109 | ||
106 | - delete(&request); | 110 | + delete(&(queue->requests[j])); |
107 | 111 | ||
108 | (this->conns)[fd].wbuf = calloc( | 112 | (this->conns)[fd].wbuf = calloc( |
109 | 1, httpResponseSizeGet(response) + 1); | 113 | 1, httpResponseSizeGet(response) + 1); |
@@ -16,13 +16,11 @@ | @@ -16,13 +16,11 @@ | ||
16 | int | 16 | int |
17 | main() | 17 | main() |
18 | { | 18 | { |
19 | - struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY}; | ||
20 | - | ||
21 | Logger logger = new(LoggerStderr, LOGGER_ERR); | 19 | Logger logger = new(LoggerStderr, LOGGER_ERR); |
22 | HttpRequestParser parser = new(HttpRequestParser); | 20 | HttpRequestParser parser = new(HttpRequestParser); |
23 | Server server = new(Server, logger, parser, 11212, SOMAXCONN); | 21 | Server server = new(Server, logger, parser, 11212, SOMAXCONN); |
24 | - //Server server = new(Server, logger, parser, 11212, 20); | ||
25 | 22 | ||
23 | + struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY}; | ||
26 | setrlimit(RLIMIT_CPU, &limit); | 24 | setrlimit(RLIMIT_CPU, &limit); |
27 | 25 | ||
28 | init_signals(); | 26 | init_signals(); |
Please
register
or
login
to post a comment