diff options
Diffstat (limited to 'src/microhttpd/daemon.c')
-rw-r--r-- | src/microhttpd/daemon.c | 97 |
1 files changed, 86 insertions, 11 deletions
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 28ec725b..09f658e0 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -38,6 +38,10 @@ | |||
38 | #include "mhd_itc.h" | 38 | #include "mhd_itc.h" |
39 | #include "mhd_compat.h" | 39 | #include "mhd_compat.h" |
40 | 40 | ||
41 | #ifdef HAVE_STDBOOL_H | ||
42 | #include <stdbool.h> | ||
43 | #endif | ||
44 | |||
41 | #if HAVE_SEARCH_H | 45 | #if HAVE_SEARCH_H |
42 | #include <search.h> | 46 | #include <search.h> |
43 | #else | 47 | #else |
@@ -1425,11 +1429,82 @@ thread_main_handle_connection (void *data) | |||
1425 | struct pollfd p[1 + EXTRA_SLOTS]; | 1429 | struct pollfd p[1 + EXTRA_SLOTS]; |
1426 | #endif | 1430 | #endif |
1427 | #undef EXTRA_SLOTS | 1431 | #undef EXTRA_SLOTS |
1432 | #ifdef HAVE_POLL | ||
1433 | const _MHD_bool use_poll = (0 != (daemon->options & MHD_USE_POLL)); | ||
1434 | #else /* ! HAVE_POLL */ | ||
1435 | const _MHD_bool use_poll = 0; | ||
1436 | #endif /* ! HAVE_POLL */ | ||
1437 | _MHD_bool was_suspended; | ||
1428 | 1438 | ||
1439 | was_suspended = 0; | ||
1429 | while ( (MHD_YES != daemon->shutdown) && | 1440 | while ( (MHD_YES != daemon->shutdown) && |
1430 | (MHD_CONNECTION_CLOSED != con->state) ) | 1441 | (MHD_CONNECTION_CLOSED != con->state) ) |
1431 | { | 1442 | { |
1432 | const unsigned int timeout = daemon->connection_timeout; | 1443 | const unsigned int timeout = daemon->connection_timeout; |
1444 | _MHD_bool was_suspended = 0; | ||
1445 | |||
1446 | if (MHD_NO != con->suspended) | ||
1447 | { | ||
1448 | /* Connection was suspended, wait for resume. */ | ||
1449 | was_suspended = !0; | ||
1450 | if (!use_poll) | ||
1451 | { | ||
1452 | FD_ZERO (&rs); | ||
1453 | if (! MHD_add_to_fd_set_ (MHD_itc_r_fd_ (daemon->itc), | ||
1454 | &rs, | ||
1455 | NULL, | ||
1456 | FD_SETSIZE)) | ||
1457 | { | ||
1458 | #ifdef HAVE_MESSAGES | ||
1459 | MHD_DLOG (con->daemon, | ||
1460 | _("Failed to add FD to fd_set\n")); | ||
1461 | #endif | ||
1462 | goto exit; | ||
1463 | } | ||
1464 | if (0 > MHD_SYS_select_ (MHD_itc_r_fd_ (daemon->itc) + 1, | ||
1465 | &rs, NULL, NULL, NULL)) | ||
1466 | { | ||
1467 | const int err = MHD_socket_get_error_(); | ||
1468 | |||
1469 | if (MHD_SCKT_ERR_IS_EINTR_(err)) | ||
1470 | continue; | ||
1471 | #ifdef HAVE_MESSAGES | ||
1472 | MHD_DLOG (con->daemon, | ||
1473 | _("Error during select (%d): `%s'\n"), | ||
1474 | err, | ||
1475 | MHD_socket_strerr_ (err)); | ||
1476 | #endif | ||
1477 | break; | ||
1478 | } | ||
1479 | } | ||
1480 | #ifdef HAVE_POLL | ||
1481 | else /* use_poll */ | ||
1482 | { | ||
1483 | p[0].events = POLLIN; | ||
1484 | p[0].fd = MHD_itc_r_fd_ (daemon->itc); | ||
1485 | p[0].revents = 0; | ||
1486 | if (0 > MHD_sys_poll_ (p, 1, -1)) | ||
1487 | { | ||
1488 | if (MHD_SCKT_LAST_ERR_IS_(MHD_SCKT_EINTR_)) | ||
1489 | continue; | ||
1490 | #ifdef HAVE_MESSAGES | ||
1491 | MHD_DLOG (con->daemon, | ||
1492 | _("Error during poll: `%s'\n"), | ||
1493 | MHD_socket_last_strerr_ ()); | ||
1494 | #endif | ||
1495 | break; | ||
1496 | } | ||
1497 | } | ||
1498 | #endif /* HAVE_POLL */ | ||
1499 | MHD_itc_clear_ (daemon->itc); | ||
1500 | continue; /* Check again for resume. */ | ||
1501 | } /* End of "suspended" branch. */ | ||
1502 | |||
1503 | if ( was_suspended && (0 != con->connection_timeout) ) | ||
1504 | { | ||
1505 | con->last_activity = MHD_monotonic_sec_counter(); /* Reset timeout timer. */ | ||
1506 | was_suspended = 0; | ||
1507 | } | ||
1433 | 1508 | ||
1434 | tvp = NULL; | 1509 | tvp = NULL; |
1435 | #if HTTPS_SUPPORT | 1510 | #if HTTPS_SUPPORT |
@@ -2429,7 +2504,17 @@ resume_suspended_connections (struct MHD_Daemon *daemon) | |||
2429 | pos->resuming = MHD_NO; | 2504 | pos->resuming = MHD_NO; |
2430 | } | 2505 | } |
2431 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2506 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2432 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | 2507 | { |
2508 | MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex); | ||
2509 | if (MHD_NO != ret) | ||
2510 | { /* Wake up suspended connections. */ | ||
2511 | if ( !MHD_itc_activate_(daemon->itc, "w")) | ||
2512 | #ifdef HAVE_MESSAGES | ||
2513 | MHD_DLOG (daemon, | ||
2514 | _("Failed to signal resume of connection via inter-thread communication channel.")); | ||
2515 | #endif | ||
2516 | } | ||
2517 | } | ||
2433 | return ret; | 2518 | return ret; |
2434 | } | 2519 | } |
2435 | 2520 | ||
@@ -4750,16 +4835,6 @@ MHD_start_daemon_va (unsigned int flags, | |||
4750 | goto free_and_fail; | 4835 | goto free_and_fail; |
4751 | } | 4836 | } |
4752 | 4837 | ||
4753 | if ( (MHD_USE_SUSPEND_RESUME == (flags & MHD_USE_SUSPEND_RESUME)) && | ||
4754 | (0 != (flags & MHD_USE_THREAD_PER_CONNECTION)) ) | ||
4755 | { | ||
4756 | #ifdef HAVE_MESSAGES | ||
4757 | MHD_DLOG (daemon, | ||
4758 | _("Combining MHD_USE_THREAD_PER_CONNECTION and MHD_USE_SUSPEND_RESUME is not supported.\n")); | ||
4759 | #endif | ||
4760 | goto free_and_fail; | ||
4761 | } | ||
4762 | |||
4763 | #ifdef __SYMBIAN32__ | 4838 | #ifdef __SYMBIAN32__ |
4764 | if (0 != (flags & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) | 4839 | if (0 != (flags & (MHD_USE_SELECT_INTERNALLY | MHD_USE_THREAD_PER_CONNECTION))) |
4765 | { | 4840 | { |