Commit 983c93390885090d8ab933c217e836a465d67753

Authored by Georg Hopp
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
  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 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 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 13 2012-02-10 09:59:41 +0100 Georg Hopp
10 14
... ...
... ... @@ -36,14 +36,14 @@ dtor(void * _this)
36 36 Server this = _this;
37 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 49 delete(&this->sock);
... ...
... ... @@ -11,7 +11,10 @@ serverCloseConn(Server this, unsigned int i)
11 11 delete(&((this->conns)[fd].sock));
12 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 18 (this->conns)[fd].keep_alive = 0;
16 19
17 20 (this->fds)[i].events = 0;
... ...
... ... @@ -10,7 +10,7 @@ serverRead(Server this, unsigned int i)
10 10 this->logger,
11 11 LOGGER_INFO,
12 12 "initialization error: NULL reader");
13   - serverCloseConn(this, i);
  13 + return -1;
14 14 }
15 15
16 16 switch ((size = streamReaderRead((this->conns)[fd].reader, fd))) {
... ... @@ -25,8 +25,10 @@ serverRead(Server this, unsigned int i)
25 25 /*
26 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 32 break;
31 33
32 34 default:
... ...
... ... @@ -75,13 +75,15 @@ serverRun(Server this)
75 75 */
76 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 82 int j;
80 83 HttpRequestQueue queue =
81 84 ((HttpRequestParser)(this->conns)[fd].reader)->request_queue;
82 85
83 86 for (j=0; j<queue->nrequests; j++) {
84   - HttpRequest request = queue->requests[j];
85 87 HttpResponse response;
86 88
87 89 /**
... ... @@ -90,20 +92,22 @@ serverRun(Server this)
90 92 */
91 93 response = httpResponse404();
92 94
93   - if (httpRequestHasKeepAlive(request)) {
  95 + if (httpRequestHasKeepAlive(queue->requests[j])) {
  96 + (this->conns)[fd].keep_alive = 1;
94 97 httpResponseHeaderSet(
95 98 response,
96 99 "Connection",
97 100 "Keep-Alive");
98 101 }
99 102 else {
  103 + (this->conns)[fd].keep_alive = 0;
100 104 httpResponseHeaderSet(
101 105 response,
102 106 "Connection",
103 107 "Close");
104 108 }
105 109
106   - delete(&request);
  110 + delete(&(queue->requests[j]));
107 111
108 112 (this->conns)[fd].wbuf = calloc(
109 113 1, httpResponseSizeGet(response) + 1);
... ...
... ... @@ -16,13 +16,11 @@
16 16 int
17 17 main()
18 18 {
19   - struct rlimit limit = {RLIM_INFINITY, RLIM_INFINITY};
20   -
21 19 Logger logger = new(LoggerStderr, LOGGER_ERR);
22 20 HttpRequestParser parser = new(HttpRequestParser);
23 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 24 setrlimit(RLIMIT_CPU, &limit);
27 25
28 26 init_signals();
... ...
Please register or login to post a comment