diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/include/mhd_options.h | 13 | ||||
-rw-r--r-- | src/microhttpd/connection.c | 40 | ||||
-rw-r--r-- | src/microhttpd/daemon.c | 231 | ||||
-rw-r--r-- | src/microhttpd/digestauth.c | 10 | ||||
-rw-r--r-- | src/microhttpd/internal.h | 9 | ||||
-rw-r--r-- | src/microhttpd/mhd_locks.h | 47 | ||||
-rw-r--r-- | src/microhttpd/mhd_sem.c | 14 | ||||
-rw-r--r-- | src/microhttpd/mhd_sockets.h | 13 | ||||
-rw-r--r-- | src/microhttpd/response.c | 35 | ||||
-rw-r--r-- | src/microhttpd/test_shutdown_select.c | 9 | ||||
-rw-r--r-- | src/microhttpd/test_upgrade_common.c | 9 | ||||
-rw-r--r-- | src/testcurl/https/test_https_time_out.c | 10 | ||||
-rw-r--r-- | src/testcurl/test_callback.c | 11 | ||||
-rw-r--r-- | src/testcurl/test_get.c | 8 | ||||
-rw-r--r-- | src/testcurl/test_quiesce.c | 8 |
16 files changed, 238 insertions, 234 deletions
@@ -1,3 +1,8 @@ | |||
1 | Thu Sep 22 11:03:43 CEST 2016 | ||
2 | Simplify internal error handling logic by folding it into the | ||
3 | MHD_socket_close_, MHD_mutex_lock_, MHD_mutex_unlock_ and | ||
4 | MHD_mutex_destroy_ functions. -CG | ||
5 | |||
1 | Tue Sep 13 22:20:26 MSK 2016 | 6 | Tue Sep 13 22:20:26 MSK 2016 |
2 | Added autoconf macro to enable maximum platform | 7 | Added autoconf macro to enable maximum platform |
3 | features. Fixed compiling on Solaris. -EG | 8 | features. Fixed compiling on Solaris. -EG |
diff --git a/src/include/mhd_options.h b/src/include/mhd_options.h index d442e6e7..8d9cedd2 100644 --- a/src/include/mhd_options.h +++ b/src/include/mhd_options.h | |||
@@ -33,6 +33,15 @@ | |||
33 | 33 | ||
34 | #include "MHD_config.h" | 34 | #include "MHD_config.h" |
35 | 35 | ||
36 | /** | ||
37 | * Macro to make it easy to mark text for translation. Note that | ||
38 | * we do not actually call gettext() in MHD, but we do make it | ||
39 | * easy to create a ".po" file so that applications that do want | ||
40 | * to translate error messages can do so. | ||
41 | */ | ||
42 | #define _(String) (String) | ||
43 | |||
44 | |||
36 | 45 | ||
37 | #ifndef _MHD_EXTERN | 46 | #ifndef _MHD_EXTERN |
38 | #if defined(BUILDING_MHD_LIB) && defined(_WIN32) && \ | 47 | #if defined(BUILDING_MHD_LIB) && defined(_WIN32) && \ |
@@ -92,7 +101,7 @@ | |||
92 | #endif /* HAVE_C11_GMTIME_S */ | 101 | #endif /* HAVE_C11_GMTIME_S */ |
93 | 102 | ||
94 | #if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE) | 103 | #if defined(MHD_FAVOR_FAST_CODE) && defined(MHD_FAVOR_SMALL_CODE) |
95 | #error MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. Cannot favor speed and size at the same time. | 104 | #error MHD_FAVOR_FAST_CODE and MHD_FAVOR_SMALL_CODE are both defined. Cannot favor speed and size at the same time. |
96 | #endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */ | 105 | #endif /* MHD_FAVOR_FAST_CODE && MHD_FAVOR_SMALL_CODE */ |
97 | 106 | ||
98 | /* Define MHD_FAVOR_FAST_CODE to force fast code path or | 107 | /* Define MHD_FAVOR_FAST_CODE to force fast code path or |
@@ -100,7 +109,7 @@ | |||
100 | #if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE) | 109 | #if !defined(MHD_FAVOR_FAST_CODE) && !defined(MHD_FAVOR_SMALL_CODE) |
101 | /* Try to detect user preferences */ | 110 | /* Try to detect user preferences */ |
102 | /* Defined by GCC and many compatible compilers */ | 111 | /* Defined by GCC and many compatible compilers */ |
103 | #ifdef __OPTIMIZE_SIZE__ | 112 | #ifdef __OPTIMIZE_SIZE__ |
104 | #define MHD_FAVOR_SMALL_CODE 1 | 113 | #define MHD_FAVOR_SMALL_CODE 1 |
105 | #elif __OPTIMIZE__ | 114 | #elif __OPTIMIZE__ |
106 | #define MHD_FAVOR_FAST_CODE 1 | 115 | #define MHD_FAVOR_FAST_CODE 1 |
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 2fe9c64b..e1d22e12 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c | |||
@@ -614,7 +614,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
614 | { | 614 | { |
615 | /* either error or http 1.0 transfer, close socket! */ | 615 | /* either error or http 1.0 transfer, close socket! */ |
616 | response->total_size = connection->response_write_position; | 616 | response->total_size = connection->response_write_position; |
617 | (void) MHD_mutex_unlock_ (&response->mutex); | 617 | MHD_mutex_unlock_ (&response->mutex); |
618 | if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret) | 618 | if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret) |
619 | MHD_connection_close_ (connection, | 619 | MHD_connection_close_ (connection, |
620 | MHD_REQUEST_TERMINATED_COMPLETED_OK); | 620 | MHD_REQUEST_TERMINATED_COMPLETED_OK); |
@@ -628,7 +628,7 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
628 | if (0 == ret) | 628 | if (0 == ret) |
629 | { | 629 | { |
630 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; | 630 | connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY; |
631 | (void) MHD_mutex_unlock_ (&response->mutex); | 631 | MHD_mutex_unlock_ (&response->mutex); |
632 | return MHD_NO; | 632 | return MHD_NO; |
633 | } | 633 | } |
634 | return MHD_YES; | 634 | return MHD_YES; |
@@ -2457,13 +2457,13 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
2457 | uint64_t data_write_offset; | 2457 | uint64_t data_write_offset; |
2458 | 2458 | ||
2459 | if (NULL != response->crc) | 2459 | if (NULL != response->crc) |
2460 | (void) MHD_mutex_lock_ (&response->mutex); | 2460 | MHD_mutex_lock_ (&response->mutex); |
2461 | if (MHD_YES != try_ready_normal_body (connection)) | 2461 | if (MHD_YES != try_ready_normal_body (connection)) |
2462 | { | 2462 | { |
2463 | if (NULL != response->crc) | 2463 | if (NULL != response->crc) |
2464 | (void) MHD_mutex_unlock_ (&response->mutex); | 2464 | MHD_mutex_unlock_ (&response->mutex); |
2465 | break; | 2465 | break; |
2466 | } | 2466 | } |
2467 | data_write_offset = connection->response_write_position | 2467 | data_write_offset = connection->response_write_position |
2468 | - response->data_start; | 2468 | - response->data_start; |
2469 | if (data_write_offset > (uint64_t)SIZE_MAX) | 2469 | if (data_write_offset > (uint64_t)SIZE_MAX) |
@@ -2484,7 +2484,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection) | |||
2484 | response->data_start]); | 2484 | response->data_start]); |
2485 | #endif | 2485 | #endif |
2486 | if (NULL != response->crc) | 2486 | if (NULL != response->crc) |
2487 | (void) MHD_mutex_unlock_ (&response->mutex); | 2487 | MHD_mutex_unlock_ (&response->mutex); |
2488 | if (ret < 0) | 2488 | if (ret < 0) |
2489 | { | 2489 | { |
2490 | if (MHD_SCKT_ERR_IS_EINTR_ (err) || | 2490 | if (MHD_SCKT_ERR_IS_EINTR_ (err) || |
@@ -2570,8 +2570,7 @@ cleanup_connection (struct MHD_Connection *connection) | |||
2570 | } | 2570 | } |
2571 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2571 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2572 | { | 2572 | { |
2573 | if (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) | 2573 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2574 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
2575 | } | 2574 | } |
2576 | else | 2575 | else |
2577 | { | 2576 | { |
@@ -2598,9 +2597,8 @@ cleanup_connection (struct MHD_Connection *connection) | |||
2598 | connection->suspended = MHD_NO; | 2597 | connection->suspended = MHD_NO; |
2599 | connection->resuming = MHD_NO; | 2598 | connection->resuming = MHD_NO; |
2600 | connection->in_idle = MHD_NO; | 2599 | connection->in_idle = MHD_NO; |
2601 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2600 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2602 | (! MHD_mutex_unlock_(&daemon->cleanup_connection_mutex)) ) | 2601 | MHD_mutex_unlock_(&daemon->cleanup_connection_mutex); |
2603 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2604 | } | 2602 | } |
2605 | 2603 | ||
2606 | 2604 | ||
@@ -2909,18 +2907,18 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2909 | break; | 2907 | break; |
2910 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: | 2908 | case MHD_CONNECTION_NORMAL_BODY_UNREADY: |
2911 | if (NULL != connection->response->crc) | 2909 | if (NULL != connection->response->crc) |
2912 | (void) MHD_mutex_lock_ (&connection->response->mutex); | 2910 | MHD_mutex_lock_ (&connection->response->mutex); |
2913 | if (0 == connection->response->total_size) | 2911 | if (0 == connection->response->total_size) |
2914 | { | 2912 | { |
2915 | if (NULL != connection->response->crc) | 2913 | if (NULL != connection->response->crc) |
2916 | (void) MHD_mutex_unlock_ (&connection->response->mutex); | 2914 | MHD_mutex_unlock_ (&connection->response->mutex); |
2917 | connection->state = MHD_CONNECTION_BODY_SENT; | 2915 | connection->state = MHD_CONNECTION_BODY_SENT; |
2918 | continue; | 2916 | continue; |
2919 | } | 2917 | } |
2920 | if (MHD_YES == try_ready_normal_body (connection)) | 2918 | if (MHD_YES == try_ready_normal_body (connection)) |
2921 | { | 2919 | { |
2922 | if (NULL != connection->response->crc) | 2920 | if (NULL != connection->response->crc) |
2923 | (void) MHD_mutex_unlock_ (&connection->response->mutex); | 2921 | MHD_mutex_unlock_ (&connection->response->mutex); |
2924 | connection->state = MHD_CONNECTION_NORMAL_BODY_READY; | 2922 | connection->state = MHD_CONNECTION_NORMAL_BODY_READY; |
2925 | /* Buffering for flushable socket was already enabled*/ | 2923 | /* Buffering for flushable socket was already enabled*/ |
2926 | if (MHD_NO == socket_flush_possible (connection)) | 2924 | if (MHD_NO == socket_flush_possible (connection)) |
@@ -2934,20 +2932,20 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2934 | break; | 2932 | break; |
2935 | case MHD_CONNECTION_CHUNKED_BODY_UNREADY: | 2933 | case MHD_CONNECTION_CHUNKED_BODY_UNREADY: |
2936 | if (NULL != connection->response->crc) | 2934 | if (NULL != connection->response->crc) |
2937 | (void) MHD_mutex_lock_ (&connection->response->mutex); | 2935 | MHD_mutex_lock_ (&connection->response->mutex); |
2938 | if ( (0 == connection->response->total_size) || | 2936 | if ( (0 == connection->response->total_size) || |
2939 | (connection->response_write_position == | 2937 | (connection->response_write_position == |
2940 | connection->response->total_size) ) | 2938 | connection->response->total_size) ) |
2941 | { | 2939 | { |
2942 | if (NULL != connection->response->crc) | 2940 | if (NULL != connection->response->crc) |
2943 | (void) MHD_mutex_unlock_ (&connection->response->mutex); | 2941 | MHD_mutex_unlock_ (&connection->response->mutex); |
2944 | connection->state = MHD_CONNECTION_BODY_SENT; | 2942 | connection->state = MHD_CONNECTION_BODY_SENT; |
2945 | continue; | 2943 | continue; |
2946 | } | 2944 | } |
2947 | if (MHD_YES == try_ready_chunked_body (connection)) | 2945 | if (MHD_YES == try_ready_chunked_body (connection)) |
2948 | { | 2946 | { |
2949 | if (NULL != connection->response->crc) | 2947 | if (NULL != connection->response->crc) |
2950 | (void) MHD_mutex_unlock_ (&connection->response->mutex); | 2948 | MHD_mutex_unlock_ (&connection->response->mutex); |
2951 | connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; | 2949 | connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; |
2952 | /* Buffering for flushable socket was already enabled */ | 2950 | /* Buffering for flushable socket was already enabled */ |
2953 | if (MHD_NO == socket_flush_possible (connection)) | 2951 | if (MHD_NO == socket_flush_possible (connection)) |
@@ -2956,7 +2954,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection) | |||
2956 | continue; | 2954 | continue; |
2957 | } | 2955 | } |
2958 | if (NULL != connection->response->crc) | 2956 | if (NULL != connection->response->crc) |
2959 | (void) MHD_mutex_unlock_ (&connection->response->mutex); | 2957 | MHD_mutex_unlock_ (&connection->response->mutex); |
2960 | break; | 2958 | break; |
2961 | case MHD_CONNECTION_BODY_SENT: | 2959 | case MHD_CONNECTION_BODY_SENT: |
2962 | if (MHD_NO == build_header_response (connection)) | 2960 | if (MHD_NO == build_header_response (connection)) |
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index ec7a3526..cfaf2e1c 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c | |||
@@ -195,10 +195,7 @@ struct MHD_IPCount | |||
195 | static void | 195 | static void |
196 | MHD_ip_count_lock (struct MHD_Daemon *daemon) | 196 | MHD_ip_count_lock (struct MHD_Daemon *daemon) |
197 | { | 197 | { |
198 | if (! MHD_mutex_lock_(&daemon->per_ip_connection_mutex)) | 198 | MHD_mutex_lock_(&daemon->per_ip_connection_mutex); |
199 | { | ||
200 | MHD_PANIC (_("Failed to acquire IP connection limit mutex\n")); | ||
201 | } | ||
202 | } | 199 | } |
203 | 200 | ||
204 | 201 | ||
@@ -210,10 +207,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon) | |||
210 | static void | 207 | static void |
211 | MHD_ip_count_unlock (struct MHD_Daemon *daemon) | 208 | MHD_ip_count_unlock (struct MHD_Daemon *daemon) |
212 | { | 209 | { |
213 | if (! MHD_mutex_unlock_(&daemon->per_ip_connection_mutex)) | 210 | MHD_mutex_unlock_(&daemon->per_ip_connection_mutex); |
214 | { | ||
215 | MHD_PANIC (_("Failed to release IP connection limit mutex\n")); | ||
216 | } | ||
217 | } | 211 | } |
218 | 212 | ||
219 | 213 | ||
@@ -965,8 +959,7 @@ finish_upgrade_close (struct MHD_UpgradeResponseHandle *urh) | |||
965 | NULL)) ) | 959 | NULL)) ) |
966 | MHD_PANIC (_("Failed to remove FD from epoll set\n")); | 960 | MHD_PANIC (_("Failed to remove FD from epoll set\n")); |
967 | #endif | 961 | #endif |
968 | if (0 != MHD_socket_close_ (urh->mhd.socket)) | 962 | MHD_socket_close_ (urh->mhd.socket); |
969 | MHD_PANIC (_("close failed\n")); | ||
970 | } | 963 | } |
971 | MHD_resume_connection (connection); | 964 | MHD_resume_connection (connection); |
972 | MHD_connection_close_ (connection, | 965 | MHD_connection_close_ (connection, |
@@ -1536,8 +1529,7 @@ exit: | |||
1536 | { | 1529 | { |
1537 | shutdown (con->socket_fd, | 1530 | shutdown (con->socket_fd, |
1538 | SHUT_WR); | 1531 | SHUT_WR); |
1539 | if (0 != MHD_socket_close_ (con->socket_fd)) | 1532 | MHD_socket_close_ (con->socket_fd); |
1540 | MHD_PANIC (_("close failed\n")); | ||
1541 | con->socket_fd = MHD_INVALID_SOCKET; | 1533 | con->socket_fd = MHD_INVALID_SOCKET; |
1542 | } | 1534 | } |
1543 | return (MHD_THRD_RTRN_TYPE_) 0; | 1535 | return (MHD_THRD_RTRN_TYPE_) 0; |
@@ -1776,8 +1768,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1776 | external_add); | 1768 | external_add); |
1777 | } | 1769 | } |
1778 | /* all pools are at their connection limit, must refuse */ | 1770 | /* all pools are at their connection limit, must refuse */ |
1779 | if (0 != MHD_socket_close_ (client_socket)) | 1771 | MHD_socket_close_ (client_socket); |
1780 | MHD_PANIC ("close failed\n"); | ||
1781 | #if ENFILE | 1772 | #if ENFILE |
1782 | errno = ENFILE; | 1773 | errno = ENFILE; |
1783 | #endif | 1774 | #endif |
@@ -1794,8 +1785,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1794 | (int) client_socket, | 1785 | (int) client_socket, |
1795 | (int) FD_SETSIZE); | 1786 | (int) FD_SETSIZE); |
1796 | #endif | 1787 | #endif |
1797 | if (0 != MHD_socket_close_ (client_socket)) | 1788 | MHD_socket_close_ (client_socket); |
1798 | MHD_PANIC (_("close failed\n")); | ||
1799 | #if EINVAL | 1789 | #if EINVAL |
1800 | errno = EINVAL; | 1790 | errno = EINVAL; |
1801 | #endif | 1791 | #endif |
@@ -1820,8 +1810,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1820 | MHD_DLOG (daemon, | 1810 | MHD_DLOG (daemon, |
1821 | _("Server reached connection limit. Closing inbound connection.\n")); | 1811 | _("Server reached connection limit. Closing inbound connection.\n")); |
1822 | #endif | 1812 | #endif |
1823 | if (0 != MHD_socket_close_ (client_socket)) | 1813 | MHD_socket_close_ (client_socket); |
1824 | MHD_PANIC (_("close failed\n")); | ||
1825 | #if ENFILE | 1814 | #if ENFILE |
1826 | errno = ENFILE; | 1815 | errno = ENFILE; |
1827 | #endif | 1816 | #endif |
@@ -1840,8 +1829,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1840 | _("Connection rejected by application. Closing connection.\n")); | 1829 | _("Connection rejected by application. Closing connection.\n")); |
1841 | #endif | 1830 | #endif |
1842 | #endif | 1831 | #endif |
1843 | if (0 != MHD_socket_close_ (client_socket)) | 1832 | MHD_socket_close_ (client_socket); |
1844 | MHD_PANIC (_("close failed\n")); | ||
1845 | MHD_ip_limit_del (daemon, | 1833 | MHD_ip_limit_del (daemon, |
1846 | addr, | 1834 | addr, |
1847 | addrlen); | 1835 | addrlen); |
@@ -1871,8 +1859,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1871 | "Error allocating memory: %s\n", | 1859 | "Error allocating memory: %s\n", |
1872 | MHD_strerror_ (errno)); | 1860 | MHD_strerror_ (errno)); |
1873 | #endif | 1861 | #endif |
1874 | if (0 != MHD_socket_close_ (client_socket)) | 1862 | MHD_socket_close_ (client_socket); |
1875 | MHD_PANIC ("close failed\n"); | ||
1876 | MHD_ip_limit_del (daemon, | 1863 | MHD_ip_limit_del (daemon, |
1877 | addr, | 1864 | addr, |
1878 | addrlen); | 1865 | addrlen); |
@@ -1890,8 +1877,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1890 | _("Error allocating memory: %s\n"), | 1877 | _("Error allocating memory: %s\n"), |
1891 | MHD_strerror_ (errno)); | 1878 | MHD_strerror_ (errno)); |
1892 | #endif | 1879 | #endif |
1893 | if (0 != MHD_socket_close_ (client_socket)) | 1880 | MHD_socket_close_ (client_socket); |
1894 | MHD_PANIC (_("close failed\n")); | ||
1895 | MHD_ip_limit_del (daemon, | 1881 | MHD_ip_limit_del (daemon, |
1896 | addr, | 1882 | addr, |
1897 | addrlen); | 1883 | addrlen); |
@@ -1911,8 +1897,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1911 | _("Error allocating memory: %s\n"), | 1897 | _("Error allocating memory: %s\n"), |
1912 | MHD_strerror_ (errno)); | 1898 | MHD_strerror_ (errno)); |
1913 | #endif | 1899 | #endif |
1914 | if (0 != MHD_socket_close_ (client_socket)) | 1900 | MHD_socket_close_ (client_socket); |
1915 | MHD_PANIC (_("close failed\n")); | ||
1916 | MHD_ip_limit_del (daemon, | 1901 | MHD_ip_limit_del (daemon, |
1917 | addr, | 1902 | addr, |
1918 | addrlen); | 1903 | addrlen); |
@@ -1973,8 +1958,7 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
1973 | _("Failed to setup TLS credentials: unknown credential type %d\n"), | 1958 | _("Failed to setup TLS credentials: unknown credential type %d\n"), |
1974 | daemon->cred_type); | 1959 | daemon->cred_type); |
1975 | #endif | 1960 | #endif |
1976 | if (0 != MHD_socket_close_ (client_socket)) | 1961 | MHD_socket_close_ (client_socket); |
1977 | MHD_PANIC ("close failed\n"); | ||
1978 | MHD_ip_limit_del (daemon, | 1962 | MHD_ip_limit_del (daemon, |
1979 | addr, | 1963 | addr, |
1980 | addrlen); | 1964 | addrlen); |
@@ -2001,19 +1985,19 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2001 | 1985 | ||
2002 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 1986 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2003 | { | 1987 | { |
2004 | if (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) | 1988 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2005 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
2006 | } | 1989 | } |
2007 | else | 1990 | else |
1991 | { | ||
2008 | XDLL_insert (daemon->normal_timeout_head, | 1992 | XDLL_insert (daemon->normal_timeout_head, |
2009 | daemon->normal_timeout_tail, | 1993 | daemon->normal_timeout_tail, |
2010 | connection); | 1994 | connection); |
1995 | } | ||
2011 | DLL_insert (daemon->connections_head, | 1996 | DLL_insert (daemon->connections_head, |
2012 | daemon->connections_tail, | 1997 | daemon->connections_tail, |
2013 | connection); | 1998 | connection); |
2014 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 1999 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2015 | (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 2000 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
2016 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2017 | 2001 | ||
2018 | if (NULL != daemon->notify_connection) | 2002 | if (NULL != daemon->notify_connection) |
2019 | daemon->notify_connection (daemon->notify_connection_cls, | 2003 | daemon->notify_connection (daemon->notify_connection_cls, |
@@ -2093,24 +2077,25 @@ internal_add_connection (struct MHD_Daemon *daemon, | |||
2093 | connection, | 2077 | connection, |
2094 | &connection->socket_context, | 2078 | &connection->socket_context, |
2095 | MHD_CONNECTION_NOTIFY_CLOSED); | 2079 | MHD_CONNECTION_NOTIFY_CLOSED); |
2096 | if (0 != MHD_socket_close_ (client_socket)) | 2080 | MHD_socket_close_ (client_socket); |
2097 | MHD_PANIC (_("close failed\n")); | 2081 | MHD_ip_limit_del (daemon, |
2098 | MHD_ip_limit_del (daemon, addr, addrlen); | 2082 | addr, |
2083 | addrlen); | ||
2099 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2084 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2100 | { | 2085 | { |
2101 | if (!MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) | 2086 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2102 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | 2087 | } |
2103 | } | ||
2104 | else | 2088 | else |
2105 | XDLL_remove (daemon->normal_timeout_head, | 2089 | { |
2106 | daemon->normal_timeout_tail, | 2090 | XDLL_remove (daemon->normal_timeout_head, |
2107 | connection); | 2091 | daemon->normal_timeout_tail, |
2092 | connection); | ||
2093 | } | ||
2108 | DLL_remove (daemon->connections_head, | 2094 | DLL_remove (daemon->connections_head, |
2109 | daemon->connections_tail, | 2095 | daemon->connections_tail, |
2110 | connection); | 2096 | connection); |
2111 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2097 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2112 | (!MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 2098 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
2113 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2114 | MHD_pool_destroy (connection->pool); | 2099 | MHD_pool_destroy (connection->pool); |
2115 | free (connection->addr); | 2100 | free (connection->addr); |
2116 | free (connection); | 2101 | free (connection); |
@@ -2156,8 +2141,7 @@ MHD_suspend_connection (struct MHD_Connection *connection) | |||
2156 | MHD_PANIC (_("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n")); | 2141 | MHD_PANIC (_("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n")); |
2157 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 2142 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2158 | { | 2143 | { |
2159 | if (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) | 2144 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2160 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
2161 | } | 2145 | } |
2162 | else | 2146 | else |
2163 | { | 2147 | { |
@@ -2199,9 +2183,8 @@ MHD_suspend_connection (struct MHD_Connection *connection) | |||
2199 | } | 2183 | } |
2200 | #endif | 2184 | #endif |
2201 | connection->suspended = MHD_YES; | 2185 | connection->suspended = MHD_YES; |
2202 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2186 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2203 | (! MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 2187 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
2204 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2205 | } | 2188 | } |
2206 | 2189 | ||
2207 | 2190 | ||
@@ -2221,9 +2204,8 @@ MHD_resume_connection (struct MHD_Connection *connection) | |||
2221 | daemon = connection->daemon; | 2204 | daemon = connection->daemon; |
2222 | if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) | 2205 | if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) |
2223 | MHD_PANIC (_("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n")); | 2206 | MHD_PANIC (_("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n")); |
2224 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2207 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2225 | (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) | 2208 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2226 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
2227 | connection->resuming = MHD_YES; | 2209 | connection->resuming = MHD_YES; |
2228 | daemon->resuming = MHD_YES; | 2210 | daemon->resuming = MHD_YES; |
2229 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && | 2211 | if ( (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && |
@@ -2234,9 +2216,8 @@ MHD_resume_connection (struct MHD_Connection *connection) | |||
2234 | _("Failed to signal resume via pipe.")); | 2216 | _("Failed to signal resume via pipe.")); |
2235 | #endif | 2217 | #endif |
2236 | } | 2218 | } |
2237 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2219 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2238 | (! MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 2220 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
2239 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2240 | } | 2221 | } |
2241 | 2222 | ||
2242 | 2223 | ||
@@ -2255,9 +2236,8 @@ resume_suspended_connections (struct MHD_Daemon *daemon) | |||
2255 | int ret; | 2236 | int ret; |
2256 | 2237 | ||
2257 | ret = MHD_NO; | 2238 | ret = MHD_NO; |
2258 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2239 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2259 | (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) | 2240 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2260 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
2261 | if (MHD_NO != daemon->resuming) | 2241 | if (MHD_NO != daemon->resuming) |
2262 | next = daemon->suspended_connections_head; | 2242 | next = daemon->suspended_connections_head; |
2263 | 2243 | ||
@@ -2311,9 +2291,8 @@ resume_suspended_connections (struct MHD_Daemon *daemon) | |||
2311 | pos->suspended = MHD_NO; | 2291 | pos->suspended = MHD_NO; |
2312 | pos->resuming = MHD_NO; | 2292 | pos->resuming = MHD_NO; |
2313 | } | 2293 | } |
2314 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2294 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2315 | (! MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 2295 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
2316 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2317 | return ret; | 2296 | return ret; |
2318 | } | 2297 | } |
2319 | 2298 | ||
@@ -2442,9 +2421,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
2442 | #endif | 2421 | #endif |
2443 | if (MHD_INVALID_SOCKET != s) | 2422 | if (MHD_INVALID_SOCKET != s) |
2444 | { | 2423 | { |
2445 | if (0 != MHD_socket_close_ (s)) | 2424 | MHD_socket_close_ (s); |
2446 | MHD_PANIC (_("close failed\n")); | ||
2447 | /* just in case */ | ||
2448 | } | 2425 | } |
2449 | if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) ) | 2426 | if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) ) |
2450 | { | 2427 | { |
@@ -2518,9 +2495,8 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
2518 | { | 2495 | { |
2519 | struct MHD_Connection *pos; | 2496 | struct MHD_Connection *pos; |
2520 | 2497 | ||
2521 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2498 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2522 | (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) | 2499 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
2523 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
2524 | while (NULL != (pos = daemon->cleanup_head)) | 2500 | while (NULL != (pos = daemon->cleanup_head)) |
2525 | { | 2501 | { |
2526 | DLL_remove (daemon->cleanup_head, | 2502 | DLL_remove (daemon->cleanup_head, |
@@ -2586,16 +2562,14 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon) | |||
2586 | } | 2562 | } |
2587 | if (MHD_INVALID_SOCKET != pos->socket_fd) | 2563 | if (MHD_INVALID_SOCKET != pos->socket_fd) |
2588 | { | 2564 | { |
2589 | if (0 != MHD_socket_close_ (pos->socket_fd)) | 2565 | MHD_socket_close_ (pos->socket_fd); |
2590 | MHD_PANIC (_("close failed\n")); | ||
2591 | } | 2566 | } |
2592 | if (NULL != pos->addr) | 2567 | if (NULL != pos->addr) |
2593 | free (pos->addr); | 2568 | free (pos->addr); |
2594 | free (pos); | 2569 | free (pos); |
2595 | } | 2570 | } |
2596 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 2571 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
2597 | (! MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 2572 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
2598 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
2599 | } | 2573 | } |
2600 | 2574 | ||
2601 | 2575 | ||
@@ -4829,8 +4803,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
4829 | (unsigned int) port, | 4803 | (unsigned int) port, |
4830 | MHD_socket_last_strerr_ ()); | 4804 | MHD_socket_last_strerr_ ()); |
4831 | #endif | 4805 | #endif |
4832 | if (0 != MHD_socket_close_ (socket_fd)) | 4806 | MHD_socket_close_ (socket_fd); |
4833 | MHD_PANIC (_("close failed\n")); | ||
4834 | goto free_and_fail; | 4807 | goto free_and_fail; |
4835 | } | 4808 | } |
4836 | #ifdef TCP_FASTOPEN | 4809 | #ifdef TCP_FASTOPEN |
@@ -4860,8 +4833,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
4860 | _("Failed to listen for connections: %s\n"), | 4833 | _("Failed to listen for connections: %s\n"), |
4861 | MHD_socket_last_strerr_ ()); | 4834 | MHD_socket_last_strerr_ ()); |
4862 | #endif | 4835 | #endif |
4863 | if (0 != MHD_socket_close_ (socket_fd)) | 4836 | MHD_socket_close_ (socket_fd); |
4864 | MHD_PANIC (_("close failed\n")); | ||
4865 | goto free_and_fail; | 4837 | goto free_and_fail; |
4866 | } | 4838 | } |
4867 | } | 4839 | } |
@@ -4883,8 +4855,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
4883 | /* Accept must be non-blocking. Multiple children may wake up | 4855 | /* Accept must be non-blocking. Multiple children may wake up |
4884 | * to handle a new connection, but only one will win the race. | 4856 | * to handle a new connection, but only one will win the race. |
4885 | * The others must immediately return. */ | 4857 | * The others must immediately return. */ |
4886 | if (0 != MHD_socket_close_ (socket_fd)) | 4858 | MHD_socket_close_ (socket_fd); |
4887 | MHD_PANIC (_("close failed\n")); | ||
4888 | goto free_and_fail; | 4859 | goto free_and_fail; |
4889 | } | 4860 | } |
4890 | } | 4861 | } |
@@ -4898,8 +4869,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
4898 | socket_fd, | 4869 | socket_fd, |
4899 | FD_SETSIZE); | 4870 | FD_SETSIZE); |
4900 | #endif | 4871 | #endif |
4901 | if (0 != MHD_socket_close_ (socket_fd)) | 4872 | MHD_socket_close_ (socket_fd); |
4902 | MHD_PANIC (_("close failed\n")); | ||
4903 | goto free_and_fail; | 4873 | goto free_and_fail; |
4904 | } | 4874 | } |
4905 | 4875 | ||
@@ -4936,9 +4906,8 @@ MHD_start_daemon_va (unsigned int flags, | |||
4936 | MHD_DLOG (daemon, | 4906 | MHD_DLOG (daemon, |
4937 | _("MHD failed to initialize IP connection limit mutex\n")); | 4907 | _("MHD failed to initialize IP connection limit mutex\n")); |
4938 | #endif | 4908 | #endif |
4939 | if ( (MHD_INVALID_SOCKET != socket_fd) && | 4909 | if (MHD_INVALID_SOCKET != socket_fd) |
4940 | (0 != MHD_socket_close_ (socket_fd)) ) | 4910 | MHD_socket_close_ (socket_fd); |
4941 | MHD_PANIC (_("close failed\n")); | ||
4942 | goto free_and_fail; | 4911 | goto free_and_fail; |
4943 | } | 4912 | } |
4944 | if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) | 4913 | if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) |
@@ -4947,10 +4916,9 @@ MHD_start_daemon_va (unsigned int flags, | |||
4947 | MHD_DLOG (daemon, | 4916 | MHD_DLOG (daemon, |
4948 | _("MHD failed to initialize IP connection limit mutex\n")); | 4917 | _("MHD failed to initialize IP connection limit mutex\n")); |
4949 | #endif | 4918 | #endif |
4950 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 4919 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
4951 | if ( (MHD_INVALID_SOCKET != socket_fd) && | 4920 | if (MHD_INVALID_SOCKET != socket_fd) |
4952 | (0 != MHD_socket_close_ (socket_fd)) ) | 4921 | MHD_socket_close_ (socket_fd); |
4953 | MHD_PANIC (_("close failed\n")); | ||
4954 | goto free_and_fail; | 4922 | goto free_and_fail; |
4955 | } | 4923 | } |
4956 | 4924 | ||
@@ -4963,11 +4931,10 @@ MHD_start_daemon_va (unsigned int flags, | |||
4963 | MHD_DLOG (daemon, | 4931 | MHD_DLOG (daemon, |
4964 | _("Failed to initialize TLS support\n")); | 4932 | _("Failed to initialize TLS support\n")); |
4965 | #endif | 4933 | #endif |
4966 | if ( (MHD_INVALID_SOCKET != socket_fd) && | 4934 | if (MHD_INVALID_SOCKET != socket_fd) |
4967 | (0 != MHD_socket_close_ (socket_fd)) ) | 4935 | MHD_socket_close_ (socket_fd); |
4968 | MHD_PANIC (_("close failed\n")); | 4936 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
4969 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 4937 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); |
4970 | (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); | ||
4971 | goto free_and_fail; | 4938 | goto free_and_fail; |
4972 | } | 4939 | } |
4973 | #endif | 4940 | #endif |
@@ -4987,11 +4954,10 @@ MHD_start_daemon_va (unsigned int flags, | |||
4987 | _("Failed to create listen thread: %s\n"), | 4954 | _("Failed to create listen thread: %s\n"), |
4988 | MHD_strerror_ (errno)); | 4955 | MHD_strerror_ (errno)); |
4989 | #endif | 4956 | #endif |
4990 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 4957 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
4991 | (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); | 4958 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); |
4992 | if ( (MHD_INVALID_SOCKET != socket_fd) && | 4959 | if (MHD_INVALID_SOCKET != socket_fd) |
4993 | (0 != MHD_socket_close_ (socket_fd)) ) | 4960 | MHD_socket_close_ (socket_fd); |
4994 | MHD_PANIC (_("close failed\n")); | ||
4995 | goto free_and_fail; | 4961 | goto free_and_fail; |
4996 | } | 4962 | } |
4997 | if ( (daemon->worker_pool_size > 0) && | 4963 | if ( (daemon->worker_pool_size > 0) && |
@@ -5107,7 +5073,7 @@ MHD_start_daemon_va (unsigned int flags, | |||
5107 | #endif | 5073 | #endif |
5108 | /* Free memory for this worker; cleanup below handles | 5074 | /* Free memory for this worker; cleanup below handles |
5109 | * all previously-created workers. */ | 5075 | * all previously-created workers. */ |
5110 | (void) MHD_mutex_destroy_ (&d->cleanup_connection_mutex); | 5076 | MHD_mutex_destroy_ (&d->cleanup_connection_mutex); |
5111 | goto thread_failed; | 5077 | goto thread_failed; |
5112 | } | 5078 | } |
5113 | } | 5079 | } |
@@ -5127,11 +5093,10 @@ thread_failed: | |||
5127 | MHD_USE_SELECT_INTERNALLY mode. */ | 5093 | MHD_USE_SELECT_INTERNALLY mode. */ |
5128 | if (0 == i) | 5094 | if (0 == i) |
5129 | { | 5095 | { |
5130 | if ( (MHD_INVALID_SOCKET != socket_fd) && | 5096 | if (MHD_INVALID_SOCKET != socket_fd) |
5131 | (0 != MHD_socket_close_ (socket_fd)) ) | 5097 | MHD_socket_close_ (socket_fd); |
5132 | MHD_PANIC (_("close failed\n")); | 5098 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
5133 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 5099 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); |
5134 | (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); | ||
5135 | if (NULL != daemon->worker_pool) | 5100 | if (NULL != daemon->worker_pool) |
5136 | free (daemon->worker_pool); | 5101 | free (daemon->worker_pool); |
5137 | goto free_and_fail; | 5102 | goto free_and_fail; |
@@ -5169,7 +5134,7 @@ thread_failed: | |||
5169 | #endif | 5134 | #endif |
5170 | #ifdef DAUTH_SUPPORT | 5135 | #ifdef DAUTH_SUPPORT |
5171 | free (daemon->nnc); | 5136 | free (daemon->nnc); |
5172 | (void) MHD_mutex_destroy_ (&daemon->nnc_lock); | 5137 | MHD_mutex_destroy_ (&daemon->nnc_lock); |
5173 | #endif | 5138 | #endif |
5174 | #if HTTPS_SUPPORT | 5139 | #if HTTPS_SUPPORT |
5175 | if (0 != (flags & MHD_USE_SSL)) | 5140 | if (0 != (flags & MHD_USE_SSL)) |
@@ -5231,11 +5196,15 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
5231 | { | 5196 | { |
5232 | struct MHD_Connection *pos; | 5197 | struct MHD_Connection *pos; |
5233 | 5198 | ||
5199 | /* Give suspended connections a chance to resume to avoid | ||
5200 | running into the check for there not being any suspended | ||
5201 | connections left in case of a tight race with a recently | ||
5202 | resumed connection. */ | ||
5203 | resume_suspended_connections (daemon); | ||
5234 | /* first, make sure all threads are aware of shutdown; need to | 5204 | /* first, make sure all threads are aware of shutdown; need to |
5235 | traverse DLLs in peace... */ | 5205 | traverse DLLs in peace... */ |
5236 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 5206 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
5237 | (! MHD_mutex_lock_ (&daemon->cleanup_connection_mutex)) ) | 5207 | MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); |
5238 | MHD_PANIC (_("Failed to acquire cleanup mutex\n")); | ||
5239 | if (NULL != daemon->suspended_connections_head) | 5208 | if (NULL != daemon->suspended_connections_head) |
5240 | MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); | 5209 | MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); |
5241 | for (pos = daemon->connections_head; NULL != pos; pos = pos->next) | 5210 | for (pos = daemon->connections_head; NULL != pos; pos = pos->next) |
@@ -5248,9 +5217,8 @@ close_all_connections (struct MHD_Daemon *daemon) | |||
5248 | MHD_PANIC (_("Failed to signal shutdown via pipe")); | 5217 | MHD_PANIC (_("Failed to signal shutdown via pipe")); |
5249 | #endif | 5218 | #endif |
5250 | } | 5219 | } |
5251 | if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && | 5220 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
5252 | (! MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex)) ) | 5221 | MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); |
5253 | MHD_PANIC (_("Failed to release cleanup mutex\n")); | ||
5254 | 5222 | ||
5255 | /* now, collect per-connection threads */ | 5223 | /* now, collect per-connection threads */ |
5256 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) | 5224 | if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) |
@@ -5392,15 +5360,13 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5392 | if (!MHD_join_thread_ (daemon->worker_pool[i].pid)) | 5360 | if (!MHD_join_thread_ (daemon->worker_pool[i].pid)) |
5393 | MHD_PANIC (_("Failed to join a thread\n")); | 5361 | MHD_PANIC (_("Failed to join a thread\n")); |
5394 | close_all_connections (&daemon->worker_pool[i]); | 5362 | close_all_connections (&daemon->worker_pool[i]); |
5395 | (void) MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex); | 5363 | MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex); |
5396 | #ifdef EPOLL_SUPPORT | 5364 | #ifdef EPOLL_SUPPORT |
5397 | if ( (-1 != daemon->worker_pool[i].epoll_fd) && | 5365 | if (-1 != daemon->worker_pool[i].epoll_fd) |
5398 | (0 != MHD_socket_close_ (daemon->worker_pool[i].epoll_fd)) ) | 5366 | MHD_socket_close_ (daemon->worker_pool[i].epoll_fd); |
5399 | MHD_PANIC (_("close failed\n")); | ||
5400 | #if HTTPS_SUPPORT | 5367 | #if HTTPS_SUPPORT |
5401 | if ( (-1 != daemon->worker_pool[i].epoll_upgrade_fd) && | 5368 | if (-1 != daemon->worker_pool[i].epoll_upgrade_fd) |
5402 | (0 != MHD_socket_close_ (daemon->worker_pool[i].epoll_upgrade_fd)) ) | 5369 | MHD_socket_close_ (daemon->worker_pool[i].epoll_upgrade_fd); |
5403 | MHD_PANIC (_("close failed\n")); | ||
5404 | #endif | 5370 | #endif |
5405 | #endif | 5371 | #endif |
5406 | /* Individual pipes are always used */ | 5372 | /* Individual pipes are always used */ |
@@ -5431,9 +5397,8 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5431 | } | 5397 | } |
5432 | } | 5398 | } |
5433 | close_all_connections (daemon); | 5399 | close_all_connections (daemon); |
5434 | if ( (MHD_INVALID_SOCKET != fd) && | 5400 | if (MHD_INVALID_SOCKET != fd) |
5435 | (0 != MHD_socket_close_ (fd)) ) | 5401 | MHD_socket_close_ (fd); |
5436 | MHD_PANIC (_("close failed\n")); | ||
5437 | 5402 | ||
5438 | /* TLS clean up */ | 5403 | /* TLS clean up */ |
5439 | #if HTTPS_SUPPORT | 5404 | #if HTTPS_SUPPORT |
@@ -5451,23 +5416,21 @@ MHD_stop_daemon (struct MHD_Daemon *daemon) | |||
5451 | #endif | 5416 | #endif |
5452 | #ifdef EPOLL_SUPPORT | 5417 | #ifdef EPOLL_SUPPORT |
5453 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && | 5418 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && |
5454 | (-1 != daemon->epoll_fd) && | 5419 | (-1 != daemon->epoll_fd) ) |
5455 | (0 != MHD_socket_close_ (daemon->epoll_fd)) ) | 5420 | MHD_socket_close_ (daemon->epoll_fd); |
5456 | MHD_PANIC (_("close failed\n")); | ||
5457 | #if HTTPS_SUPPORT | 5421 | #if HTTPS_SUPPORT |
5458 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && | 5422 | if ( (0 != (daemon->options & MHD_USE_EPOLL)) && |
5459 | (-1 != daemon->epoll_upgrade_fd) && | 5423 | (-1 != daemon->epoll_upgrade_fd) ) |
5460 | (0 != MHD_socket_close_ (daemon->epoll_upgrade_fd)) ) | 5424 | MHD_socket_close_ (daemon->epoll_upgrade_fd); |
5461 | MHD_PANIC (_("close failed\n")); | ||
5462 | #endif | 5425 | #endif |
5463 | #endif | 5426 | #endif |
5464 | 5427 | ||
5465 | #ifdef DAUTH_SUPPORT | 5428 | #ifdef DAUTH_SUPPORT |
5466 | free (daemon->nnc); | 5429 | free (daemon->nnc); |
5467 | (void) MHD_mutex_destroy_ (&daemon->nnc_lock); | 5430 | MHD_mutex_destroy_ (&daemon->nnc_lock); |
5468 | #endif | 5431 | #endif |
5469 | (void) MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); | 5432 | MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); |
5470 | (void) MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); | 5433 | MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); |
5471 | 5434 | ||
5472 | if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) | 5435 | if (MHD_INVALID_PIPE_ != daemon->wpipe[1]) |
5473 | { | 5436 | { |
@@ -5735,14 +5698,16 @@ gcry_w32_mutex_destroy (void **ppmtx) | |||
5735 | static int | 5698 | static int |
5736 | gcry_w32_mutex_lock (void **ppmtx) | 5699 | gcry_w32_mutex_lock (void **ppmtx) |
5737 | { | 5700 | { |
5738 | return (MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1; | 5701 | MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx); |
5702 | return 0; | ||
5739 | } | 5703 | } |
5740 | 5704 | ||
5741 | 5705 | ||
5742 | static int | 5706 | static int |
5743 | gcry_w32_mutex_unlock (void **ppmtx) | 5707 | gcry_w32_mutex_unlock (void **ppmtx) |
5744 | { | 5708 | { |
5745 | return (MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1; | 5709 | MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx); |
5710 | return 0; | ||
5746 | } | 5711 | } |
5747 | 5712 | ||
5748 | 5713 | ||
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c index 769fb3e4..5060d253 100644 --- a/src/microhttpd/digestauth.c +++ b/src/microhttpd/digestauth.c | |||
@@ -408,7 +408,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
408 | * then only increase the nonce counter by one. | 408 | * then only increase the nonce counter by one. |
409 | */ | 409 | */ |
410 | nn = &daemon->nnc[off]; | 410 | nn = &daemon->nnc[off]; |
411 | (void) MHD_mutex_lock_ (&daemon->nnc_lock); | 411 | MHD_mutex_lock_ (&daemon->nnc_lock); |
412 | if (0 == nc) | 412 | if (0 == nc) |
413 | { | 413 | { |
414 | /* Fresh nonce, reinitialize array */ | 414 | /* Fresh nonce, reinitialize array */ |
@@ -416,7 +416,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
416 | nonce); | 416 | nonce); |
417 | nn->nc = 0; | 417 | nn->nc = 0; |
418 | nn->nmask = 0; | 418 | nn->nmask = 0; |
419 | (void) MHD_mutex_unlock_ (&daemon->nnc_lock); | 419 | MHD_mutex_unlock_ (&daemon->nnc_lock); |
420 | return MHD_YES; | 420 | return MHD_YES; |
421 | } | 421 | } |
422 | /* Note that we use 64 here, as we do not store the | 422 | /* Note that we use 64 here, as we do not store the |
@@ -428,7 +428,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
428 | { | 428 | { |
429 | /* Out-of-order nonce, but within 64-bit bitmask, set bit */ | 429 | /* Out-of-order nonce, but within 64-bit bitmask, set bit */ |
430 | nn->nmask |= (1LLU < (nn->nc - nc - 1)); | 430 | nn->nmask |= (1LLU < (nn->nc - nc - 1)); |
431 | (void) MHD_mutex_unlock_ (&daemon->nnc_lock); | 431 | MHD_mutex_unlock_ (&daemon->nnc_lock); |
432 | return MHD_YES; | 432 | return MHD_YES; |
433 | } | 433 | } |
434 | 434 | ||
@@ -437,7 +437,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
437 | nonce)) ) | 437 | nonce)) ) |
438 | { | 438 | { |
439 | /* Nonce does not match, fail */ | 439 | /* Nonce does not match, fail */ |
440 | (void) MHD_mutex_unlock_ (&daemon->nnc_lock); | 440 | MHD_mutex_unlock_ (&daemon->nnc_lock); |
441 | #ifdef HAVE_MESSAGES | 441 | #ifdef HAVE_MESSAGES |
442 | MHD_DLOG (daemon, | 442 | MHD_DLOG (daemon, |
443 | _("Stale nonce received. If this happens a lot, you should probably increase the size of the nonce array.\n")); | 443 | _("Stale nonce received. If this happens a lot, you should probably increase the size of the nonce array.\n")); |
@@ -450,7 +450,7 @@ check_nonce_nc (struct MHD_Connection *connection, | |||
450 | else | 450 | else |
451 | nn->nmask = 0; /* big jump, unset all bits in the mask */ | 451 | nn->nmask = 0; /* big jump, unset all bits in the mask */ |
452 | nn->nc = nc; | 452 | nn->nc = nc; |
453 | (void) MHD_mutex_unlock_ (&daemon->nnc_lock); | 453 | MHD_mutex_unlock_ (&daemon->nnc_lock); |
454 | return MHD_YES; | 454 | return MHD_YES; |
455 | } | 455 | } |
456 | 456 | ||
diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index 61e08a38..ff554581 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <gnutls/abstract.h> | 35 | #include <gnutls/abstract.h> |
36 | #endif | 36 | #endif |
37 | #endif | 37 | #endif |
38 | |||
38 | #include "mhd_threads.h" | 39 | #include "mhd_threads.h" |
39 | #include "mhd_locks.h" | 40 | #include "mhd_locks.h" |
40 | #include "mhd_sockets.h" | 41 | #include "mhd_sockets.h" |
@@ -42,14 +43,6 @@ | |||
42 | 43 | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Macro to make it easy to mark text for translation. Note that | ||
46 | * we do not actually call gettext() in MHD, but we do make it | ||
47 | * easy to create a ".po" file so that applications that do want | ||
48 | * to translate error messages can do so. | ||
49 | */ | ||
50 | #define _(String) String | ||
51 | |||
52 | /** | ||
53 | * Should we perform additional sanity checks at runtime (on our internal | 46 | * Should we perform additional sanity checks at runtime (on our internal |
54 | * invariants)? This may lead to aborts, but can be useful for debugging. | 47 | * invariants)? This may lead to aborts, but can be useful for debugging. |
55 | */ | 48 | */ |
diff --git a/src/microhttpd/mhd_locks.h b/src/microhttpd/mhd_locks.h index 1d8376f0..f69c7861 100644 --- a/src/microhttpd/mhd_locks.h +++ b/src/microhttpd/mhd_locks.h | |||
@@ -80,16 +80,19 @@ | |||
80 | /** | 80 | /** |
81 | * Destroy previously initialised mutex. | 81 | * Destroy previously initialised mutex. |
82 | * @param pmutex pointer to mutex | 82 | * @param pmutex pointer to mutex |
83 | * @return nonzero on success, zero otherwise | ||
84 | */ | 83 | */ |
85 | #define MHD_mutex_destroy_(pmutex) (!(pthread_mutex_destroy((pmutex)))) | 84 | #define MHD_mutex_destroy_(pmutex) do { \ |
85 | if ( (0 != pthread_mutex_destroy((pmutex))) && \ | ||
86 | (EAGAIN != errno) && \ | ||
87 | (EINPROGRESS != errno) ) \ | ||
88 | MHD_PANIC (_("Failed to destroy mutex\n")); \ | ||
89 | } while (0) | ||
86 | #elif defined(MHD_W32_MUTEX_) | 90 | #elif defined(MHD_W32_MUTEX_) |
87 | /** | 91 | /** |
88 | * Destroy previously initialised mutex. | 92 | * Destroy previously initialised mutex. |
89 | * @param pmutex pointer to mutex | 93 | * @param pmutex pointer to mutex |
90 | * @return Always nonzero | ||
91 | */ | 94 | */ |
92 | #define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection((pmutex)), !0) | 95 | #define MHD_mutex_destroy_(pmutex) DeleteCriticalSection((pmutex)) |
93 | #endif | 96 | #endif |
94 | 97 | ||
95 | #if defined(MHD_PTHREAD_MUTEX_) | 98 | #if defined(MHD_PTHREAD_MUTEX_) |
@@ -98,38 +101,19 @@ | |||
98 | * If mutex was already locked by other thread, function | 101 | * If mutex was already locked by other thread, function |
99 | * blocks until mutex becomes available. | 102 | * blocks until mutex becomes available. |
100 | * @param pmutex pointer to mutex | 103 | * @param pmutex pointer to mutex |
101 | * @return nonzero on success, zero otherwise | ||
102 | */ | 104 | */ |
103 | #define MHD_mutex_lock_(pmutex) (!(pthread_mutex_lock((pmutex)))) | 105 | #define MHD_mutex_lock_(pmutex) do { \ |
106 | if (0 != pthread_mutex_lock((pmutex))) \ | ||
107 | MHD_PANIC (_("Failed to lock mutex\n")); \ | ||
108 | } while (0) | ||
104 | #elif defined(MHD_W32_MUTEX_) | 109 | #elif defined(MHD_W32_MUTEX_) |
105 | /** | 110 | /** |
106 | * Acquire lock on previously initialised mutex. | 111 | * Acquire lock on previously initialised mutex. |
107 | * If mutex was already locked by other thread, function | 112 | * If mutex was already locked by other thread, function |
108 | * blocks until mutex becomes available. | 113 | * blocks until mutex becomes available. |
109 | * @param pmutex pointer to mutex | 114 | * @param pmutex pointer to mutex |
110 | * @return Always nonzero | ||
111 | */ | ||
112 | #define MHD_mutex_lock_(pmutex) (EnterCriticalSection((pmutex)), !0) | ||
113 | #endif | ||
114 | |||
115 | #if defined(MHD_PTHREAD_MUTEX_) | ||
116 | /** | ||
117 | * Try to acquire lock on previously initialised mutex. | ||
118 | * Function returns immediately. | ||
119 | * @param pmutex pointer to mutex | ||
120 | * @return nonzero if mutex is locked, zero if | ||
121 | * mutex was not locked. | ||
122 | */ | ||
123 | #define MHD_mutex_trylock_(pmutex) (!(pthread_mutex_trylock((pmutex)))) | ||
124 | #elif defined(MHD_W32_MUTEX_) | ||
125 | /** | ||
126 | * Try to acquire lock on previously initialised mutex. | ||
127 | * Function returns immediately. | ||
128 | * @param pmutex pointer to mutex | ||
129 | * @return nonzero if mutex is locked, zero if | ||
130 | * mutex was not locked. | ||
131 | */ | 115 | */ |
132 | #define MHD_mutex_trylock_(pmutex) (TryEnterCriticalSection((pmutex)))) | 116 | #define MHD_mutex_lock_(pmutex) EnterCriticalSection((pmutex)) |
133 | #endif | 117 | #endif |
134 | 118 | ||
135 | #if defined(MHD_PTHREAD_MUTEX_) | 119 | #if defined(MHD_PTHREAD_MUTEX_) |
@@ -138,14 +122,17 @@ | |||
138 | * @param pmutex pointer to mutex | 122 | * @param pmutex pointer to mutex |
139 | * @return nonzero on success, zero otherwise | 123 | * @return nonzero on success, zero otherwise |
140 | */ | 124 | */ |
141 | #define MHD_mutex_unlock_(pmutex) (!(pthread_mutex_unlock((pmutex)))) | 125 | #define MHD_mutex_unlock_(pmutex) do { \ |
126 | if (0 != pthread_mutex_unlock((pmutex))) \ | ||
127 | MHD_PANIC (_("Failed to unlock mutex\n")); \ | ||
128 | } while (0) | ||
142 | #elif defined(MHD_W32_MUTEX_) | 129 | #elif defined(MHD_W32_MUTEX_) |
143 | /** | 130 | /** |
144 | * Unlock previously initialised and locked mutex. | 131 | * Unlock previously initialised and locked mutex. |
145 | * @param pmutex pointer to mutex | 132 | * @param pmutex pointer to mutex |
146 | * @return Always nonzero | 133 | * @return Always nonzero |
147 | */ | 134 | */ |
148 | #define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection((pmutex)), !0) | 135 | #define MHD_mutex_unlock_(pmutex) LeaveCriticalSection((pmutex)) |
149 | #endif | 136 | #endif |
150 | 137 | ||
151 | 138 | ||
diff --git a/src/microhttpd/mhd_sem.c b/src/microhttpd/mhd_sem.c index d4d6600b..724d6c45 100644 --- a/src/microhttpd/mhd_sem.c +++ b/src/microhttpd/mhd_sem.c | |||
@@ -89,16 +89,16 @@ void | |||
89 | MHD_semaphore_down (struct MHD_Semaphore *sem) | 89 | MHD_semaphore_down (struct MHD_Semaphore *sem) |
90 | { | 90 | { |
91 | if (0 != pthread_mutex_lock (&sem->mutex)) | 91 | if (0 != pthread_mutex_lock (&sem->mutex)) |
92 | MHD_PANIC ("pthread_mutex_lock for semaphore failed\n"); | 92 | MHD_PANIC (_("Failed to lock mutex\n")); |
93 | while (0 == sem->counter) | 93 | while (0 == sem->counter) |
94 | { | 94 | { |
95 | if (0 != pthread_cond_wait (&sem->cv, | 95 | if (0 != pthread_cond_wait (&sem->cv, |
96 | &sem->mutex)) | 96 | &sem->mutex)) |
97 | MHD_PANIC ("pthread_cond_wait failed\n"); | 97 | MHD_PANIC (_("pthread_cond_wait failed\n")); |
98 | } | 98 | } |
99 | sem->counter--; | 99 | sem->counter--; |
100 | if (0 != pthread_mutex_unlock (&sem->mutex)) | 100 | if (0 != pthread_mutex_unlock (&sem->mutex)) |
101 | MHD_PANIC ("pthread_mutex_unlock for semaphore failed\n"); | 101 | MHD_PANIC (_("Failed to unlock mutex\n")); |
102 | } | 102 | } |
103 | 103 | ||
104 | 104 | ||
@@ -111,11 +111,11 @@ void | |||
111 | MHD_semaphore_up (struct MHD_Semaphore *sem) | 111 | MHD_semaphore_up (struct MHD_Semaphore *sem) |
112 | { | 112 | { |
113 | if (0 != pthread_mutex_lock (&sem->mutex)) | 113 | if (0 != pthread_mutex_lock (&sem->mutex)) |
114 | MHD_PANIC ("pthread_mutex_lock for semaphore failed\n"); | 114 | MHD_PANIC (_("Failed to lock mutex\n")); |
115 | sem->counter++; | 115 | sem->counter++; |
116 | pthread_cond_signal (&sem->cv); | 116 | pthread_cond_signal (&sem->cv); |
117 | if (0 != pthread_mutex_unlock (&sem->mutex)) | 117 | if (0 != pthread_mutex_unlock (&sem->mutex)) |
118 | MHD_PANIC ("pthread_mutex_unlock for semaphore failed\n"); | 118 | MHD_PANIC (_("Failed to unlock mutex\n")); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
@@ -128,9 +128,9 @@ void | |||
128 | MHD_semaphore_destroy (struct MHD_Semaphore *sem) | 128 | MHD_semaphore_destroy (struct MHD_Semaphore *sem) |
129 | { | 129 | { |
130 | if (0 != pthread_cond_destroy (&sem->cv)) | 130 | if (0 != pthread_cond_destroy (&sem->cv)) |
131 | MHD_PANIC ("pthread_cond_destroy failed\n"); | 131 | MHD_PANIC (_("pthread_cond_destroy failed\n")); |
132 | if (0 != pthread_mutex_destroy (&sem->mutex)) | 132 | if (0 != pthread_mutex_destroy (&sem->mutex)) |
133 | MHD_PANIC ("pthread_mutex_destroy failed\n"); | 133 | MHD_PANIC (_("Failed to destroy mutex\n")); |
134 | free (sem); | 134 | free (sem); |
135 | } | 135 | } |
136 | 136 | ||
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h index cc8f88b6..1bcd0a04 100644 --- a/src/microhttpd/mhd_sockets.h +++ b/src/microhttpd/mhd_sockets.h | |||
@@ -195,13 +195,18 @@ | |||
195 | * errno is set to EINTR. Do not use HP-UNIX. | 195 | * errno is set to EINTR. Do not use HP-UNIX. |
196 | * | 196 | * |
197 | * @param fd descriptor to close | 197 | * @param fd descriptor to close |
198 | * @return 0 on success (error codes like EINTR and EIO are counted as success, | ||
199 | * only EBADF counts as an error!) | ||
200 | */ | 198 | */ |
201 | #if !defined(MHD_WINSOCK_SOCKETS) | 199 | #if !defined(MHD_WINSOCK_SOCKETS) |
202 | # define MHD_socket_close_(fd) (((0 != close(fd)) && (EBADF == errno)) ? -1 : 0) | 200 | # define MHD_socket_close_(fd) do { \ |
201 | if ( (0 != close((fd))) && \ | ||
202 | (EBADF == errno) ) \ | ||
203 | MHD_PANIC (_("close failed\n")); \ | ||
204 | } while (0) | ||
203 | #else | 205 | #else |
204 | # define MHD_socket_close_(fd) closesocket((fd)) | 206 | # define MHD_socket_close_(fd) do { \ |
207 | if (0 != closesocket((fd)) ) \ | ||
208 | MHD_PANIC (_("close failed\n")); \ | ||
209 | } while (0) | ||
205 | #endif | 210 | #endif |
206 | 211 | ||
207 | /** | 212 | /** |
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c index 15ad91e6..3e4040c4 100644 --- a/src/microhttpd/response.c +++ b/src/microhttpd/response.c | |||
@@ -568,7 +568,7 @@ MHD_create_response_from_data (size_t size, | |||
568 | { | 568 | { |
569 | if (NULL == (tmp = malloc (size))) | 569 | if (NULL == (tmp = malloc (size))) |
570 | { | 570 | { |
571 | (void) MHD_mutex_destroy_ (&response->mutex); | 571 | MHD_mutex_destroy_ (&response->mutex); |
572 | free (response); | 572 | free (response); |
573 | return NULL; | 573 | return NULL; |
574 | } | 574 | } |
@@ -655,8 +655,7 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh, | |||
655 | urh->was_closed = MHD_YES; | 655 | urh->was_closed = MHD_YES; |
656 | if (MHD_INVALID_SOCKET != urh->app.socket) | 656 | if (MHD_INVALID_SOCKET != urh->app.socket) |
657 | { | 657 | { |
658 | if (0 != MHD_socket_close_ (urh->app.socket)) | 658 | MHD_socket_close_ (urh->app.socket); |
659 | MHD_PANIC (_("close failed\n")); | ||
660 | urh->app.socket = MHD_INVALID_SOCKET; | 659 | urh->app.socket = MHD_INVALID_SOCKET; |
661 | } | 660 | } |
662 | return MHD_YES; | 661 | return MHD_YES; |
@@ -743,10 +742,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
743 | (int) sv[1], | 742 | (int) sv[1], |
744 | (int) FD_SETSIZE); | 743 | (int) FD_SETSIZE); |
745 | #endif | 744 | #endif |
746 | if (0 != MHD_socket_close_ (sv[0])) | 745 | MHD_socket_close_ (sv[0]); |
747 | MHD_PANIC (_("close failed\n")); | 746 | MHD_socket_close_ (sv[1]); |
748 | if (0 != MHD_socket_close_ (sv[1])) | ||
749 | MHD_PANIC (_("close failed\n")); | ||
750 | free (urh); | 747 | free (urh); |
751 | return MHD_NO; | 748 | return MHD_NO; |
752 | } | 749 | } |
@@ -817,10 +814,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
817 | _("Call to epoll_ctl failed: %s\n"), | 814 | _("Call to epoll_ctl failed: %s\n"), |
818 | MHD_socket_last_strerr_ ()); | 815 | MHD_socket_last_strerr_ ()); |
819 | #endif | 816 | #endif |
820 | if (0 != MHD_socket_close_ (sv[0])) | 817 | MHD_socket_close_ (sv[0]); |
821 | MHD_PANIC (_("close failed\n")); | 818 | MHD_socket_close_ (sv[1]); |
822 | if (0 != MHD_socket_close_ (sv[1])) | ||
823 | MHD_PANIC (_("close failed\n")); | ||
824 | free (urh); | 819 | free (urh); |
825 | return MHD_NO; | 820 | return MHD_NO; |
826 | } | 821 | } |
@@ -845,10 +840,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response, | |||
845 | _("Call to epoll_ctl failed: %s\n"), | 840 | _("Call to epoll_ctl failed: %s\n"), |
846 | MHD_socket_last_strerr_ ()); | 841 | MHD_socket_last_strerr_ ()); |
847 | #endif | 842 | #endif |
848 | if (0 != MHD_socket_close_ (sv[0])) | 843 | MHD_socket_close_ (sv[0]); |
849 | MHD_PANIC (_("close failed\n")); | 844 | MHD_socket_close_ (sv[1]); |
850 | if (0 != MHD_socket_close_ (sv[1])) | ||
851 | MHD_PANIC (_("close failed\n")); | ||
852 | free (urh); | 845 | free (urh); |
853 | return MHD_NO; | 846 | return MHD_NO; |
854 | } | 847 | } |
@@ -993,14 +986,14 @@ MHD_destroy_response (struct MHD_Response *response) | |||
993 | 986 | ||
994 | if (NULL == response) | 987 | if (NULL == response) |
995 | return; | 988 | return; |
996 | (void) MHD_mutex_lock_ (&response->mutex); | 989 | MHD_mutex_lock_ (&response->mutex); |
997 | if (0 != --(response->reference_count)) | 990 | if (0 != --(response->reference_count)) |
998 | { | 991 | { |
999 | (void) MHD_mutex_unlock_ (&response->mutex); | 992 | MHD_mutex_unlock_ (&response->mutex); |
1000 | return; | 993 | return; |
1001 | } | 994 | } |
1002 | (void) MHD_mutex_unlock_ (&response->mutex); | 995 | MHD_mutex_unlock_ (&response->mutex); |
1003 | (void) MHD_mutex_destroy_ (&response->mutex); | 996 | MHD_mutex_destroy_ (&response->mutex); |
1004 | if (NULL != response->crfc) | 997 | if (NULL != response->crfc) |
1005 | response->crfc (response->crc_cls); | 998 | response->crfc (response->crc_cls); |
1006 | while (NULL != response->first_header) | 999 | while (NULL != response->first_header) |
@@ -1023,9 +1016,9 @@ MHD_destroy_response (struct MHD_Response *response) | |||
1023 | void | 1016 | void |
1024 | MHD_increment_response_rc (struct MHD_Response *response) | 1017 | MHD_increment_response_rc (struct MHD_Response *response) |
1025 | { | 1018 | { |
1026 | (void) MHD_mutex_lock_ (&response->mutex); | 1019 | MHD_mutex_lock_ (&response->mutex); |
1027 | (response->reference_count)++; | 1020 | (response->reference_count)++; |
1028 | (void) MHD_mutex_unlock_ (&response->mutex); | 1021 | MHD_mutex_unlock_ (&response->mutex); |
1029 | } | 1022 | } |
1030 | 1023 | ||
1031 | 1024 | ||
diff --git a/src/microhttpd/test_shutdown_select.c b/src/microhttpd/test_shutdown_select.c index a40ac9cc..63c0c53c 100644 --- a/src/microhttpd/test_shutdown_select.c +++ b/src/microhttpd/test_shutdown_select.c | |||
@@ -89,6 +89,15 @@ | |||
89 | 89 | ||
90 | static _MHD_bool check_err; | 90 | static _MHD_bool check_err; |
91 | 91 | ||
92 | |||
93 | void | ||
94 | MHD_PANIC (char *msg) | ||
95 | { | ||
96 | fprintf (stderr, "%s", msg); | ||
97 | abort (); | ||
98 | } | ||
99 | |||
100 | |||
92 | static _MHD_bool | 101 | static _MHD_bool |
93 | has_in_name(const char *prog_name, const char *marker) | 102 | has_in_name(const char *prog_name, const char *marker) |
94 | { | 103 | { |
diff --git a/src/microhttpd/test_upgrade_common.c b/src/microhttpd/test_upgrade_common.c index 2067a0e6..47a2fc95 100644 --- a/src/microhttpd/test_upgrade_common.c +++ b/src/microhttpd/test_upgrade_common.c | |||
@@ -45,6 +45,15 @@ static pthread_t pt_client; | |||
45 | */ | 45 | */ |
46 | static int done; | 46 | static int done; |
47 | 47 | ||
48 | |||
49 | void | ||
50 | MHD_PANIC (char *msg) | ||
51 | { | ||
52 | fprintf (stderr, "%s", msg); | ||
53 | abort (); | ||
54 | } | ||
55 | |||
56 | |||
48 | /** | 57 | /** |
49 | * Change socket to non-blocking. | 58 | * Change socket to non-blocking. |
50 | * | 59 | * |
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c index 914100eb..b1725256 100644 --- a/src/testcurl/https/test_https_time_out.c +++ b/src/testcurl/https/test_https_time_out.c | |||
@@ -32,6 +32,16 @@ | |||
32 | #include <gcrypt.h> | 32 | #include <gcrypt.h> |
33 | #include "mhd_sockets.h" /* only macros used */ | 33 | #include "mhd_sockets.h" /* only macros used */ |
34 | 34 | ||
35 | #undef MHD_PANIC | ||
36 | |||
37 | |||
38 | void | ||
39 | MHD_PANIC (char *msg) | ||
40 | { | ||
41 | fprintf (stderr, "%s", msg); | ||
42 | abort (); | ||
43 | } | ||
44 | |||
35 | #ifdef _WIN32 | 45 | #ifdef _WIN32 |
36 | #ifndef WIN32_LEAN_AND_MEAN | 46 | #ifndef WIN32_LEAN_AND_MEAN |
37 | #define WIN32_LEAN_AND_MEAN 1 | 47 | #define WIN32_LEAN_AND_MEAN 1 |
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c index a987aac1..1077983a 100644 --- a/src/testcurl/test_callback.c +++ b/src/testcurl/test_callback.c | |||
@@ -73,14 +73,19 @@ callback(void *cls, | |||
73 | r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, | 73 | r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024, |
74 | &called_twice, cbc, | 74 | &called_twice, cbc, |
75 | &free); | 75 | &free); |
76 | MHD_queue_response(connection, MHD_HTTP_OK, r); | 76 | MHD_queue_response (connection, |
77 | MHD_destroy_response(r); | 77 | MHD_HTTP_OK, |
78 | r); | ||
79 | MHD_destroy_response (r); | ||
78 | return MHD_YES; | 80 | return MHD_YES; |
79 | } | 81 | } |
80 | 82 | ||
81 | 83 | ||
82 | static size_t | 84 | static size_t |
83 | discard_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 85 | discard_buffer (void *ptr, |
86 | size_t size, | ||
87 | size_t nmemb, | ||
88 | void *ctx) | ||
84 | { | 89 | { |
85 | return size * nmemb; | 90 | return size * nmemb; |
86 | } | 91 | } |
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c index 1fc6df17..19740042 100644 --- a/src/testcurl/test_get.c +++ b/src/testcurl/test_get.c | |||
@@ -34,6 +34,14 @@ | |||
34 | #include <time.h> | 34 | #include <time.h> |
35 | #include "mhd_sockets.h" /* only macros used */ | 35 | #include "mhd_sockets.h" /* only macros used */ |
36 | 36 | ||
37 | void | ||
38 | MHD_PANIC (char *msg) | ||
39 | { | ||
40 | fprintf (stderr, "%s", msg); | ||
41 | abort (); | ||
42 | } | ||
43 | |||
44 | |||
37 | #ifdef _WIN32 | 45 | #ifdef _WIN32 |
38 | #ifndef WIN32_LEAN_AND_MEAN | 46 | #ifndef WIN32_LEAN_AND_MEAN |
39 | #define WIN32_LEAN_AND_MEAN 1 | 47 | #define WIN32_LEAN_AND_MEAN 1 |
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c index 9ff3086c..2b119608 100644 --- a/src/testcurl/test_quiesce.c +++ b/src/testcurl/test_quiesce.c | |||
@@ -34,6 +34,14 @@ | |||
34 | #include <pthread.h> | 34 | #include <pthread.h> |
35 | #include "mhd_sockets.h" /* only macros used */ | 35 | #include "mhd_sockets.h" /* only macros used */ |
36 | 36 | ||
37 | void | ||
38 | MHD_PANIC (char *msg) | ||
39 | { | ||
40 | fprintf (stderr, "%s", msg); | ||
41 | abort (); | ||
42 | } | ||
43 | |||
44 | |||
37 | #ifndef WINDOWS | 45 | #ifndef WINDOWS |
38 | #include <unistd.h> | 46 | #include <unistd.h> |
39 | #include <sys/socket.h> | 47 | #include <sys/socket.h> |