aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r--src/daemon/daemon.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c
index 657afb23..33f048ed 100644
--- a/src/daemon/daemon.c
+++ b/src/daemon/daemon.c
@@ -276,6 +276,7 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) {
276 struct MHD_Session * pos; 276 struct MHD_Session * pos;
277 struct MHD_Session * prev; 277 struct MHD_Session * prev;
278 struct MHD_HTTP_Header * hpos; 278 struct MHD_HTTP_Header * hpos;
279 void * unused;
279 280
280 pos = daemon->connections; 281 pos = daemon->connections;
281 prev = NULL; 282 prev = NULL;
@@ -285,6 +286,8 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) {
285 daemon->connections = pos->next; 286 daemon->connections = pos->next;
286 else 287 else
287 prev->next = pos->next; 288 prev->next = pos->next;
289 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
290 pthread_join(pos->pid, &unused);
288 free(pos->addr); 291 free(pos->addr);
289 if (pos->url != NULL) 292 if (pos->url != NULL)
290 free(pos->url); 293 free(pos->url);
@@ -299,6 +302,7 @@ MHD_cleanup_sessions(struct MHD_Daemon * daemon) {
299 pos->headers_received = hpos->next; 302 pos->headers_received = hpos->next;
300 free(hpos->header); 303 free(hpos->header);
301 free(hpos->value); 304 free(hpos->value);
305 free(hpos);
302 } 306 }
303 if (pos->response != NULL) 307 if (pos->response != NULL)
304 MHD_destroy_response(pos->response); 308 MHD_destroy_response(pos->response);
@@ -337,6 +341,7 @@ MHD_select(struct MHD_Daemon * daemon,
337 fd_set es; 341 fd_set es;
338 int max; 342 int max;
339 struct timeval timeout; 343 struct timeval timeout;
344 int ds;
340 345
341 timeout.tv_sec = 0; 346 timeout.tv_sec = 0;
342 timeout.tv_usec = 0; 347 timeout.tv_usec = 0;
@@ -373,16 +378,22 @@ MHD_select(struct MHD_Daemon * daemon,
373 strerror(errno)); 378 strerror(errno));
374 return MHD_NO; 379 return MHD_NO;
375 } 380 }
376 if (FD_ISSET(daemon->socket_fd, 381 ds = daemon->socket_fd;
382 if (ds == -1)
383 return MHD_YES;
384 if (FD_ISSET(ds,
377 &rs)) 385 &rs))
378 MHD_accept_connection(daemon); 386 MHD_accept_connection(daemon);
379 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) { 387 if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) {
380 /* do not have a thread per connection, process all connections now */ 388 /* do not have a thread per connection, process all connections now */
381 pos = daemon->connections; 389 pos = daemon->connections;
382 while (pos != NULL) { 390 while (pos != NULL) {
383 if (FD_ISSET(pos->socket_fd, &rs)) 391 ds = pos->socket_fd;
392 if (ds == -1)
393 continue;
394 if (FD_ISSET(ds, &rs))
384 MHD_session_handle_read(pos); 395 MHD_session_handle_read(pos);
385 if (FD_ISSET(pos->socket_fd, &ws)) 396 if (FD_ISSET(ds, &ws))
386 MHD_session_handle_write(pos); 397 MHD_session_handle_write(pos);
387 pos = pos->next; 398 pos = pos->next;
388 } 399 }
@@ -542,9 +553,6 @@ MHD_stop_daemon(struct MHD_Daemon * daemon) {
542 close(daemon->connections->socket_fd); 553 close(daemon->connections->socket_fd);
543 daemon->connections->socket_fd = -1; 554 daemon->connections->socket_fd = -1;
544 } 555 }
545 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
546 pthread_join(daemon->connections->pid, &unused);
547
548 MHD_cleanup_sessions(daemon); 556 MHD_cleanup_sessions(daemon);
549 } 557 }
550 free(daemon); 558 free(daemon);