diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index b6f1e9f3..6a0e4ab2 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -42,13 +42,13 @@ | |||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * Print extra messages with reasons for closing | 44 | * Print extra messages with reasons for closing |
45 | * sockets? (only adds non-error messages). | 45 | * sockets? (only adds non-error messages). |
46 | */ | 46 | */ |
47 | #define DEBUG_CLOSE MHD_NO | 47 | #define DEBUG_CLOSE MHD_NO |
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Print extra messages when establishing | 50 | * Print extra messages when establishing |
51 | * connections? (only adds non-error messages). | 51 | * connections? (only adds non-error messages). |
52 | */ | 52 | */ |
53 | #define DEBUG_CONNECT MHD_NO | 53 | #define DEBUG_CONNECT MHD_NO |
54 | 54 | ||
@@ -116,20 +116,19 @@ MHD_handle_connection (void *data) | |||
116 | if (con == NULL) | 116 | if (con == NULL) |
117 | abort (); | 117 | abort (); |
118 | timeout = con->daemon->connection_timeout; | 118 | timeout = con->daemon->connection_timeout; |
119 | while ( (!con->daemon->shutdown) && | 119 | while ((!con->daemon->shutdown) && (con->socket_fd != -1)) |
120 | (con->socket_fd != -1) ) | ||
121 | { | 120 | { |
122 | FD_ZERO (&rs); | 121 | FD_ZERO (&rs); |
123 | FD_ZERO (&ws); | 122 | FD_ZERO (&ws); |
124 | FD_ZERO (&es); | 123 | FD_ZERO (&es); |
125 | max = 0; | 124 | max = 0; |
126 | MHD_connection_get_fdset (con, &rs, &ws, &es, &max); | 125 | MHD_connection_get_fdset (con, &rs, &ws, &es, &max); |
127 | now = time(NULL); | 126 | now = time (NULL); |
128 | tv.tv_usec = 0; | 127 | tv.tv_usec = 0; |
129 | if ( timeout > (now - con->last_activity) ) | 128 | if (timeout > (now - con->last_activity)) |
130 | tv.tv_sec = timeout - (now - con->last_activity); | 129 | tv.tv_sec = timeout - (now - con->last_activity); |
131 | else | 130 | else |
132 | tv.tv_sec = 0; | 131 | tv.tv_sec = 0; |
133 | num_ready = SELECT (max + 1, | 132 | num_ready = SELECT (max + 1, |
134 | &rs, &ws, &es, (timeout != 0) ? &tv : NULL); | 133 | &rs, &ws, &es, (timeout != 0) ? &tv : NULL); |
135 | if (num_ready < 0) | 134 | if (num_ready < 0) |
@@ -143,12 +142,11 @@ MHD_handle_connection (void *data) | |||
143 | break; | 142 | break; |
144 | } | 143 | } |
145 | if (FD_ISSET (con->socket_fd, &rs)) | 144 | if (FD_ISSET (con->socket_fd, &rs)) |
146 | MHD_connection_handle_read (con); | 145 | MHD_connection_handle_read (con); |
147 | if ((con->socket_fd != -1) && | 146 | if ((con->socket_fd != -1) && (FD_ISSET (con->socket_fd, &ws))) |
148 | (FD_ISSET (con->socket_fd, &ws)) ) | 147 | MHD_connection_handle_write (con); |
149 | MHD_connection_handle_write (con); | 148 | if (con->socket_fd != -1) |
150 | if (con->socket_fd != -1) | 149 | MHD_connection_handle_idle (con); |
151 | MHD_connection_handle_idle (con); | ||
152 | } | 150 | } |
153 | if (con->socket_fd != -1) | 151 | if (con->socket_fd != -1) |
154 | { | 152 | { |
@@ -309,7 +307,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
309 | pthread_kill (pos->pid, SIGALRM); | 307 | pthread_kill (pos->pid, SIGALRM); |
310 | pthread_join (pos->pid, &unused); | 308 | pthread_join (pos->pid, &unused); |
311 | } | 309 | } |
312 | MHD_destroy_response (pos->response); | 310 | MHD_destroy_response (pos->response); |
313 | MHD_pool_destroy (pos->pool); | 311 | MHD_pool_destroy (pos->pool); |
314 | free (pos->addr); | 312 | free (pos->addr); |
315 | free (pos); | 313 | free (pos); |
@@ -455,12 +453,11 @@ MHD_select (struct MHD_Daemon *daemon, int may_block) | |||
455 | if (ds != -1) | 453 | if (ds != -1) |
456 | { | 454 | { |
457 | if (FD_ISSET (ds, &rs)) | 455 | if (FD_ISSET (ds, &rs)) |
458 | MHD_connection_handle_read (pos); | 456 | MHD_connection_handle_read (pos); |
459 | if ( (pos->socket_fd != -1) && | 457 | if ((pos->socket_fd != -1) && (FD_ISSET (ds, &ws))) |
460 | (FD_ISSET (ds, &ws)) ) | 458 | MHD_connection_handle_write (pos); |
461 | MHD_connection_handle_write (pos); | 459 | if (pos->socket_fd != -1) |
462 | if (pos->socket_fd != -1) | 460 | MHD_connection_handle_idle (pos); |
463 | MHD_connection_handle_idle(pos); | ||
464 | } | 461 | } |
465 | pos = pos->next; | 462 | pos = pos->next; |
466 | } | 463 | } |