aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-10-11 15:20:40 +0000
committerEvgeny Grin (Karlson2k) <k2k@narod.ru>2016-10-11 15:20:40 +0000
commita8948d201be986112a2a616b2ff30e58e8a8f08f (patch)
treecf8211f0691aa1a1f6f40b6e051b5be6ddd9dfae
parent3675d8e5a77e91147a14da7bdbbdcc9fe6a3b5d6 (diff)
downloadlibmicrohttpd-a8948d201be986112a2a616b2ff30e58e8a8f08f.tar.gz
libmicrohttpd-a8948d201be986112a2a616b2ff30e58e8a8f08f.zip
Refactored mhd_locks.h and mhd_sockets.h: allow usage of macros without
aborting of execution.
-rw-r--r--src/microhttpd/connection.c26
-rw-r--r--src/microhttpd/daemon.c118
-rw-r--r--src/microhttpd/digestauth.c10
-rw-r--r--src/microhttpd/internal.h40
-rw-r--r--src/microhttpd/mhd_itc.h4
-rw-r--r--src/microhttpd/mhd_locks.h67
-rw-r--r--src/microhttpd/mhd_sockets.h33
-rw-r--r--src/microhttpd/response.c28
-rw-r--r--src/microhttpd/test_shutdown_select.c28
-rw-r--r--src/microhttpd/test_upgrade_common.c9
-rw-r--r--src/microhttpd/test_upgrade_ssl.c6
-rw-r--r--src/testcurl/https/test_https_time_out.c18
-rw-r--r--src/testcurl/https/test_tls_extensions.c2
-rw-r--r--src/testcurl/test_get.c11
-rw-r--r--src/testcurl/test_quiesce.c19
15 files changed, 218 insertions, 201 deletions
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index e23a196c..891ade9b 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 MHD_mutex_unlock_ (&response->mutex); 617 MHD_mutex_unlock_chk_ (&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 MHD_mutex_unlock_ (&response->mutex); 631 MHD_mutex_unlock_chk_ (&response->mutex);
632 return MHD_NO; 632 return MHD_NO;
633 } 633 }
634 return MHD_YES; 634 return MHD_YES;
@@ -2457,7 +2457,7 @@ 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 MHD_mutex_lock_ (&response->mutex); 2460 MHD_mutex_lock_chk_ (&response->mutex);
2461 if (MHD_YES != try_ready_normal_body (connection)) 2461 if (MHD_YES != try_ready_normal_body (connection))
2462 { 2462 {
2463 /* mutex was already unlocked by try_ready_normal_body */ 2463 /* mutex was already unlocked by try_ready_normal_body */
@@ -2483,7 +2483,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
2483 response->data_start]); 2483 response->data_start]);
2484#endif 2484#endif
2485 if (NULL != response->crc) 2485 if (NULL != response->crc)
2486 MHD_mutex_unlock_ (&response->mutex); 2486 MHD_mutex_unlock_chk_ (&response->mutex);
2487 if (ret < 0) 2487 if (ret < 0)
2488 { 2488 {
2489 if (MHD_SCKT_ERR_IS_EINTR_ (err) || 2489 if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
@@ -2569,7 +2569,7 @@ cleanup_connection (struct MHD_Connection *connection)
2569 } 2569 }
2570 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2570 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2571 { 2571 {
2572 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 2572 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2573 } 2573 }
2574 else 2574 else
2575 { 2575 {
@@ -2597,7 +2597,7 @@ cleanup_connection (struct MHD_Connection *connection)
2597 connection->resuming = MHD_NO; 2597 connection->resuming = MHD_NO;
2598 connection->in_idle = MHD_NO; 2598 connection->in_idle = MHD_NO;
2599 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2599 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2600 MHD_mutex_unlock_(&daemon->cleanup_connection_mutex); 2600 MHD_mutex_unlock_chk_(&daemon->cleanup_connection_mutex);
2601} 2601}
2602 2602
2603 2603
@@ -2906,18 +2906,18 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2906 break; 2906 break;
2907 case MHD_CONNECTION_NORMAL_BODY_UNREADY: 2907 case MHD_CONNECTION_NORMAL_BODY_UNREADY:
2908 if (NULL != connection->response->crc) 2908 if (NULL != connection->response->crc)
2909 MHD_mutex_lock_ (&connection->response->mutex); 2909 MHD_mutex_lock_chk_ (&connection->response->mutex);
2910 if (0 == connection->response->total_size) 2910 if (0 == connection->response->total_size)
2911 { 2911 {
2912 if (NULL != connection->response->crc) 2912 if (NULL != connection->response->crc)
2913 MHD_mutex_unlock_ (&connection->response->mutex); 2913 MHD_mutex_unlock_chk_ (&connection->response->mutex);
2914 connection->state = MHD_CONNECTION_BODY_SENT; 2914 connection->state = MHD_CONNECTION_BODY_SENT;
2915 continue; 2915 continue;
2916 } 2916 }
2917 if (MHD_YES == try_ready_normal_body (connection)) 2917 if (MHD_YES == try_ready_normal_body (connection))
2918 { 2918 {
2919 if (NULL != connection->response->crc) 2919 if (NULL != connection->response->crc)
2920 MHD_mutex_unlock_ (&connection->response->mutex); 2920 MHD_mutex_unlock_chk_ (&connection->response->mutex);
2921 connection->state = MHD_CONNECTION_NORMAL_BODY_READY; 2921 connection->state = MHD_CONNECTION_NORMAL_BODY_READY;
2922 /* Buffering for flushable socket was already enabled*/ 2922 /* Buffering for flushable socket was already enabled*/
2923 if (MHD_NO == socket_flush_possible (connection)) 2923 if (MHD_NO == socket_flush_possible (connection))
@@ -2932,20 +2932,20 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2932 break; 2932 break;
2933 case MHD_CONNECTION_CHUNKED_BODY_UNREADY: 2933 case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
2934 if (NULL != connection->response->crc) 2934 if (NULL != connection->response->crc)
2935 MHD_mutex_lock_ (&connection->response->mutex); 2935 MHD_mutex_lock_chk_ (&connection->response->mutex);
2936 if ( (0 == connection->response->total_size) || 2936 if ( (0 == connection->response->total_size) ||
2937 (connection->response_write_position == 2937 (connection->response_write_position ==
2938 connection->response->total_size) ) 2938 connection->response->total_size) )
2939 { 2939 {
2940 if (NULL != connection->response->crc) 2940 if (NULL != connection->response->crc)
2941 MHD_mutex_unlock_ (&connection->response->mutex); 2941 MHD_mutex_unlock_chk_ (&connection->response->mutex);
2942 connection->state = MHD_CONNECTION_BODY_SENT; 2942 connection->state = MHD_CONNECTION_BODY_SENT;
2943 continue; 2943 continue;
2944 } 2944 }
2945 if (MHD_YES == try_ready_chunked_body (connection)) 2945 if (MHD_YES == try_ready_chunked_body (connection))
2946 { 2946 {
2947 if (NULL != connection->response->crc) 2947 if (NULL != connection->response->crc)
2948 MHD_mutex_unlock_ (&connection->response->mutex); 2948 MHD_mutex_unlock_chk_ (&connection->response->mutex);
2949 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY; 2949 connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
2950 /* Buffering for flushable socket was already enabled */ 2950 /* Buffering for flushable socket was already enabled */
2951 if (MHD_NO == socket_flush_possible (connection)) 2951 if (MHD_NO == socket_flush_possible (connection))
@@ -2953,7 +2953,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
2953 continue; 2953 continue;
2954 } 2954 }
2955 if (NULL != connection->response->crc) 2955 if (NULL != connection->response->crc)
2956 MHD_mutex_unlock_ (&connection->response->mutex); 2956 MHD_mutex_unlock_chk_ (&connection->response->mutex);
2957 break; 2957 break;
2958 case MHD_CONNECTION_BODY_SENT: 2958 case MHD_CONNECTION_BODY_SENT:
2959 if (MHD_NO == build_header_response (connection)) 2959 if (MHD_NO == build_header_response (connection))
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 969c797c..ce1b5939 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -195,7 +195,7 @@ struct MHD_IPCount
195static void 195static void
196MHD_ip_count_lock (struct MHD_Daemon *daemon) 196MHD_ip_count_lock (struct MHD_Daemon *daemon)
197{ 197{
198 MHD_mutex_lock_(&daemon->per_ip_connection_mutex); 198 MHD_mutex_lock_chk_(&daemon->per_ip_connection_mutex);
199} 199}
200 200
201 201
@@ -207,7 +207,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon)
207static void 207static void
208MHD_ip_count_unlock (struct MHD_Daemon *daemon) 208MHD_ip_count_unlock (struct MHD_Daemon *daemon)
209{ 209{
210 MHD_mutex_unlock_(&daemon->per_ip_connection_mutex); 210 MHD_mutex_unlock_chk_(&daemon->per_ip_connection_mutex);
211} 211}
212 212
213 213
@@ -962,7 +962,7 @@ finish_upgrade_close (struct MHD_UpgradeResponseHandle *urh)
962 NULL)) ) 962 NULL)) )
963 MHD_PANIC (_("Failed to remove FD from epoll set\n")); 963 MHD_PANIC (_("Failed to remove FD from epoll set\n"));
964#endif 964#endif
965 MHD_socket_close_ (urh->mhd.socket); 965 MHD_socket_close_chk_ (urh->mhd.socket);
966 } 966 }
967 MHD_resume_connection (connection); 967 MHD_resume_connection (connection);
968 MHD_connection_close_ (connection, 968 MHD_connection_close_ (connection,
@@ -1532,7 +1532,7 @@ exit:
1532 { 1532 {
1533 shutdown (con->socket_fd, 1533 shutdown (con->socket_fd,
1534 SHUT_WR); 1534 SHUT_WR);
1535 MHD_socket_close_ (con->socket_fd); 1535 MHD_socket_close_chk_ (con->socket_fd);
1536 con->socket_fd = MHD_INVALID_SOCKET; 1536 con->socket_fd = MHD_INVALID_SOCKET;
1537 } 1537 }
1538 return (MHD_THRD_RTRN_TYPE_) 0; 1538 return (MHD_THRD_RTRN_TYPE_) 0;
@@ -1771,7 +1771,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1771 external_add); 1771 external_add);
1772 } 1772 }
1773 /* all pools are at their connection limit, must refuse */ 1773 /* all pools are at their connection limit, must refuse */
1774 MHD_socket_close_ (client_socket); 1774 MHD_socket_close_chk_ (client_socket);
1775#if ENFILE 1775#if ENFILE
1776 errno = ENFILE; 1776 errno = ENFILE;
1777#endif 1777#endif
@@ -1788,7 +1788,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1788 (int) client_socket, 1788 (int) client_socket,
1789 (int) FD_SETSIZE); 1789 (int) FD_SETSIZE);
1790#endif 1790#endif
1791 MHD_socket_close_ (client_socket); 1791 MHD_socket_close_chk_ (client_socket);
1792#if EINVAL 1792#if EINVAL
1793 errno = EINVAL; 1793 errno = EINVAL;
1794#endif 1794#endif
@@ -1813,7 +1813,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1813 MHD_DLOG (daemon, 1813 MHD_DLOG (daemon,
1814 _("Server reached connection limit. Closing inbound connection.\n")); 1814 _("Server reached connection limit. Closing inbound connection.\n"));
1815#endif 1815#endif
1816 MHD_socket_close_ (client_socket); 1816 MHD_socket_close_chk_ (client_socket);
1817#if ENFILE 1817#if ENFILE
1818 errno = ENFILE; 1818 errno = ENFILE;
1819#endif 1819#endif
@@ -1832,7 +1832,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1832 _("Connection rejected by application. Closing connection.\n")); 1832 _("Connection rejected by application. Closing connection.\n"));
1833#endif 1833#endif
1834#endif 1834#endif
1835 MHD_socket_close_ (client_socket); 1835 MHD_socket_close_chk_ (client_socket);
1836 MHD_ip_limit_del (daemon, 1836 MHD_ip_limit_del (daemon,
1837 addr, 1837 addr,
1838 addrlen); 1838 addrlen);
@@ -1862,7 +1862,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1862 "Error allocating memory: %s\n", 1862 "Error allocating memory: %s\n",
1863 MHD_strerror_ (errno)); 1863 MHD_strerror_ (errno));
1864#endif 1864#endif
1865 MHD_socket_close_ (client_socket); 1865 MHD_socket_close_chk_ (client_socket);
1866 MHD_ip_limit_del (daemon, 1866 MHD_ip_limit_del (daemon,
1867 addr, 1867 addr,
1868 addrlen); 1868 addrlen);
@@ -1880,7 +1880,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1880 _("Error allocating memory: %s\n"), 1880 _("Error allocating memory: %s\n"),
1881 MHD_strerror_ (errno)); 1881 MHD_strerror_ (errno));
1882#endif 1882#endif
1883 MHD_socket_close_ (client_socket); 1883 MHD_socket_close_chk_ (client_socket);
1884 MHD_ip_limit_del (daemon, 1884 MHD_ip_limit_del (daemon,
1885 addr, 1885 addr,
1886 addrlen); 1886 addrlen);
@@ -1900,7 +1900,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1900 _("Error allocating memory: %s\n"), 1900 _("Error allocating memory: %s\n"),
1901 MHD_strerror_ (errno)); 1901 MHD_strerror_ (errno));
1902#endif 1902#endif
1903 MHD_socket_close_ (client_socket); 1903 MHD_socket_close_chk_ (client_socket);
1904 MHD_ip_limit_del (daemon, 1904 MHD_ip_limit_del (daemon,
1905 addr, 1905 addr,
1906 addrlen); 1906 addrlen);
@@ -1961,7 +1961,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1961 _("Failed to setup TLS credentials: unknown credential type %d\n"), 1961 _("Failed to setup TLS credentials: unknown credential type %d\n"),
1962 daemon->cred_type); 1962 daemon->cred_type);
1963#endif 1963#endif
1964 MHD_socket_close_ (client_socket); 1964 MHD_socket_close_chk_ (client_socket);
1965 MHD_ip_limit_del (daemon, 1965 MHD_ip_limit_del (daemon,
1966 addr, 1966 addr,
1967 addrlen); 1967 addrlen);
@@ -1988,7 +1988,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
1988 1988
1989 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 1989 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
1990 { 1990 {
1991 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 1991 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
1992 } 1992 }
1993 else 1993 else
1994 { 1994 {
@@ -2000,7 +2000,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
2000 daemon->connections_tail, 2000 daemon->connections_tail,
2001 connection); 2001 connection);
2002 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2002 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2003 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 2003 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2004 2004
2005 if (NULL != daemon->notify_connection) 2005 if (NULL != daemon->notify_connection)
2006 daemon->notify_connection (daemon->notify_connection_cls, 2006 daemon->notify_connection (daemon->notify_connection_cls,
@@ -2080,13 +2080,13 @@ internal_add_connection (struct MHD_Daemon *daemon,
2080 connection, 2080 connection,
2081 &connection->socket_context, 2081 &connection->socket_context,
2082 MHD_CONNECTION_NOTIFY_CLOSED); 2082 MHD_CONNECTION_NOTIFY_CLOSED);
2083 MHD_socket_close_ (client_socket); 2083 MHD_socket_close_chk_ (client_socket);
2084 MHD_ip_limit_del (daemon, 2084 MHD_ip_limit_del (daemon,
2085 addr, 2085 addr,
2086 addrlen); 2086 addrlen);
2087 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2087 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2088 { 2088 {
2089 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 2089 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2090 } 2090 }
2091 else 2091 else
2092 { 2092 {
@@ -2098,7 +2098,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
2098 daemon->connections_tail, 2098 daemon->connections_tail,
2099 connection); 2099 connection);
2100 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2100 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2101 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 2101 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2102 MHD_pool_destroy (connection->pool); 2102 MHD_pool_destroy (connection->pool);
2103 free (connection->addr); 2103 free (connection->addr);
2104 free (connection); 2104 free (connection);
@@ -2144,7 +2144,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
2144 MHD_PANIC (_("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n")); 2144 MHD_PANIC (_("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n"));
2145 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2145 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2146 { 2146 {
2147 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 2147 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2148 } 2148 }
2149 else 2149 else
2150 { 2150 {
@@ -2187,7 +2187,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
2187#endif 2187#endif
2188 connection->suspended = MHD_YES; 2188 connection->suspended = MHD_YES;
2189 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2189 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2190 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 2190 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2191} 2191}
2192 2192
2193 2193
@@ -2208,7 +2208,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
2208 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME)) 2208 if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
2209 MHD_PANIC (_("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n")); 2209 MHD_PANIC (_("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n"));
2210 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2210 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2211 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 2211 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2212 connection->resuming = MHD_YES; 2212 connection->resuming = MHD_YES;
2213 daemon->resuming = MHD_YES; 2213 daemon->resuming = MHD_YES;
2214 if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) && 2214 if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
@@ -2220,7 +2220,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
2220#endif 2220#endif
2221 } 2221 }
2222 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2222 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2223 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 2223 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2224} 2224}
2225 2225
2226 2226
@@ -2240,7 +2240,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
2240 2240
2241 ret = MHD_NO; 2241 ret = MHD_NO;
2242 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2242 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2243 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 2243 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2244 if (MHD_NO != daemon->resuming) 2244 if (MHD_NO != daemon->resuming)
2245 next = daemon->suspended_connections_head; 2245 next = daemon->suspended_connections_head;
2246 2246
@@ -2295,7 +2295,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
2295 pos->resuming = MHD_NO; 2295 pos->resuming = MHD_NO;
2296 } 2296 }
2297 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2297 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2298 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 2298 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2299 return ret; 2299 return ret;
2300} 2300}
2301 2301
@@ -2424,7 +2424,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
2424#endif 2424#endif
2425 if (MHD_INVALID_SOCKET != s) 2425 if (MHD_INVALID_SOCKET != s)
2426 { 2426 {
2427 MHD_socket_close_ (s); 2427 MHD_socket_close_chk_ (s);
2428 } 2428 }
2429 if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) ) 2429 if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) )
2430 { 2430 {
@@ -2499,7 +2499,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2499 struct MHD_Connection *pos; 2499 struct MHD_Connection *pos;
2500 2500
2501 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2501 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2502 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 2502 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
2503 while (NULL != (pos = daemon->cleanup_head)) 2503 while (NULL != (pos = daemon->cleanup_head))
2504 { 2504 {
2505 DLL_remove (daemon->cleanup_head, 2505 DLL_remove (daemon->cleanup_head,
@@ -2565,14 +2565,14 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
2565 } 2565 }
2566 if (MHD_INVALID_SOCKET != pos->socket_fd) 2566 if (MHD_INVALID_SOCKET != pos->socket_fd)
2567 { 2567 {
2568 MHD_socket_close_ (pos->socket_fd); 2568 MHD_socket_close_chk_ (pos->socket_fd);
2569 } 2569 }
2570 if (NULL != pos->addr) 2570 if (NULL != pos->addr)
2571 free (pos->addr); 2571 free (pos->addr);
2572 free (pos); 2572 free (pos);
2573 } 2573 }
2574 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 2574 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
2575 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 2575 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
2576} 2576}
2577 2577
2578 2578
@@ -4791,7 +4791,7 @@ MHD_start_daemon_va (unsigned int flags,
4791 (unsigned int) port, 4791 (unsigned int) port,
4792 MHD_socket_last_strerr_ ()); 4792 MHD_socket_last_strerr_ ());
4793#endif 4793#endif
4794 MHD_socket_close_ (socket_fd); 4794 MHD_socket_close_chk_ (socket_fd);
4795 goto free_and_fail; 4795 goto free_and_fail;
4796 } 4796 }
4797#ifdef TCP_FASTOPEN 4797#ifdef TCP_FASTOPEN
@@ -4821,7 +4821,7 @@ MHD_start_daemon_va (unsigned int flags,
4821 _("Failed to listen for connections: %s\n"), 4821 _("Failed to listen for connections: %s\n"),
4822 MHD_socket_last_strerr_ ()); 4822 MHD_socket_last_strerr_ ());
4823#endif 4823#endif
4824 MHD_socket_close_ (socket_fd); 4824 MHD_socket_close_chk_ (socket_fd);
4825 goto free_and_fail; 4825 goto free_and_fail;
4826 } 4826 }
4827 } 4827 }
@@ -4843,7 +4843,7 @@ MHD_start_daemon_va (unsigned int flags,
4843 /* Accept must be non-blocking. Multiple children may wake up 4843 /* Accept must be non-blocking. Multiple children may wake up
4844 * to handle a new connection, but only one will win the race. 4844 * to handle a new connection, but only one will win the race.
4845 * The others must immediately return. */ 4845 * The others must immediately return. */
4846 MHD_socket_close_ (socket_fd); 4846 MHD_socket_close_chk_ (socket_fd);
4847 goto free_and_fail; 4847 goto free_and_fail;
4848 } 4848 }
4849 } 4849 }
@@ -4857,7 +4857,7 @@ MHD_start_daemon_va (unsigned int flags,
4857 socket_fd, 4857 socket_fd,
4858 FD_SETSIZE); 4858 FD_SETSIZE);
4859#endif 4859#endif
4860 MHD_socket_close_ (socket_fd); 4860 MHD_socket_close_chk_ (socket_fd);
4861 goto free_and_fail; 4861 goto free_and_fail;
4862 } 4862 }
4863 4863
@@ -4895,7 +4895,7 @@ MHD_start_daemon_va (unsigned int flags,
4895 _("MHD failed to initialize IP connection limit mutex\n")); 4895 _("MHD failed to initialize IP connection limit mutex\n"));
4896#endif 4896#endif
4897 if (MHD_INVALID_SOCKET != socket_fd) 4897 if (MHD_INVALID_SOCKET != socket_fd)
4898 MHD_socket_close_ (socket_fd); 4898 MHD_socket_close_chk_ (socket_fd);
4899 goto free_and_fail; 4899 goto free_and_fail;
4900 } 4900 }
4901 if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex)) 4901 if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
@@ -4904,9 +4904,9 @@ MHD_start_daemon_va (unsigned int flags,
4904 MHD_DLOG (daemon, 4904 MHD_DLOG (daemon,
4905 _("MHD failed to initialize IP connection limit mutex\n")); 4905 _("MHD failed to initialize IP connection limit mutex\n"));
4906#endif 4906#endif
4907 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 4907 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
4908 if (MHD_INVALID_SOCKET != socket_fd) 4908 if (MHD_INVALID_SOCKET != socket_fd)
4909 MHD_socket_close_ (socket_fd); 4909 MHD_socket_close_chk_ (socket_fd);
4910 goto free_and_fail; 4910 goto free_and_fail;
4911 } 4911 }
4912 4912
@@ -4920,9 +4920,9 @@ MHD_start_daemon_va (unsigned int flags,
4920 _("Failed to initialize TLS support\n")); 4920 _("Failed to initialize TLS support\n"));
4921#endif 4921#endif
4922 if (MHD_INVALID_SOCKET != socket_fd) 4922 if (MHD_INVALID_SOCKET != socket_fd)
4923 MHD_socket_close_ (socket_fd); 4923 MHD_socket_close_chk_ (socket_fd);
4924 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 4924 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
4925 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); 4925 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
4926 goto free_and_fail; 4926 goto free_and_fail;
4927 } 4927 }
4928#endif 4928#endif
@@ -4942,10 +4942,10 @@ MHD_start_daemon_va (unsigned int flags,
4942 _("Failed to create listen thread: %s\n"), 4942 _("Failed to create listen thread: %s\n"),
4943 MHD_strerror_ (errno)); 4943 MHD_strerror_ (errno));
4944#endif 4944#endif
4945 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 4945 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
4946 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); 4946 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
4947 if (MHD_INVALID_SOCKET != socket_fd) 4947 if (MHD_INVALID_SOCKET != socket_fd)
4948 MHD_socket_close_ (socket_fd); 4948 MHD_socket_close_chk_ (socket_fd);
4949 goto free_and_fail; 4949 goto free_and_fail;
4950 } 4950 }
4951 if ( (daemon->worker_pool_size > 0) && 4951 if ( (daemon->worker_pool_size > 0) &&
@@ -5050,7 +5050,7 @@ MHD_start_daemon_va (unsigned int flags,
5050#endif 5050#endif
5051 /* Free memory for this worker; cleanup below handles 5051 /* Free memory for this worker; cleanup below handles
5052 * all previously-created workers. */ 5052 * all previously-created workers. */
5053 MHD_mutex_destroy_ (&d->cleanup_connection_mutex); 5053 MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
5054 goto thread_failed; 5054 goto thread_failed;
5055 } 5055 }
5056 } 5056 }
@@ -5071,9 +5071,9 @@ thread_failed:
5071 if (0 == i) 5071 if (0 == i)
5072 { 5072 {
5073 if (MHD_INVALID_SOCKET != socket_fd) 5073 if (MHD_INVALID_SOCKET != socket_fd)
5074 MHD_socket_close_ (socket_fd); 5074 MHD_socket_close_chk_ (socket_fd);
5075 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 5075 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
5076 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); 5076 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
5077 if (NULL != daemon->worker_pool) 5077 if (NULL != daemon->worker_pool)
5078 free (daemon->worker_pool); 5078 free (daemon->worker_pool);
5079 goto free_and_fail; 5079 goto free_and_fail;
@@ -5111,7 +5111,7 @@ thread_failed:
5111#endif 5111#endif
5112#ifdef DAUTH_SUPPORT 5112#ifdef DAUTH_SUPPORT
5113 free (daemon->nnc); 5113 free (daemon->nnc);
5114 MHD_mutex_destroy_ (&daemon->nnc_lock); 5114 MHD_mutex_destroy_chk_ (&daemon->nnc_lock);
5115#endif 5115#endif
5116#if HTTPS_SUPPORT 5116#if HTTPS_SUPPORT
5117 if (0 != (flags & MHD_USE_SSL)) 5117 if (0 != (flags & MHD_USE_SSL))
@@ -5177,7 +5177,7 @@ close_all_connections (struct MHD_Daemon *daemon)
5177 /* first, make sure all threads are aware of shutdown; need to 5177 /* first, make sure all threads are aware of shutdown; need to
5178 traverse DLLs in peace... */ 5178 traverse DLLs in peace... */
5179 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 5179 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
5180 MHD_mutex_lock_ (&daemon->cleanup_connection_mutex); 5180 MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
5181 if (NULL != daemon->suspended_connections_head) 5181 if (NULL != daemon->suspended_connections_head)
5182 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n")); 5182 MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n"));
5183 for (pos = daemon->connections_head; NULL != pos; pos = pos->next) 5183 for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
@@ -5191,7 +5191,7 @@ close_all_connections (struct MHD_Daemon *daemon)
5191#endif 5191#endif
5192 } 5192 }
5193 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 5193 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
5194 MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex); 5194 MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
5195 5195
5196 /* now, collect per-connection threads */ 5196 /* now, collect per-connection threads */
5197 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) 5197 if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
@@ -5333,13 +5333,13 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5333 if (!MHD_join_thread_ (daemon->worker_pool[i].pid)) 5333 if (!MHD_join_thread_ (daemon->worker_pool[i].pid))
5334 MHD_PANIC (_("Failed to join a thread\n")); 5334 MHD_PANIC (_("Failed to join a thread\n"));
5335 close_all_connections (&daemon->worker_pool[i]); 5335 close_all_connections (&daemon->worker_pool[i]);
5336 MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex); 5336 MHD_mutex_destroy_chk_ (&daemon->worker_pool[i].cleanup_connection_mutex);
5337#ifdef EPOLL_SUPPORT 5337#ifdef EPOLL_SUPPORT
5338 if (-1 != daemon->worker_pool[i].epoll_fd) 5338 if (-1 != daemon->worker_pool[i].epoll_fd)
5339 MHD_socket_close_ (daemon->worker_pool[i].epoll_fd); 5339 MHD_socket_close_chk_ (daemon->worker_pool[i].epoll_fd);
5340#if HTTPS_SUPPORT 5340#if HTTPS_SUPPORT
5341 if (-1 != daemon->worker_pool[i].epoll_upgrade_fd) 5341 if (-1 != daemon->worker_pool[i].epoll_upgrade_fd)
5342 MHD_socket_close_ (daemon->worker_pool[i].epoll_upgrade_fd); 5342 MHD_socket_close_chk_ (daemon->worker_pool[i].epoll_upgrade_fd);
5343#endif 5343#endif
5344#endif 5344#endif
5345 /* Individual pipes are always used */ 5345 /* Individual pipes are always used */
@@ -5368,7 +5368,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5368 } 5368 }
5369 close_all_connections (daemon); 5369 close_all_connections (daemon);
5370 if (MHD_INVALID_SOCKET != fd) 5370 if (MHD_INVALID_SOCKET != fd)
5371 MHD_socket_close_ (fd); 5371 MHD_socket_close_chk_ (fd);
5372 5372
5373 /* TLS clean up */ 5373 /* TLS clean up */
5374#if HTTPS_SUPPORT 5374#if HTTPS_SUPPORT
@@ -5387,20 +5387,20 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
5387#ifdef EPOLL_SUPPORT 5387#ifdef EPOLL_SUPPORT
5388 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 5388 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
5389 (-1 != daemon->epoll_fd) ) 5389 (-1 != daemon->epoll_fd) )
5390 MHD_socket_close_ (daemon->epoll_fd); 5390 MHD_socket_close_chk_ (daemon->epoll_fd);
5391#if HTTPS_SUPPORT 5391#if HTTPS_SUPPORT
5392 if ( (0 != (daemon->options & MHD_USE_EPOLL)) && 5392 if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
5393 (-1 != daemon->epoll_upgrade_fd) ) 5393 (-1 != daemon->epoll_upgrade_fd) )
5394 MHD_socket_close_ (daemon->epoll_upgrade_fd); 5394 MHD_socket_close_chk_ (daemon->epoll_upgrade_fd);
5395#endif 5395#endif
5396#endif 5396#endif
5397 5397
5398#ifdef DAUTH_SUPPORT 5398#ifdef DAUTH_SUPPORT
5399 free (daemon->nnc); 5399 free (daemon->nnc);
5400 MHD_mutex_destroy_ (&daemon->nnc_lock); 5400 MHD_mutex_destroy_chk_ (&daemon->nnc_lock);
5401#endif 5401#endif
5402 MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex); 5402 MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
5403 MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex); 5403 MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
5404 5404
5405 if (! MHD_INVALID_PIPE_(daemon->wpipe)) 5405 if (! MHD_INVALID_PIPE_(daemon->wpipe))
5406 MHD_pipe_close_ (daemon->wpipe); 5406 MHD_pipe_close_ (daemon->wpipe);
@@ -5654,7 +5654,7 @@ gcry_w32_mutex_init (void **ppmtx)
5654static int 5654static int
5655gcry_w32_mutex_destroy (void **ppmtx) 5655gcry_w32_mutex_destroy (void **ppmtx)
5656{ 5656{
5657 int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1; 5657 int res = (MHD_mutex_destroy_chk_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
5658 free (*ppmtx); 5658 free (*ppmtx);
5659 return res; 5659 return res;
5660} 5660}
@@ -5663,7 +5663,7 @@ gcry_w32_mutex_destroy (void **ppmtx)
5663static int 5663static int
5664gcry_w32_mutex_lock (void **ppmtx) 5664gcry_w32_mutex_lock (void **ppmtx)
5665{ 5665{
5666 MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx); 5666 MHD_mutex_lock_chk_ ((MHD_mutex_*)*ppmtx);
5667 return 0; 5667 return 0;
5668} 5668}
5669 5669
@@ -5671,7 +5671,7 @@ gcry_w32_mutex_lock (void **ppmtx)
5671static int 5671static int
5672gcry_w32_mutex_unlock (void **ppmtx) 5672gcry_w32_mutex_unlock (void **ppmtx)
5673{ 5673{
5674 MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx); 5674 MHD_mutex_unlock_chk_ ((MHD_mutex_*)*ppmtx);
5675 return 0; 5675 return 0;
5676} 5676}
5677 5677
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 5060d253..638c0825 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 MHD_mutex_lock_ (&daemon->nnc_lock); 411 MHD_mutex_lock_chk_ (&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 MHD_mutex_unlock_ (&daemon->nnc_lock); 419 MHD_mutex_unlock_chk_ (&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 MHD_mutex_unlock_ (&daemon->nnc_lock); 431 MHD_mutex_unlock_chk_ (&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 MHD_mutex_unlock_ (&daemon->nnc_lock); 440 MHD_mutex_unlock_chk_ (&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 MHD_mutex_unlock_ (&daemon->nnc_lock); 453 MHD_mutex_unlock_chk_ (&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 a42564de..a72fcf65 100644
--- a/src/microhttpd/internal.h
+++ b/src/microhttpd/internal.h
@@ -35,6 +35,29 @@
35#include <gnutls/abstract.h> 35#include <gnutls/abstract.h>
36#endif 36#endif
37#endif 37#endif
38#include "mhd_options.h"
39
40
41#ifdef MHD_PANIC
42/* Override any defined MHD_PANIC macro with proper one */
43#undef MHD_PANIC
44#endif /* MHD_PANIC */
45
46#ifdef HAVE_MESSAGES
47/**
48 * Trigger 'panic' action based on fatal errors.
49 *
50 * @param msg error message (const char *)
51 */
52#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); BUILTIN_NOT_REACHED; } while (0)
53#else
54/**
55 * Trigger 'panic' action based on fatal errors.
56 *
57 * @param msg error message (const char *)
58 */
59#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); BUILTIN_NOT_REACHED; } while (0)
60#endif
38 61
39#include "mhd_threads.h" 62#include "mhd_threads.h"
40#include "mhd_locks.h" 63#include "mhd_locks.h"
@@ -82,23 +105,6 @@ extern void *mhd_panic_cls;
82#endif 105#endif
83 106
84 107
85#ifdef HAVE_MESSAGES
86/**
87 * Trigger 'panic' action based on fatal errors.
88 *
89 * @param msg error message (const char *)
90 */
91#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); BUILTIN_NOT_REACHED; } while (0)
92#else
93/**
94 * Trigger 'panic' action based on fatal errors.
95 *
96 * @param msg error message (const char *)
97 */
98#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); BUILTIN_NOT_REACHED; } while (0)
99#endif
100
101
102/** 108/**
103 * State of the socket with respect to epoll (bitmask). 109 * State of the socket with respect to epoll (bitmask).
104 */ 110 */
diff --git a/src/microhttpd/mhd_itc.h b/src/microhttpd/mhd_itc.h
index 6d295619..163a4d5f 100644
--- a/src/microhttpd/mhd_itc.h
+++ b/src/microhttpd/mhd_itc.h
@@ -245,8 +245,8 @@ struct MHD_Pipe
245 * Close emulated pipe FDs 245 * Close emulated pipe FDs
246 */ 246 */
247#define MHD_pipe_close_(pip) do { \ 247#define MHD_pipe_close_(pip) do { \
248 MHD_socket_close_ ((pip).fd[0]); \ 248 MHD_socket_close_chk_ ((pip).fd[0]); \
249 MHD_socket_close_ ((pip).fd[1]); \ 249 MHD_socket_close_chk_ ((pip).fd[1]); \
250} while (0) 250} while (0)
251 251
252/** 252/**
diff --git a/src/microhttpd/mhd_locks.h b/src/microhttpd/mhd_locks.h
index a5a8fd67..a3fad893 100644
--- a/src/microhttpd/mhd_locks.h
+++ b/src/microhttpd/mhd_locks.h
@@ -54,6 +54,15 @@
54# error No base mutex API is available. 54# error No base mutex API is available.
55#endif 55#endif
56 56
57#ifndef MHD_PANIC
58# include <stdio.h>
59# include <stdlib.h>
60/* Simple implementation of MHD_PANIC, to be used outside lib */
61# define MHD_PANIC(msg) do { fprintf (stderr, \
62 "Abnormal termination at %d line in file %s: %s\n", \
63 (int)__LINE__, __FILE__, msg); abort();} while(0)
64#endif /* ! MHD_PANIC */
65
57#if defined(MHD_PTHREAD_MUTEX_) 66#if defined(MHD_PTHREAD_MUTEX_)
58 typedef pthread_mutex_t MHD_mutex_; 67 typedef pthread_mutex_t MHD_mutex_;
59#elif defined(MHD_W32_MUTEX_) 68#elif defined(MHD_W32_MUTEX_)
@@ -80,60 +89,86 @@
80/** 89/**
81 * Destroy previously initialised mutex. 90 * Destroy previously initialised mutex.
82 * @param pmutex pointer to mutex 91 * @param pmutex pointer to mutex
92 * @return nonzero on success, zero otherwise
83 */ 93 */
84#define MHD_mutex_destroy_(pmutex) do { \ 94#define MHD_mutex_destroy_(pmutex) (!(pthread_mutex_destroy((pmutex))))
85 errno = 0; \
86 if (0 != pthread_mutex_destroy((pmutex))) \
87 MHD_PANIC (_("Failed to destroy mutex\n")); \
88 } while (0)
89#elif defined(MHD_W32_MUTEX_) 95#elif defined(MHD_W32_MUTEX_)
90/** 96/**
91 * Destroy previously initialised mutex. 97 * Destroy previously initialised mutex.
92 * @param pmutex pointer to mutex 98 * @param pmutex pointer to mutex
99 * @return Always nonzero
93 */ 100 */
94#define MHD_mutex_destroy_(pmutex) DeleteCriticalSection((pmutex)) 101#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection((pmutex)), !0)
95#endif 102#endif
96 103
104/**
105 * Destroy previously initialised mutex and abort execution
106 * if error is detected.
107 * @param pmutex pointer to mutex
108 */
109#define MHD_mutex_destroy_chk_(pmutex) do { \
110 if (!MHD_mutex_destroy_(pmutex)) \
111 MHD_PANIC(_("Failed to destroy mutex.\n")); \
112 } while(0)
113
114
97#if defined(MHD_PTHREAD_MUTEX_) 115#if defined(MHD_PTHREAD_MUTEX_)
98/** 116/**
99 * Acquire lock on previously initialised mutex. 117 * Acquire lock on previously initialised mutex.
100 * If mutex was already locked by other thread, function 118 * If mutex was already locked by other thread, function
101 * blocks until mutex becomes available. 119 * blocks until mutex becomes available.
102 * @param pmutex pointer to mutex 120 * @param pmutex pointer to mutex
121 * @return nonzero on success, zero otherwise
103 */ 122 */
104#define MHD_mutex_lock_(pmutex) do { \ 123#define MHD_mutex_lock_(pmutex) (!(pthread_mutex_lock((pmutex))))
105 if (0 != pthread_mutex_lock((pmutex))) \
106 MHD_PANIC (_("Failed to lock mutex\n")); \
107 } while (0)
108#elif defined(MHD_W32_MUTEX_) 124#elif defined(MHD_W32_MUTEX_)
109/** 125/**
110 * Acquire lock on previously initialised mutex. 126 * Acquire lock on previously initialised mutex.
111 * If mutex was already locked by other thread, function 127 * If mutex was already locked by other thread, function
112 * blocks until mutex becomes available. 128 * blocks until mutex becomes available.
113 * @param pmutex pointer to mutex 129 * @param pmutex pointer to mutex
130 * @return Always nonzero
114 */ 131 */
115#define MHD_mutex_lock_(pmutex) EnterCriticalSection((pmutex)) 132#define MHD_mutex_lock_(pmutex) (EnterCriticalSection((pmutex)), !0)
116#endif 133#endif
117 134
135/**
136 * Acquire lock on previously initialised mutex.
137 * If mutex was already locked by other thread, function
138 * blocks until mutex becomes available.
139 * If error is detected, execution will be aborted.
140 * @param pmutex pointer to mutex
141 */
142#define MHD_mutex_lock_chk_(pmutex) do { \
143 if (!MHD_mutex_lock_(pmutex)) \
144 MHD_PANIC(_("Failed to lock mutex.\n")); \
145 } while(0)
146
118#if defined(MHD_PTHREAD_MUTEX_) 147#if defined(MHD_PTHREAD_MUTEX_)
119/** 148/**
120 * Unlock previously initialised and locked mutex. 149 * Unlock previously initialised and locked mutex.
121 * @param pmutex pointer to mutex 150 * @param pmutex pointer to mutex
122 * @return nonzero on success, zero otherwise 151 * @return nonzero on success, zero otherwise
123 */ 152 */
124#define MHD_mutex_unlock_(pmutex) do { \ 153#define MHD_mutex_unlock_(pmutex) (!(pthread_mutex_unlock((pmutex))))
125 if (0 != pthread_mutex_unlock((pmutex))) \
126 MHD_PANIC (_("Failed to unlock mutex\n")); \
127 } while (0)
128#elif defined(MHD_W32_MUTEX_) 154#elif defined(MHD_W32_MUTEX_)
129/** 155/**
130 * Unlock previously initialised and locked mutex. 156 * Unlock previously initialised and locked mutex.
131 * @param pmutex pointer to mutex 157 * @param pmutex pointer to mutex
132 * @return Always nonzero 158 * @return Always nonzero
133 */ 159 */
134#define MHD_mutex_unlock_(pmutex) LeaveCriticalSection((pmutex)) 160#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection((pmutex)), !0)
135#endif 161#endif
136 162
163/**
164 * Unlock previously initialised and locked mutex.
165 * If error is detected, execution will be aborted.
166 * @param pmutex pointer to mutex
167 */
168#define MHD_mutex_unlock_chk_(pmutex) do { \
169 if (!MHD_mutex_unlock_(pmutex)) \
170 MHD_PANIC(_("Failed to unlock mutex.\n")); \
171 } while(0)
137 172
138/** 173/**
139 * A semaphore. 174 * A semaphore.
diff --git a/src/microhttpd/mhd_sockets.h b/src/microhttpd/mhd_sockets.h
index 1bcd0a04..236e93f2 100644
--- a/src/microhttpd/mhd_sockets.h
+++ b/src/microhttpd/mhd_sockets.h
@@ -117,6 +117,15 @@
117# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value() 117# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value()
118#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */ 118#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
119 119
120#ifndef MHD_PANIC
121# include <stdio.h>
122# include <stdlib.h>
123/* Simple implementation of MHD_PANIC, to be used outside lib */
124# define MHD_PANIC(msg) do { fprintf (stderr, \
125 "Abnormal termination at %d line in file %s: %s\n", \
126 (int)__LINE__, __FILE__, msg); abort();} while(0)
127#endif /* ! MHD_PANIC */
128
120#ifndef MHD_SOCKET_DEFINED 129#ifndef MHD_SOCKET_DEFINED
121/** 130/**
122 * MHD_socket is type for socket FDs 131 * MHD_socket is type for socket FDs
@@ -195,21 +204,27 @@
195 * errno is set to EINTR. Do not use HP-UNIX. 204 * errno is set to EINTR. Do not use HP-UNIX.
196 * 205 *
197 * @param fd descriptor to close 206 * @param fd descriptor to close
207 * @return boolean true on success (error codes like EINTR and EIO are
208 * counted as success, only EBADF counts as an error!),
209 * boolean false otherwise.
198 */ 210 */
199#if !defined(MHD_WINSOCK_SOCKETS) 211#if !defined(MHD_WINSOCK_SOCKETS)
200# define MHD_socket_close_(fd) do { \ 212# define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno))
201 if ( (0 != close((fd))) && \
202 (EBADF == errno) ) \
203 MHD_PANIC (_("close failed\n")); \
204 } while (0)
205#else 213#else
206# define MHD_socket_close_(fd) do { \ 214# define MHD_socket_close_(fd) (0 == closesocket((fd)))
207 if (0 != closesocket((fd)) ) \
208 MHD_PANIC (_("close failed\n")); \
209 } while (0)
210#endif 215#endif
211 216
212/** 217/**
218 * MHD_socket_close_chk_(fd) close socket and abort execution
219 * if error is detected.
220 * @param fd socket to close
221 */
222#define MHD_socket_close_chk_(fd) do { \
223 if (!MHD_socket_close_(fd)) \
224 MHD_PANIC(_("Close socket failed.\n")); \
225 } while(0)
226
227/**
213 * Check whether FD can be added to fd_set with specified FD_SETSIZE. 228 * Check whether FD can be added to fd_set with specified FD_SETSIZE.
214 * @param fd the fd to check 229 * @param fd the fd to check
215 * @param pset the pointer to fd_set to check or NULL to check 230 * @param pset the pointer to fd_set to check or NULL to check
diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c
index 3e4040c4..b06e268d 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 MHD_mutex_destroy_ (&response->mutex); 571 MHD_mutex_destroy_chk_ (&response->mutex);
572 free (response); 572 free (response);
573 return NULL; 573 return NULL;
574 } 574 }
@@ -655,7 +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 MHD_socket_close_ (urh->app.socket); 658 MHD_socket_close_chk_ (urh->app.socket);
659 urh->app.socket = MHD_INVALID_SOCKET; 659 urh->app.socket = MHD_INVALID_SOCKET;
660 } 660 }
661 return MHD_YES; 661 return MHD_YES;
@@ -742,8 +742,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
742 (int) sv[1], 742 (int) sv[1],
743 (int) FD_SETSIZE); 743 (int) FD_SETSIZE);
744#endif 744#endif
745 MHD_socket_close_ (sv[0]); 745 MHD_socket_close_chk_ (sv[0]);
746 MHD_socket_close_ (sv[1]); 746 MHD_socket_close_chk_ (sv[1]);
747 free (urh); 747 free (urh);
748 return MHD_NO; 748 return MHD_NO;
749 } 749 }
@@ -814,8 +814,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
814 _("Call to epoll_ctl failed: %s\n"), 814 _("Call to epoll_ctl failed: %s\n"),
815 MHD_socket_last_strerr_ ()); 815 MHD_socket_last_strerr_ ());
816#endif 816#endif
817 MHD_socket_close_ (sv[0]); 817 MHD_socket_close_chk_ (sv[0]);
818 MHD_socket_close_ (sv[1]); 818 MHD_socket_close_chk_ (sv[1]);
819 free (urh); 819 free (urh);
820 return MHD_NO; 820 return MHD_NO;
821 } 821 }
@@ -840,8 +840,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
840 _("Call to epoll_ctl failed: %s\n"), 840 _("Call to epoll_ctl failed: %s\n"),
841 MHD_socket_last_strerr_ ()); 841 MHD_socket_last_strerr_ ());
842#endif 842#endif
843 MHD_socket_close_ (sv[0]); 843 MHD_socket_close_chk_ (sv[0]);
844 MHD_socket_close_ (sv[1]); 844 MHD_socket_close_chk_ (sv[1]);
845 free (urh); 845 free (urh);
846 return MHD_NO; 846 return MHD_NO;
847 } 847 }
@@ -986,14 +986,14 @@ MHD_destroy_response (struct MHD_Response *response)
986 986
987 if (NULL == response) 987 if (NULL == response)
988 return; 988 return;
989 MHD_mutex_lock_ (&response->mutex); 989 MHD_mutex_lock_chk_ (&response->mutex);
990 if (0 != --(response->reference_count)) 990 if (0 != --(response->reference_count))
991 { 991 {
992 MHD_mutex_unlock_ (&response->mutex); 992 MHD_mutex_unlock_chk_ (&response->mutex);
993 return; 993 return;
994 } 994 }
995 MHD_mutex_unlock_ (&response->mutex); 995 MHD_mutex_unlock_chk_ (&response->mutex);
996 MHD_mutex_destroy_ (&response->mutex); 996 MHD_mutex_destroy_chk_ (&response->mutex);
997 if (NULL != response->crfc) 997 if (NULL != response->crfc)
998 response->crfc (response->crc_cls); 998 response->crfc (response->crc_cls);
999 while (NULL != response->first_header) 999 while (NULL != response->first_header)
@@ -1016,9 +1016,9 @@ MHD_destroy_response (struct MHD_Response *response)
1016void 1016void
1017MHD_increment_response_rc (struct MHD_Response *response) 1017MHD_increment_response_rc (struct MHD_Response *response)
1018{ 1018{
1019 MHD_mutex_lock_ (&response->mutex); 1019 MHD_mutex_lock_chk_ (&response->mutex);
1020 (response->reference_count)++; 1020 (response->reference_count)++;
1021 MHD_mutex_unlock_ (&response->mutex); 1021 MHD_mutex_unlock_chk_ (&response->mutex);
1022} 1022}
1023 1023
1024 1024
diff --git a/src/microhttpd/test_shutdown_select.c b/src/microhttpd/test_shutdown_select.c
index 63c0c53c..96e045bf 100644
--- a/src/microhttpd/test_shutdown_select.c
+++ b/src/microhttpd/test_shutdown_select.c
@@ -90,14 +90,6 @@
90static _MHD_bool check_err; 90static _MHD_bool check_err;
91 91
92 92
93void
94MHD_PANIC (char *msg)
95{
96 fprintf (stderr, "%s", msg);
97 abort ();
98}
99
100
101static _MHD_bool 93static _MHD_bool
102has_in_name(const char *prog_name, const char *marker) 94has_in_name(const char *prog_name, const char *marker)
103{ 95{
@@ -189,7 +181,7 @@ start_socket_listen(int domain)
189 { 181 {
190 fprintf (stderr, "Failed to bind socket: %u\n", 182 fprintf (stderr, "Failed to bind socket: %u\n",
191 (unsigned)sock_errno); 183 (unsigned)sock_errno);
192 MHD_socket_close_ (fd); 184 MHD_socket_close_chk_ (fd);
193 return MHD_INVALID_SOCKET; 185 return MHD_INVALID_SOCKET;
194 } 186 }
195 187
@@ -198,7 +190,7 @@ start_socket_listen(int domain)
198 { 190 {
199 fprintf (stderr, "Failed to make socket non-blocking: %u\n", 191 fprintf (stderr, "Failed to make socket non-blocking: %u\n",
200 (unsigned)sock_errno); 192 (unsigned)sock_errno);
201 MHD_socket_close_ (fd); 193 MHD_socket_close_chk_ (fd);
202 return MHD_INVALID_SOCKET; 194 return MHD_INVALID_SOCKET;
203 } 195 }
204#else /* MHD_POSIX_SOCKETS */ 196#else /* MHD_POSIX_SOCKETS */
@@ -209,7 +201,7 @@ start_socket_listen(int domain)
209 { 201 {
210 fprintf (stderr, "Failed to make socket non-blocking: %s\n", 202 fprintf (stderr, "Failed to make socket non-blocking: %s\n",
211 MHD_socket_last_strerr_ ()); 203 MHD_socket_last_strerr_ ());
212 MHD_socket_close_ (fd); 204 MHD_socket_close_chk_ (fd);
213 return MHD_INVALID_SOCKET; 205 return MHD_INVALID_SOCKET;
214 } 206 }
215#endif /* MHD_POSIX_SOCKETS */ 207#endif /* MHD_POSIX_SOCKETS */
@@ -218,7 +210,7 @@ start_socket_listen(int domain)
218 { 210 {
219 fprintf (stderr, "Failed to listen on socket: %u\n", 211 fprintf (stderr, "Failed to listen on socket: %u\n",
220 (unsigned)sock_errno); 212 (unsigned)sock_errno);
221 MHD_socket_close_ (fd); 213 MHD_socket_close_chk_ (fd);
222 return MHD_INVALID_SOCKET; 214 return MHD_INVALID_SOCKET;
223 } 215 }
224 216
@@ -334,7 +326,7 @@ main (int argc, char *const *argv)
334#if defined(MHD_USE_POSIX_THREADS) 326#if defined(MHD_USE_POSIX_THREADS)
335 if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket)) 327 if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket))
336 { 328 {
337 MHD_socket_close_ (listen_socket); 329 MHD_socket_close_chk_ (listen_socket);
338 fprintf (stderr, "Can't start thread\n"); 330 fprintf (stderr, "Can't start thread\n");
339 return 99; 331 return 99;
340 } 332 }
@@ -342,7 +334,7 @@ main (int argc, char *const *argv)
342 sel_thrd = (HANDLE)_beginthreadex (NULL, 0, test_func, &listen_socket, 0, NULL); 334 sel_thrd = (HANDLE)_beginthreadex (NULL, 0, test_func, &listen_socket, 0, NULL);
343 if (0 == (sel_thrd)) 335 if (0 == (sel_thrd))
344 { 336 {
345 MHD_socket_close_ (listen_socket); 337 MHD_socket_close_chk_ (listen_socket);
346 fprintf (stderr, "Can't start select() thread\n"); 338 fprintf (stderr, "Can't start select() thread\n");
347 return 99; 339 return 99;
348 } 340 }
@@ -359,23 +351,23 @@ main (int argc, char *const *argv)
359 /* fprintf (stdout, "Waiting for thread to finish...\n"); */ 351 /* fprintf (stdout, "Waiting for thread to finish...\n"); */
360 if (!MHD_join_thread_(sel_thrd)) 352 if (!MHD_join_thread_(sel_thrd))
361 { 353 {
362 MHD_socket_close_(listen_socket); 354 MHD_socket_close_chk_(listen_socket);
363 fprintf (stderr, "Can't join select() thread\n"); 355 fprintf (stderr, "Can't join select() thread\n");
364 return 99; 356 return 99;
365 } 357 }
366 if (check_err) 358 if (check_err)
367 { 359 {
368 MHD_socket_close_(listen_socket); 360 MHD_socket_close_chk_(listen_socket);
369 fprintf (stderr, "Error in waiting thread\n"); 361 fprintf (stderr, "Error in waiting thread\n");
370 return 99; 362 return 99;
371 } 363 }
372 end_t = time (NULL); 364 end_t = time (NULL);
373 /* fprintf (stdout, "Thread finished.\n"); */ 365 /* fprintf (stdout, "Thread finished.\n"); */
374 MHD_socket_close_(listen_socket); 366 MHD_socket_close_chk_(listen_socket);
375 367
376 if (start_t == (time_t)-1 || end_t == (time_t)-1) 368 if (start_t == (time_t)-1 || end_t == (time_t)-1)
377 { 369 {
378 MHD_socket_close_(listen_socket); 370 MHD_socket_close_chk_(listen_socket);
379 fprintf (stderr, "Can't get current time\n"); 371 fprintf (stderr, "Can't get current time\n");
380 return 99; 372 return 99;
381 } 373 }
diff --git a/src/microhttpd/test_upgrade_common.c b/src/microhttpd/test_upgrade_common.c
index e6e72a8e..429b4d8e 100644
--- a/src/microhttpd/test_upgrade_common.c
+++ b/src/microhttpd/test_upgrade_common.c
@@ -46,13 +46,6 @@ static pthread_t pt_client;
46static int done; 46static int done;
47 47
48 48
49void
50MHD_PANIC (char *msg)
51{
52 fprintf (stderr, "%s", msg);
53 abort ();
54}
55
56 49
57/** 50/**
58 * Change socket to non-blocking. 51 * Change socket to non-blocking.
@@ -231,7 +224,7 @@ run_usock_client (void *cls)
231 "World"); 224 "World");
232 recv_all (*sock, 225 recv_all (*sock,
233 "Finished"); 226 "Finished");
234 MHD_socket_close_ (*sock); 227 MHD_socket_close_chk_ (*sock);
235 done = 1; 228 done = 1;
236 return NULL; 229 return NULL;
237} 230}
diff --git a/src/microhttpd/test_upgrade_ssl.c b/src/microhttpd/test_upgrade_ssl.c
index cdceb410..4e601588 100644
--- a/src/microhttpd/test_upgrade_ssl.c
+++ b/src/microhttpd/test_upgrade_ssl.c
@@ -72,15 +72,15 @@ openssl_connect (int *sock,
72 if (0 != chld) 72 if (0 != chld)
73 { 73 {
74 *sock = sp[1]; 74 *sock = sp[1];
75 MHD_socket_close_ (sp[0]); 75 MHD_socket_close_chk_ (sp[0]);
76 return chld; 76 return chld;
77 } 77 }
78 MHD_socket_close_ (sp[1]); 78 MHD_socket_close_chk_ (sp[1]);
79 (void) close (0); 79 (void) close (0);
80 (void) close (1); 80 (void) close (1);
81 dup2 (sp[0], 0); 81 dup2 (sp[0], 0);
82 dup2 (sp[0], 1); 82 dup2 (sp[0], 1);
83 MHD_socket_close_ (sp[0]); 83 MHD_socket_close_chk_ (sp[0]);
84 sprintf (destination, 84 sprintf (destination,
85 "localhost:%u", 85 "localhost:%u",
86 (unsigned int) port); 86 (unsigned int) port);
diff --git a/src/testcurl/https/test_https_time_out.c b/src/testcurl/https/test_https_time_out.c
index b1725256..bd14b8a2 100644
--- a/src/testcurl/https/test_https_time_out.c
+++ b/src/testcurl/https/test_https_time_out.c
@@ -27,20 +27,10 @@
27 27
28#include "platform.h" 28#include "platform.h"
29#include "microhttpd.h" 29#include "microhttpd.h"
30#include "internal.h"
31#include "tls_test_common.h" 30#include "tls_test_common.h"
32#include <gcrypt.h> 31#include <gcrypt.h>
33#include "mhd_sockets.h" /* only macros used */ 32#include "mhd_sockets.h" /* only macros used */
34 33
35#undef MHD_PANIC
36
37
38void
39MHD_PANIC (char *msg)
40{
41 fprintf (stderr, "%s", msg);
42 abort ();
43}
44 34
45#ifdef _WIN32 35#ifdef _WIN32
46#ifndef WIN32_LEAN_AND_MEAN 36#ifndef WIN32_LEAN_AND_MEAN
@@ -80,7 +70,7 @@ test_tls_session_time_out (gnutls_session_t session)
80 if (ret < 0) 70 if (ret < 0)
81 { 71 {
82 fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT); 72 fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT);
83 MHD_socket_close_ (sd); 73 MHD_socket_close_chk_ (sd);
84 return -1; 74 return -1;
85 } 75 }
86 76
@@ -88,7 +78,7 @@ test_tls_session_time_out (gnutls_session_t session)
88 if (ret < 0) 78 if (ret < 0)
89 { 79 {
90 fprintf (stderr, "Handshake failed\n"); 80 fprintf (stderr, "Handshake failed\n");
91 MHD_socket_close_ (sd); 81 MHD_socket_close_chk_ (sd);
92 return -1; 82 return -1;
93 } 83 }
94 84
@@ -99,11 +89,11 @@ test_tls_session_time_out (gnutls_session_t session)
99 if (send (sd, "", 1, 0) == 0) 89 if (send (sd, "", 1, 0) == 0)
100 { 90 {
101 fprintf (stderr, "Connection failed to time-out\n"); 91 fprintf (stderr, "Connection failed to time-out\n");
102 MHD_socket_close_ (sd); 92 MHD_socket_close_chk_ (sd);
103 return -1; 93 return -1;
104 } 94 }
105 95
106 MHD_socket_close_ (sd); 96 MHD_socket_close_chk_ (sd);
107 return 0; 97 return 0;
108} 98}
109 99
diff --git a/src/testcurl/https/test_tls_extensions.c b/src/testcurl/https/test_tls_extensions.c
index cc87c2b2..4cbdcaed 100644
--- a/src/testcurl/https/test_tls_extensions.c
+++ b/src/testcurl/https/test_tls_extensions.c
@@ -191,7 +191,7 @@ test_hello_extension (gnutls_session_t session, extensions_t exten_t,
191 191
192cleanup: 192cleanup:
193 if (-1 != sd) 193 if (-1 != sd)
194 MHD_socket_close_ (sd); 194 MHD_socket_close_chk_ (sd);
195 gnutls_free (cbc.buf); 195 gnutls_free (cbc.buf);
196 return ret; 196 return ret;
197} 197}
diff --git a/src/testcurl/test_get.c b/src/testcurl/test_get.c
index abcd848b..95286023 100644
--- a/src/testcurl/test_get.c
+++ b/src/testcurl/test_get.c
@@ -34,13 +34,6 @@
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
37void
38MHD_PANIC (char *msg)
39{
40 fprintf (stderr, "%s", msg);
41 abort ();
42}
43
44 37
45#ifdef _WIN32 38#ifdef _WIN32
46#ifndef WIN32_LEAN_AND_MEAN 39#ifndef WIN32_LEAN_AND_MEAN
@@ -501,7 +494,7 @@ testStopRace (int poll_flag)
501 if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0) 494 if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0)
502 { 495 {
503 fprintf(stderr, "connect error\n"); 496 fprintf(stderr, "connect error\n");
504 MHD_socket_close_ (fd); 497 MHD_socket_close_chk_ (fd);
505 return 512; 498 return 512;
506 } 499 }
507 500
@@ -512,7 +505,7 @@ testStopRace (int poll_flag)
512 /* printf("Stopping daemon\n"); */ 505 /* printf("Stopping daemon\n"); */
513 MHD_stop_daemon (d); 506 MHD_stop_daemon (d);
514 507
515 MHD_socket_close_ (fd); 508 MHD_socket_close_chk_ (fd);
516 509
517 /* printf("good\n"); */ 510 /* printf("good\n"); */
518 return 0; 511 return 0;
diff --git a/src/testcurl/test_quiesce.c b/src/testcurl/test_quiesce.c
index 695c5db9..254e7c99 100644
--- a/src/testcurl/test_quiesce.c
+++ b/src/testcurl/test_quiesce.c
@@ -34,13 +34,6 @@
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
37void
38MHD_PANIC (char *msg)
39{
40 fprintf (stderr, "%s", msg);
41 abort ();
42}
43
44 37
45#ifndef WINDOWS 38#ifndef WINDOWS
46#include <unistd.h> 39#include <unistd.h>
@@ -150,7 +143,7 @@ ServeOneRequest(void *param)
150 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max)) 143 if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
151 { 144 {
152 MHD_stop_daemon (d); 145 MHD_stop_daemon (d);
153 MHD_socket_close_(fd); 146 MHD_socket_close_chk_(fd);
154 return "MHD_get_fdset() failed"; 147 return "MHD_get_fdset() failed";
155 } 148 }
156 tv.tv_sec = 0; 149 tv.tv_sec = 0;
@@ -293,7 +286,7 @@ testGet (int type, int pool_count, int poll_flag)
293 fprintf(stderr, "%s\n", cbc.buf); 286 fprintf(stderr, "%s\n", cbc.buf);
294 curl_easy_cleanup (c); 287 curl_easy_cleanup (c);
295 MHD_stop_daemon (d); 288 MHD_stop_daemon (d);
296 MHD_socket_close_(fd); 289 MHD_socket_close_chk_(fd);
297 return 4; 290 return 4;
298 } 291 }
299 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 292 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
@@ -301,7 +294,7 @@ testGet (int type, int pool_count, int poll_flag)
301 fprintf(stderr, "%s\n", cbc.buf); 294 fprintf(stderr, "%s\n", cbc.buf);
302 curl_easy_cleanup (c); 295 curl_easy_cleanup (c);
303 MHD_stop_daemon (d); 296 MHD_stop_daemon (d);
304 MHD_socket_close_(fd); 297 MHD_socket_close_chk_(fd);
305 return 8; 298 return 8;
306 } 299 }
307 300
@@ -313,12 +306,12 @@ testGet (int type, int pool_count, int poll_flag)
313 fprintf (stderr, "curl_easy_perform should fail\n"); 306 fprintf (stderr, "curl_easy_perform should fail\n");
314 curl_easy_cleanup (c); 307 curl_easy_cleanup (c);
315 MHD_stop_daemon (d); 308 MHD_stop_daemon (d);
316 MHD_socket_close_(fd); 309 MHD_socket_close_chk_(fd);
317 return 2; 310 return 2;
318 } 311 }
319 curl_easy_cleanup (c); 312 curl_easy_cleanup (c);
320 MHD_stop_daemon (d); 313 MHD_stop_daemon (d);
321 MHD_socket_close_(fd); 314 MHD_socket_close_chk_(fd);
322 315
323 return 0; 316 return 0;
324} 317}
@@ -478,7 +471,7 @@ testExternalGet ()
478 curl_multi_cleanup (multi); 471 curl_multi_cleanup (multi);
479 } 472 }
480 MHD_stop_daemon (d); 473 MHD_stop_daemon (d);
481 MHD_socket_close_ (fd); 474 MHD_socket_close_chk_ (fd);
482 if (cbc.pos != strlen ("/hello_world")) 475 if (cbc.pos != strlen ("/hello_world"))
483 return 8192; 476 return 8192;
484 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) 477 if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))