mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-29 04:09:31 +03:00
Refactored mhd_locks.h and mhd_sockets.h: allow usage of macros without
aborting of execution.
This commit is contained in:
+13
-13
@@ -614,7 +614,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
|
||||
{
|
||||
/* either error or http 1.0 transfer, close socket! */
|
||||
response->total_size = connection->response_write_position;
|
||||
MHD_mutex_unlock_ (&response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&response->mutex);
|
||||
if ( ((ssize_t)MHD_CONTENT_READER_END_OF_STREAM) == ret)
|
||||
MHD_connection_close_ (connection,
|
||||
MHD_REQUEST_TERMINATED_COMPLETED_OK);
|
||||
@@ -628,7 +628,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
|
||||
if (0 == ret)
|
||||
{
|
||||
connection->state = MHD_CONNECTION_NORMAL_BODY_UNREADY;
|
||||
MHD_mutex_unlock_ (&response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&response->mutex);
|
||||
return MHD_NO;
|
||||
}
|
||||
return MHD_YES;
|
||||
@@ -2457,7 +2457,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
uint64_t data_write_offset;
|
||||
|
||||
if (NULL != response->crc)
|
||||
MHD_mutex_lock_ (&response->mutex);
|
||||
MHD_mutex_lock_chk_ (&response->mutex);
|
||||
if (MHD_YES != try_ready_normal_body (connection))
|
||||
{
|
||||
/* mutex was already unlocked by try_ready_normal_body */
|
||||
@@ -2483,7 +2483,7 @@ MHD_connection_handle_write (struct MHD_Connection *connection)
|
||||
response->data_start]);
|
||||
#endif
|
||||
if (NULL != response->crc)
|
||||
MHD_mutex_unlock_ (&response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&response->mutex);
|
||||
if (ret < 0)
|
||||
{
|
||||
if (MHD_SCKT_ERR_IS_EINTR_ (err) ||
|
||||
@@ -2569,7 +2569,7 @@ cleanup_connection (struct MHD_Connection *connection)
|
||||
}
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
{
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2597,7 +2597,7 @@ cleanup_connection (struct MHD_Connection *connection)
|
||||
connection->resuming = MHD_NO;
|
||||
connection->in_idle = MHD_NO;
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_(&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_(&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -2906,18 +2906,18 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
|
||||
break;
|
||||
case MHD_CONNECTION_NORMAL_BODY_UNREADY:
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_lock_ (&connection->response->mutex);
|
||||
MHD_mutex_lock_chk_ (&connection->response->mutex);
|
||||
if (0 == connection->response->total_size)
|
||||
{
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_unlock_ (&connection->response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&connection->response->mutex);
|
||||
connection->state = MHD_CONNECTION_BODY_SENT;
|
||||
continue;
|
||||
}
|
||||
if (MHD_YES == try_ready_normal_body (connection))
|
||||
{
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_unlock_ (&connection->response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&connection->response->mutex);
|
||||
connection->state = MHD_CONNECTION_NORMAL_BODY_READY;
|
||||
/* Buffering for flushable socket was already enabled*/
|
||||
if (MHD_NO == socket_flush_possible (connection))
|
||||
@@ -2932,20 +2932,20 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
|
||||
break;
|
||||
case MHD_CONNECTION_CHUNKED_BODY_UNREADY:
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_lock_ (&connection->response->mutex);
|
||||
MHD_mutex_lock_chk_ (&connection->response->mutex);
|
||||
if ( (0 == connection->response->total_size) ||
|
||||
(connection->response_write_position ==
|
||||
connection->response->total_size) )
|
||||
{
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_unlock_ (&connection->response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&connection->response->mutex);
|
||||
connection->state = MHD_CONNECTION_BODY_SENT;
|
||||
continue;
|
||||
}
|
||||
if (MHD_YES == try_ready_chunked_body (connection))
|
||||
{
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_unlock_ (&connection->response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&connection->response->mutex);
|
||||
connection->state = MHD_CONNECTION_CHUNKED_BODY_READY;
|
||||
/* Buffering for flushable socket was already enabled */
|
||||
if (MHD_NO == socket_flush_possible (connection))
|
||||
@@ -2953,7 +2953,7 @@ MHD_connection_handle_idle (struct MHD_Connection *connection)
|
||||
continue;
|
||||
}
|
||||
if (NULL != connection->response->crc)
|
||||
MHD_mutex_unlock_ (&connection->response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&connection->response->mutex);
|
||||
break;
|
||||
case MHD_CONNECTION_BODY_SENT:
|
||||
if (MHD_NO == build_header_response (connection))
|
||||
|
||||
+59
-59
@@ -195,7 +195,7 @@ struct MHD_IPCount
|
||||
static void
|
||||
MHD_ip_count_lock (struct MHD_Daemon *daemon)
|
||||
{
|
||||
MHD_mutex_lock_(&daemon->per_ip_connection_mutex);
|
||||
MHD_mutex_lock_chk_(&daemon->per_ip_connection_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ MHD_ip_count_lock (struct MHD_Daemon *daemon)
|
||||
static void
|
||||
MHD_ip_count_unlock (struct MHD_Daemon *daemon)
|
||||
{
|
||||
MHD_mutex_unlock_(&daemon->per_ip_connection_mutex);
|
||||
MHD_mutex_unlock_chk_(&daemon->per_ip_connection_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -962,7 +962,7 @@ finish_upgrade_close (struct MHD_UpgradeResponseHandle *urh)
|
||||
NULL)) )
|
||||
MHD_PANIC (_("Failed to remove FD from epoll set\n"));
|
||||
#endif
|
||||
MHD_socket_close_ (urh->mhd.socket);
|
||||
MHD_socket_close_chk_ (urh->mhd.socket);
|
||||
}
|
||||
MHD_resume_connection (connection);
|
||||
MHD_connection_close_ (connection,
|
||||
@@ -1532,7 +1532,7 @@ exit:
|
||||
{
|
||||
shutdown (con->socket_fd,
|
||||
SHUT_WR);
|
||||
MHD_socket_close_ (con->socket_fd);
|
||||
MHD_socket_close_chk_ (con->socket_fd);
|
||||
con->socket_fd = MHD_INVALID_SOCKET;
|
||||
}
|
||||
return (MHD_THRD_RTRN_TYPE_) 0;
|
||||
@@ -1771,7 +1771,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
external_add);
|
||||
}
|
||||
/* all pools are at their connection limit, must refuse */
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
#if ENFILE
|
||||
errno = ENFILE;
|
||||
#endif
|
||||
@@ -1788,7 +1788,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
(int) client_socket,
|
||||
(int) FD_SETSIZE);
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
#if EINVAL
|
||||
errno = EINVAL;
|
||||
#endif
|
||||
@@ -1813,7 +1813,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
MHD_DLOG (daemon,
|
||||
_("Server reached connection limit. Closing inbound connection.\n"));
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
#if ENFILE
|
||||
errno = ENFILE;
|
||||
#endif
|
||||
@@ -1832,7 +1832,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
_("Connection rejected by application. Closing connection.\n"));
|
||||
#endif
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
MHD_ip_limit_del (daemon,
|
||||
addr,
|
||||
addrlen);
|
||||
@@ -1862,7 +1862,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
"Error allocating memory: %s\n",
|
||||
MHD_strerror_ (errno));
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
MHD_ip_limit_del (daemon,
|
||||
addr,
|
||||
addrlen);
|
||||
@@ -1880,7 +1880,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
_("Error allocating memory: %s\n"),
|
||||
MHD_strerror_ (errno));
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
MHD_ip_limit_del (daemon,
|
||||
addr,
|
||||
addrlen);
|
||||
@@ -1900,7 +1900,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
_("Error allocating memory: %s\n"),
|
||||
MHD_strerror_ (errno));
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
MHD_ip_limit_del (daemon,
|
||||
addr,
|
||||
addrlen);
|
||||
@@ -1961,7 +1961,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
_("Failed to setup TLS credentials: unknown credential type %d\n"),
|
||||
daemon->cred_type);
|
||||
#endif
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
MHD_ip_limit_del (daemon,
|
||||
addr,
|
||||
addrlen);
|
||||
@@ -1988,7 +1988,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
{
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2000,7 +2000,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
daemon->connections_tail,
|
||||
connection);
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
|
||||
if (NULL != daemon->notify_connection)
|
||||
daemon->notify_connection (daemon->notify_connection_cls,
|
||||
@@ -2080,13 +2080,13 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
connection,
|
||||
&connection->socket_context,
|
||||
MHD_CONNECTION_NOTIFY_CLOSED);
|
||||
MHD_socket_close_ (client_socket);
|
||||
MHD_socket_close_chk_ (client_socket);
|
||||
MHD_ip_limit_del (daemon,
|
||||
addr,
|
||||
addrlen);
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
{
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2098,7 +2098,7 @@ internal_add_connection (struct MHD_Daemon *daemon,
|
||||
daemon->connections_tail,
|
||||
connection);
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_pool_destroy (connection->pool);
|
||||
free (connection->addr);
|
||||
free (connection);
|
||||
@@ -2144,7 +2144,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
|
||||
MHD_PANIC (_("Cannot suspend connections without enabling MHD_USE_SUSPEND_RESUME!\n"));
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
{
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2187,7 +2187,7 @@ MHD_suspend_connection (struct MHD_Connection *connection)
|
||||
#endif
|
||||
connection->suspended = MHD_YES;
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -2208,7 +2208,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
|
||||
if (MHD_USE_SUSPEND_RESUME != (daemon->options & MHD_USE_SUSPEND_RESUME))
|
||||
MHD_PANIC (_("Cannot resume connections without enabling MHD_USE_SUSPEND_RESUME!\n"));
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
connection->resuming = MHD_YES;
|
||||
daemon->resuming = MHD_YES;
|
||||
if ( (! MHD_INVALID_PIPE_(daemon->wpipe)) &&
|
||||
@@ -2220,7 +2220,7 @@ MHD_resume_connection (struct MHD_Connection *connection)
|
||||
#endif
|
||||
}
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -2240,7 +2240,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
|
||||
|
||||
ret = MHD_NO;
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
if (MHD_NO != daemon->resuming)
|
||||
next = daemon->suspended_connections_head;
|
||||
|
||||
@@ -2295,7 +2295,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
|
||||
pos->resuming = MHD_NO;
|
||||
}
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -2424,7 +2424,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
|
||||
#endif
|
||||
if (MHD_INVALID_SOCKET != s)
|
||||
{
|
||||
MHD_socket_close_ (s);
|
||||
MHD_socket_close_chk_ (s);
|
||||
}
|
||||
if ( MHD_SCKT_ERR_IS_LOW_RESOURCES_ (err) )
|
||||
{
|
||||
@@ -2499,7 +2499,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
|
||||
struct MHD_Connection *pos;
|
||||
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
while (NULL != (pos = daemon->cleanup_head))
|
||||
{
|
||||
DLL_remove (daemon->cleanup_head,
|
||||
@@ -2565,14 +2565,14 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
|
||||
}
|
||||
if (MHD_INVALID_SOCKET != pos->socket_fd)
|
||||
{
|
||||
MHD_socket_close_ (pos->socket_fd);
|
||||
MHD_socket_close_chk_ (pos->socket_fd);
|
||||
}
|
||||
if (NULL != pos->addr)
|
||||
free (pos->addr);
|
||||
free (pos);
|
||||
}
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
}
|
||||
|
||||
|
||||
@@ -4791,7 +4791,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
(unsigned int) port,
|
||||
MHD_socket_last_strerr_ ());
|
||||
#endif
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
#ifdef TCP_FASTOPEN
|
||||
@@ -4821,7 +4821,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
_("Failed to listen for connections: %s\n"),
|
||||
MHD_socket_last_strerr_ ());
|
||||
#endif
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
}
|
||||
@@ -4843,7 +4843,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
/* Accept must be non-blocking. Multiple children may wake up
|
||||
* to handle a new connection, but only one will win the race.
|
||||
* The others must immediately return. */
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
}
|
||||
@@ -4857,7 +4857,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
socket_fd,
|
||||
FD_SETSIZE);
|
||||
#endif
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
@@ -4895,7 +4895,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
_("MHD failed to initialize IP connection limit mutex\n"));
|
||||
#endif
|
||||
if (MHD_INVALID_SOCKET != socket_fd)
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
if (! MHD_mutex_init_ (&daemon->cleanup_connection_mutex))
|
||||
@@ -4904,9 +4904,9 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
MHD_DLOG (daemon,
|
||||
_("MHD failed to initialize IP connection limit mutex\n"));
|
||||
#endif
|
||||
MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
|
||||
if (MHD_INVALID_SOCKET != socket_fd)
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
@@ -4920,9 +4920,9 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
_("Failed to initialize TLS support\n"));
|
||||
#endif
|
||||
if (MHD_INVALID_SOCKET != socket_fd)
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
|
||||
goto free_and_fail;
|
||||
}
|
||||
#endif
|
||||
@@ -4942,10 +4942,10 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
_("Failed to create listen thread: %s\n"),
|
||||
MHD_strerror_ (errno));
|
||||
#endif
|
||||
MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
|
||||
if (MHD_INVALID_SOCKET != socket_fd)
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
goto free_and_fail;
|
||||
}
|
||||
if ( (daemon->worker_pool_size > 0) &&
|
||||
@@ -5050,7 +5050,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
#endif
|
||||
/* Free memory for this worker; cleanup below handles
|
||||
* all previously-created workers. */
|
||||
MHD_mutex_destroy_ (&d->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&d->cleanup_connection_mutex);
|
||||
goto thread_failed;
|
||||
}
|
||||
}
|
||||
@@ -5071,9 +5071,9 @@ thread_failed:
|
||||
if (0 == i)
|
||||
{
|
||||
if (MHD_INVALID_SOCKET != socket_fd)
|
||||
MHD_socket_close_ (socket_fd);
|
||||
MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
|
||||
MHD_socket_close_chk_ (socket_fd);
|
||||
MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
|
||||
if (NULL != daemon->worker_pool)
|
||||
free (daemon->worker_pool);
|
||||
goto free_and_fail;
|
||||
@@ -5111,7 +5111,7 @@ thread_failed:
|
||||
#endif
|
||||
#ifdef DAUTH_SUPPORT
|
||||
free (daemon->nnc);
|
||||
MHD_mutex_destroy_ (&daemon->nnc_lock);
|
||||
MHD_mutex_destroy_chk_ (&daemon->nnc_lock);
|
||||
#endif
|
||||
#if HTTPS_SUPPORT
|
||||
if (0 != (flags & MHD_USE_SSL))
|
||||
@@ -5177,7 +5177,7 @@ close_all_connections (struct MHD_Daemon *daemon)
|
||||
/* first, make sure all threads are aware of shutdown; need to
|
||||
traverse DLLs in peace... */
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_lock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_lock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
if (NULL != daemon->suspended_connections_head)
|
||||
MHD_PANIC (_("MHD_stop_daemon() called while we have suspended connections.\n"));
|
||||
for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
|
||||
@@ -5191,7 +5191,7 @@ close_all_connections (struct MHD_Daemon *daemon)
|
||||
#endif
|
||||
}
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
MHD_mutex_unlock_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_unlock_chk_ (&daemon->cleanup_connection_mutex);
|
||||
|
||||
/* now, collect per-connection threads */
|
||||
if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
@@ -5333,13 +5333,13 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
if (!MHD_join_thread_ (daemon->worker_pool[i].pid))
|
||||
MHD_PANIC (_("Failed to join a thread\n"));
|
||||
close_all_connections (&daemon->worker_pool[i]);
|
||||
MHD_mutex_destroy_ (&daemon->worker_pool[i].cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->worker_pool[i].cleanup_connection_mutex);
|
||||
#ifdef EPOLL_SUPPORT
|
||||
if (-1 != daemon->worker_pool[i].epoll_fd)
|
||||
MHD_socket_close_ (daemon->worker_pool[i].epoll_fd);
|
||||
MHD_socket_close_chk_ (daemon->worker_pool[i].epoll_fd);
|
||||
#if HTTPS_SUPPORT
|
||||
if (-1 != daemon->worker_pool[i].epoll_upgrade_fd)
|
||||
MHD_socket_close_ (daemon->worker_pool[i].epoll_upgrade_fd);
|
||||
MHD_socket_close_chk_ (daemon->worker_pool[i].epoll_upgrade_fd);
|
||||
#endif
|
||||
#endif
|
||||
/* Individual pipes are always used */
|
||||
@@ -5368,7 +5368,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
}
|
||||
close_all_connections (daemon);
|
||||
if (MHD_INVALID_SOCKET != fd)
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
|
||||
/* TLS clean up */
|
||||
#if HTTPS_SUPPORT
|
||||
@@ -5387,20 +5387,20 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
#ifdef EPOLL_SUPPORT
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
|
||||
(-1 != daemon->epoll_fd) )
|
||||
MHD_socket_close_ (daemon->epoll_fd);
|
||||
MHD_socket_close_chk_ (daemon->epoll_fd);
|
||||
#if HTTPS_SUPPORT
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL)) &&
|
||||
(-1 != daemon->epoll_upgrade_fd) )
|
||||
MHD_socket_close_ (daemon->epoll_upgrade_fd);
|
||||
MHD_socket_close_chk_ (daemon->epoll_upgrade_fd);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DAUTH_SUPPORT
|
||||
free (daemon->nnc);
|
||||
MHD_mutex_destroy_ (&daemon->nnc_lock);
|
||||
MHD_mutex_destroy_chk_ (&daemon->nnc_lock);
|
||||
#endif
|
||||
MHD_mutex_destroy_ (&daemon->per_ip_connection_mutex);
|
||||
MHD_mutex_destroy_ (&daemon->cleanup_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->per_ip_connection_mutex);
|
||||
MHD_mutex_destroy_chk_ (&daemon->cleanup_connection_mutex);
|
||||
|
||||
if (! MHD_INVALID_PIPE_(daemon->wpipe))
|
||||
MHD_pipe_close_ (daemon->wpipe);
|
||||
@@ -5654,7 +5654,7 @@ gcry_w32_mutex_init (void **ppmtx)
|
||||
static int
|
||||
gcry_w32_mutex_destroy (void **ppmtx)
|
||||
{
|
||||
int res = (MHD_mutex_destroy_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
|
||||
int res = (MHD_mutex_destroy_chk_ ((MHD_mutex_*)*ppmtx)) ? 0 : 1;
|
||||
free (*ppmtx);
|
||||
return res;
|
||||
}
|
||||
@@ -5663,7 +5663,7 @@ gcry_w32_mutex_destroy (void **ppmtx)
|
||||
static int
|
||||
gcry_w32_mutex_lock (void **ppmtx)
|
||||
{
|
||||
MHD_mutex_lock_ ((MHD_mutex_*)*ppmtx);
|
||||
MHD_mutex_lock_chk_ ((MHD_mutex_*)*ppmtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -5671,7 +5671,7 @@ gcry_w32_mutex_lock (void **ppmtx)
|
||||
static int
|
||||
gcry_w32_mutex_unlock (void **ppmtx)
|
||||
{
|
||||
MHD_mutex_unlock_ ((MHD_mutex_*)*ppmtx);
|
||||
MHD_mutex_unlock_chk_ ((MHD_mutex_*)*ppmtx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -408,7 +408,7 @@ check_nonce_nc (struct MHD_Connection *connection,
|
||||
* then only increase the nonce counter by one.
|
||||
*/
|
||||
nn = &daemon->nnc[off];
|
||||
MHD_mutex_lock_ (&daemon->nnc_lock);
|
||||
MHD_mutex_lock_chk_ (&daemon->nnc_lock);
|
||||
if (0 == nc)
|
||||
{
|
||||
/* Fresh nonce, reinitialize array */
|
||||
@@ -416,7 +416,7 @@ check_nonce_nc (struct MHD_Connection *connection,
|
||||
nonce);
|
||||
nn->nc = 0;
|
||||
nn->nmask = 0;
|
||||
MHD_mutex_unlock_ (&daemon->nnc_lock);
|
||||
MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
|
||||
return MHD_YES;
|
||||
}
|
||||
/* Note that we use 64 here, as we do not store the
|
||||
@@ -428,7 +428,7 @@ check_nonce_nc (struct MHD_Connection *connection,
|
||||
{
|
||||
/* Out-of-order nonce, but within 64-bit bitmask, set bit */
|
||||
nn->nmask |= (1LLU < (nn->nc - nc - 1));
|
||||
MHD_mutex_unlock_ (&daemon->nnc_lock);
|
||||
MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
|
||||
return MHD_YES;
|
||||
}
|
||||
|
||||
@@ -437,7 +437,7 @@ check_nonce_nc (struct MHD_Connection *connection,
|
||||
nonce)) )
|
||||
{
|
||||
/* Nonce does not match, fail */
|
||||
MHD_mutex_unlock_ (&daemon->nnc_lock);
|
||||
MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
|
||||
#ifdef HAVE_MESSAGES
|
||||
MHD_DLOG (daemon,
|
||||
_("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,
|
||||
else
|
||||
nn->nmask = 0; /* big jump, unset all bits in the mask */
|
||||
nn->nc = nc;
|
||||
MHD_mutex_unlock_ (&daemon->nnc_lock);
|
||||
MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
|
||||
return MHD_YES;
|
||||
}
|
||||
|
||||
|
||||
+23
-17
@@ -35,6 +35,29 @@
|
||||
#include <gnutls/abstract.h>
|
||||
#endif
|
||||
#endif
|
||||
#include "mhd_options.h"
|
||||
|
||||
|
||||
#ifdef MHD_PANIC
|
||||
/* Override any defined MHD_PANIC macro with proper one */
|
||||
#undef MHD_PANIC
|
||||
#endif /* MHD_PANIC */
|
||||
|
||||
#ifdef HAVE_MESSAGES
|
||||
/**
|
||||
* Trigger 'panic' action based on fatal errors.
|
||||
*
|
||||
* @param msg error message (const char *)
|
||||
*/
|
||||
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); BUILTIN_NOT_REACHED; } while (0)
|
||||
#else
|
||||
/**
|
||||
* Trigger 'panic' action based on fatal errors.
|
||||
*
|
||||
* @param msg error message (const char *)
|
||||
*/
|
||||
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); BUILTIN_NOT_REACHED; } while (0)
|
||||
#endif
|
||||
|
||||
#include "mhd_threads.h"
|
||||
#include "mhd_locks.h"
|
||||
@@ -82,23 +105,6 @@ extern void *mhd_panic_cls;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_MESSAGES
|
||||
/**
|
||||
* Trigger 'panic' action based on fatal errors.
|
||||
*
|
||||
* @param msg error message (const char *)
|
||||
*/
|
||||
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, msg); BUILTIN_NOT_REACHED; } while (0)
|
||||
#else
|
||||
/**
|
||||
* Trigger 'panic' action based on fatal errors.
|
||||
*
|
||||
* @param msg error message (const char *)
|
||||
*/
|
||||
#define MHD_PANIC(msg) do { mhd_panic (mhd_panic_cls, __FILE__, __LINE__, NULL); BUILTIN_NOT_REACHED; } while (0)
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* State of the socket with respect to epoll (bitmask).
|
||||
*/
|
||||
|
||||
@@ -245,8 +245,8 @@ struct MHD_Pipe
|
||||
* Close emulated pipe FDs
|
||||
*/
|
||||
#define MHD_pipe_close_(pip) do { \
|
||||
MHD_socket_close_ ((pip).fd[0]); \
|
||||
MHD_socket_close_ ((pip).fd[1]); \
|
||||
MHD_socket_close_chk_ ((pip).fd[0]); \
|
||||
MHD_socket_close_chk_ ((pip).fd[1]); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
|
||||
+51
-16
@@ -54,6 +54,15 @@
|
||||
# error No base mutex API is available.
|
||||
#endif
|
||||
|
||||
#ifndef MHD_PANIC
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
/* Simple implementation of MHD_PANIC, to be used outside lib */
|
||||
# define MHD_PANIC(msg) do { fprintf (stderr, \
|
||||
"Abnormal termination at %d line in file %s: %s\n", \
|
||||
(int)__LINE__, __FILE__, msg); abort();} while(0)
|
||||
#endif /* ! MHD_PANIC */
|
||||
|
||||
#if defined(MHD_PTHREAD_MUTEX_)
|
||||
typedef pthread_mutex_t MHD_mutex_;
|
||||
#elif defined(MHD_W32_MUTEX_)
|
||||
@@ -80,60 +89,86 @@
|
||||
/**
|
||||
* Destroy previously initialised mutex.
|
||||
* @param pmutex pointer to mutex
|
||||
* @return nonzero on success, zero otherwise
|
||||
*/
|
||||
#define MHD_mutex_destroy_(pmutex) do { \
|
||||
errno = 0; \
|
||||
if (0 != pthread_mutex_destroy((pmutex))) \
|
||||
MHD_PANIC (_("Failed to destroy mutex\n")); \
|
||||
} while (0)
|
||||
#define MHD_mutex_destroy_(pmutex) (!(pthread_mutex_destroy((pmutex))))
|
||||
#elif defined(MHD_W32_MUTEX_)
|
||||
/**
|
||||
* Destroy previously initialised mutex.
|
||||
* @param pmutex pointer to mutex
|
||||
* @return Always nonzero
|
||||
*/
|
||||
#define MHD_mutex_destroy_(pmutex) DeleteCriticalSection((pmutex))
|
||||
#define MHD_mutex_destroy_(pmutex) (DeleteCriticalSection((pmutex)), !0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Destroy previously initialised mutex and abort execution
|
||||
* if error is detected.
|
||||
* @param pmutex pointer to mutex
|
||||
*/
|
||||
#define MHD_mutex_destroy_chk_(pmutex) do { \
|
||||
if (!MHD_mutex_destroy_(pmutex)) \
|
||||
MHD_PANIC(_("Failed to destroy mutex.\n")); \
|
||||
} while(0)
|
||||
|
||||
|
||||
#if defined(MHD_PTHREAD_MUTEX_)
|
||||
/**
|
||||
* Acquire lock on previously initialised mutex.
|
||||
* If mutex was already locked by other thread, function
|
||||
* blocks until mutex becomes available.
|
||||
* @param pmutex pointer to mutex
|
||||
* @return nonzero on success, zero otherwise
|
||||
*/
|
||||
#define MHD_mutex_lock_(pmutex) do { \
|
||||
if (0 != pthread_mutex_lock((pmutex))) \
|
||||
MHD_PANIC (_("Failed to lock mutex\n")); \
|
||||
} while (0)
|
||||
#define MHD_mutex_lock_(pmutex) (!(pthread_mutex_lock((pmutex))))
|
||||
#elif defined(MHD_W32_MUTEX_)
|
||||
/**
|
||||
* Acquire lock on previously initialised mutex.
|
||||
* If mutex was already locked by other thread, function
|
||||
* blocks until mutex becomes available.
|
||||
* @param pmutex pointer to mutex
|
||||
* @return Always nonzero
|
||||
*/
|
||||
#define MHD_mutex_lock_(pmutex) EnterCriticalSection((pmutex))
|
||||
#define MHD_mutex_lock_(pmutex) (EnterCriticalSection((pmutex)), !0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Acquire lock on previously initialised mutex.
|
||||
* If mutex was already locked by other thread, function
|
||||
* blocks until mutex becomes available.
|
||||
* If error is detected, execution will be aborted.
|
||||
* @param pmutex pointer to mutex
|
||||
*/
|
||||
#define MHD_mutex_lock_chk_(pmutex) do { \
|
||||
if (!MHD_mutex_lock_(pmutex)) \
|
||||
MHD_PANIC(_("Failed to lock mutex.\n")); \
|
||||
} while(0)
|
||||
|
||||
#if defined(MHD_PTHREAD_MUTEX_)
|
||||
/**
|
||||
* Unlock previously initialised and locked mutex.
|
||||
* @param pmutex pointer to mutex
|
||||
* @return nonzero on success, zero otherwise
|
||||
*/
|
||||
#define MHD_mutex_unlock_(pmutex) do { \
|
||||
if (0 != pthread_mutex_unlock((pmutex))) \
|
||||
MHD_PANIC (_("Failed to unlock mutex\n")); \
|
||||
} while (0)
|
||||
#define MHD_mutex_unlock_(pmutex) (!(pthread_mutex_unlock((pmutex))))
|
||||
#elif defined(MHD_W32_MUTEX_)
|
||||
/**
|
||||
* Unlock previously initialised and locked mutex.
|
||||
* @param pmutex pointer to mutex
|
||||
* @return Always nonzero
|
||||
*/
|
||||
#define MHD_mutex_unlock_(pmutex) LeaveCriticalSection((pmutex))
|
||||
#define MHD_mutex_unlock_(pmutex) (LeaveCriticalSection((pmutex)), !0)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Unlock previously initialised and locked mutex.
|
||||
* If error is detected, execution will be aborted.
|
||||
* @param pmutex pointer to mutex
|
||||
*/
|
||||
#define MHD_mutex_unlock_chk_(pmutex) do { \
|
||||
if (!MHD_mutex_unlock_(pmutex)) \
|
||||
MHD_PANIC(_("Failed to unlock mutex.\n")); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* A semaphore.
|
||||
|
||||
@@ -117,6 +117,15 @@
|
||||
# define _MHD_SYS_DEFAULT_FD_SETSIZE get_system_fdsetsize_value()
|
||||
#endif /* ! _MHD_FD_SETSIZE_IS_DEFAULT */
|
||||
|
||||
#ifndef MHD_PANIC
|
||||
# include <stdio.h>
|
||||
# include <stdlib.h>
|
||||
/* Simple implementation of MHD_PANIC, to be used outside lib */
|
||||
# define MHD_PANIC(msg) do { fprintf (stderr, \
|
||||
"Abnormal termination at %d line in file %s: %s\n", \
|
||||
(int)__LINE__, __FILE__, msg); abort();} while(0)
|
||||
#endif /* ! MHD_PANIC */
|
||||
|
||||
#ifndef MHD_SOCKET_DEFINED
|
||||
/**
|
||||
* MHD_socket is type for socket FDs
|
||||
@@ -195,20 +204,26 @@
|
||||
* errno is set to EINTR. Do not use HP-UNIX.
|
||||
*
|
||||
* @param fd descriptor to close
|
||||
* @return boolean true on success (error codes like EINTR and EIO are
|
||||
* counted as success, only EBADF counts as an error!),
|
||||
* boolean false otherwise.
|
||||
*/
|
||||
#if !defined(MHD_WINSOCK_SOCKETS)
|
||||
# define MHD_socket_close_(fd) do { \
|
||||
if ( (0 != close((fd))) && \
|
||||
(EBADF == errno) ) \
|
||||
MHD_PANIC (_("close failed\n")); \
|
||||
} while (0)
|
||||
# define MHD_socket_close_(fd) ((0 == close((fd))) || (EBADF != errno))
|
||||
#else
|
||||
# define MHD_socket_close_(fd) do { \
|
||||
if (0 != closesocket((fd)) ) \
|
||||
MHD_PANIC (_("close failed\n")); \
|
||||
} while (0)
|
||||
# define MHD_socket_close_(fd) (0 == closesocket((fd)))
|
||||
#endif
|
||||
|
||||
/**
|
||||
* MHD_socket_close_chk_(fd) close socket and abort execution
|
||||
* if error is detected.
|
||||
* @param fd socket to close
|
||||
*/
|
||||
#define MHD_socket_close_chk_(fd) do { \
|
||||
if (!MHD_socket_close_(fd)) \
|
||||
MHD_PANIC(_("Close socket failed.\n")); \
|
||||
} while(0)
|
||||
|
||||
/**
|
||||
* Check whether FD can be added to fd_set with specified FD_SETSIZE.
|
||||
* @param fd the fd to check
|
||||
|
||||
+14
-14
@@ -568,7 +568,7 @@ MHD_create_response_from_data (size_t size,
|
||||
{
|
||||
if (NULL == (tmp = malloc (size)))
|
||||
{
|
||||
MHD_mutex_destroy_ (&response->mutex);
|
||||
MHD_mutex_destroy_chk_ (&response->mutex);
|
||||
free (response);
|
||||
return NULL;
|
||||
}
|
||||
@@ -655,7 +655,7 @@ MHD_upgrade_action (struct MHD_UpgradeResponseHandle *urh,
|
||||
urh->was_closed = MHD_YES;
|
||||
if (MHD_INVALID_SOCKET != urh->app.socket)
|
||||
{
|
||||
MHD_socket_close_ (urh->app.socket);
|
||||
MHD_socket_close_chk_ (urh->app.socket);
|
||||
urh->app.socket = MHD_INVALID_SOCKET;
|
||||
}
|
||||
return MHD_YES;
|
||||
@@ -742,8 +742,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
|
||||
(int) sv[1],
|
||||
(int) FD_SETSIZE);
|
||||
#endif
|
||||
MHD_socket_close_ (sv[0]);
|
||||
MHD_socket_close_ (sv[1]);
|
||||
MHD_socket_close_chk_ (sv[0]);
|
||||
MHD_socket_close_chk_ (sv[1]);
|
||||
free (urh);
|
||||
return MHD_NO;
|
||||
}
|
||||
@@ -814,8 +814,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
|
||||
_("Call to epoll_ctl failed: %s\n"),
|
||||
MHD_socket_last_strerr_ ());
|
||||
#endif
|
||||
MHD_socket_close_ (sv[0]);
|
||||
MHD_socket_close_ (sv[1]);
|
||||
MHD_socket_close_chk_ (sv[0]);
|
||||
MHD_socket_close_chk_ (sv[1]);
|
||||
free (urh);
|
||||
return MHD_NO;
|
||||
}
|
||||
@@ -840,8 +840,8 @@ MHD_response_execute_upgrade_ (struct MHD_Response *response,
|
||||
_("Call to epoll_ctl failed: %s\n"),
|
||||
MHD_socket_last_strerr_ ());
|
||||
#endif
|
||||
MHD_socket_close_ (sv[0]);
|
||||
MHD_socket_close_ (sv[1]);
|
||||
MHD_socket_close_chk_ (sv[0]);
|
||||
MHD_socket_close_chk_ (sv[1]);
|
||||
free (urh);
|
||||
return MHD_NO;
|
||||
}
|
||||
@@ -986,14 +986,14 @@ MHD_destroy_response (struct MHD_Response *response)
|
||||
|
||||
if (NULL == response)
|
||||
return;
|
||||
MHD_mutex_lock_ (&response->mutex);
|
||||
MHD_mutex_lock_chk_ (&response->mutex);
|
||||
if (0 != --(response->reference_count))
|
||||
{
|
||||
MHD_mutex_unlock_ (&response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&response->mutex);
|
||||
return;
|
||||
}
|
||||
MHD_mutex_unlock_ (&response->mutex);
|
||||
MHD_mutex_destroy_ (&response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&response->mutex);
|
||||
MHD_mutex_destroy_chk_ (&response->mutex);
|
||||
if (NULL != response->crfc)
|
||||
response->crfc (response->crc_cls);
|
||||
while (NULL != response->first_header)
|
||||
@@ -1016,9 +1016,9 @@ MHD_destroy_response (struct MHD_Response *response)
|
||||
void
|
||||
MHD_increment_response_rc (struct MHD_Response *response)
|
||||
{
|
||||
MHD_mutex_lock_ (&response->mutex);
|
||||
MHD_mutex_lock_chk_ (&response->mutex);
|
||||
(response->reference_count)++;
|
||||
MHD_mutex_unlock_ (&response->mutex);
|
||||
MHD_mutex_unlock_chk_ (&response->mutex);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -90,14 +90,6 @@
|
||||
static _MHD_bool check_err;
|
||||
|
||||
|
||||
void
|
||||
MHD_PANIC (char *msg)
|
||||
{
|
||||
fprintf (stderr, "%s", msg);
|
||||
abort ();
|
||||
}
|
||||
|
||||
|
||||
static _MHD_bool
|
||||
has_in_name(const char *prog_name, const char *marker)
|
||||
{
|
||||
@@ -189,7 +181,7 @@ start_socket_listen(int domain)
|
||||
{
|
||||
fprintf (stderr, "Failed to bind socket: %u\n",
|
||||
(unsigned)sock_errno);
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
return MHD_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
@@ -198,7 +190,7 @@ start_socket_listen(int domain)
|
||||
{
|
||||
fprintf (stderr, "Failed to make socket non-blocking: %u\n",
|
||||
(unsigned)sock_errno);
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
return MHD_INVALID_SOCKET;
|
||||
}
|
||||
#else /* MHD_POSIX_SOCKETS */
|
||||
@@ -209,7 +201,7 @@ start_socket_listen(int domain)
|
||||
{
|
||||
fprintf (stderr, "Failed to make socket non-blocking: %s\n",
|
||||
MHD_socket_last_strerr_ ());
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
return MHD_INVALID_SOCKET;
|
||||
}
|
||||
#endif /* MHD_POSIX_SOCKETS */
|
||||
@@ -218,7 +210,7 @@ start_socket_listen(int domain)
|
||||
{
|
||||
fprintf (stderr, "Failed to listen on socket: %u\n",
|
||||
(unsigned)sock_errno);
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
return MHD_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
@@ -334,7 +326,7 @@ main (int argc, char *const *argv)
|
||||
#if defined(MHD_USE_POSIX_THREADS)
|
||||
if (0 != pthread_create (&sel_thrd, NULL, test_func, &listen_socket))
|
||||
{
|
||||
MHD_socket_close_ (listen_socket);
|
||||
MHD_socket_close_chk_ (listen_socket);
|
||||
fprintf (stderr, "Can't start thread\n");
|
||||
return 99;
|
||||
}
|
||||
@@ -342,7 +334,7 @@ main (int argc, char *const *argv)
|
||||
sel_thrd = (HANDLE)_beginthreadex (NULL, 0, test_func, &listen_socket, 0, NULL);
|
||||
if (0 == (sel_thrd))
|
||||
{
|
||||
MHD_socket_close_ (listen_socket);
|
||||
MHD_socket_close_chk_ (listen_socket);
|
||||
fprintf (stderr, "Can't start select() thread\n");
|
||||
return 99;
|
||||
}
|
||||
@@ -359,23 +351,23 @@ main (int argc, char *const *argv)
|
||||
/* fprintf (stdout, "Waiting for thread to finish...\n"); */
|
||||
if (!MHD_join_thread_(sel_thrd))
|
||||
{
|
||||
MHD_socket_close_(listen_socket);
|
||||
MHD_socket_close_chk_(listen_socket);
|
||||
fprintf (stderr, "Can't join select() thread\n");
|
||||
return 99;
|
||||
}
|
||||
if (check_err)
|
||||
{
|
||||
MHD_socket_close_(listen_socket);
|
||||
MHD_socket_close_chk_(listen_socket);
|
||||
fprintf (stderr, "Error in waiting thread\n");
|
||||
return 99;
|
||||
}
|
||||
end_t = time (NULL);
|
||||
/* fprintf (stdout, "Thread finished.\n"); */
|
||||
MHD_socket_close_(listen_socket);
|
||||
MHD_socket_close_chk_(listen_socket);
|
||||
|
||||
if (start_t == (time_t)-1 || end_t == (time_t)-1)
|
||||
{
|
||||
MHD_socket_close_(listen_socket);
|
||||
MHD_socket_close_chk_(listen_socket);
|
||||
fprintf (stderr, "Can't get current time\n");
|
||||
return 99;
|
||||
}
|
||||
|
||||
@@ -46,13 +46,6 @@ static pthread_t pt_client;
|
||||
static int done;
|
||||
|
||||
|
||||
void
|
||||
MHD_PANIC (char *msg)
|
||||
{
|
||||
fprintf (stderr, "%s", msg);
|
||||
abort ();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Change socket to non-blocking.
|
||||
@@ -231,7 +224,7 @@ run_usock_client (void *cls)
|
||||
"World");
|
||||
recv_all (*sock,
|
||||
"Finished");
|
||||
MHD_socket_close_ (*sock);
|
||||
MHD_socket_close_chk_ (*sock);
|
||||
done = 1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -72,15 +72,15 @@ openssl_connect (int *sock,
|
||||
if (0 != chld)
|
||||
{
|
||||
*sock = sp[1];
|
||||
MHD_socket_close_ (sp[0]);
|
||||
MHD_socket_close_chk_ (sp[0]);
|
||||
return chld;
|
||||
}
|
||||
MHD_socket_close_ (sp[1]);
|
||||
MHD_socket_close_chk_ (sp[1]);
|
||||
(void) close (0);
|
||||
(void) close (1);
|
||||
dup2 (sp[0], 0);
|
||||
dup2 (sp[0], 1);
|
||||
MHD_socket_close_ (sp[0]);
|
||||
MHD_socket_close_chk_ (sp[0]);
|
||||
sprintf (destination,
|
||||
"localhost:%u",
|
||||
(unsigned int) port);
|
||||
|
||||
@@ -27,20 +27,10 @@
|
||||
|
||||
#include "platform.h"
|
||||
#include "microhttpd.h"
|
||||
#include "internal.h"
|
||||
#include "tls_test_common.h"
|
||||
#include <gcrypt.h>
|
||||
#include "mhd_sockets.h" /* only macros used */
|
||||
|
||||
#undef MHD_PANIC
|
||||
|
||||
|
||||
void
|
||||
MHD_PANIC (char *msg)
|
||||
{
|
||||
fprintf (stderr, "%s", msg);
|
||||
abort ();
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
@@ -80,7 +70,7 @@ test_tls_session_time_out (gnutls_session_t session)
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf (stderr, "Error: %s\n", MHD_E_FAILED_TO_CONNECT);
|
||||
MHD_socket_close_ (sd);
|
||||
MHD_socket_close_chk_ (sd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -88,7 +78,7 @@ test_tls_session_time_out (gnutls_session_t session)
|
||||
if (ret < 0)
|
||||
{
|
||||
fprintf (stderr, "Handshake failed\n");
|
||||
MHD_socket_close_ (sd);
|
||||
MHD_socket_close_chk_ (sd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -99,11 +89,11 @@ test_tls_session_time_out (gnutls_session_t session)
|
||||
if (send (sd, "", 1, 0) == 0)
|
||||
{
|
||||
fprintf (stderr, "Connection failed to time-out\n");
|
||||
MHD_socket_close_ (sd);
|
||||
MHD_socket_close_chk_ (sd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
MHD_socket_close_ (sd);
|
||||
MHD_socket_close_chk_ (sd);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ test_hello_extension (gnutls_session_t session, extensions_t exten_t,
|
||||
|
||||
cleanup:
|
||||
if (-1 != sd)
|
||||
MHD_socket_close_ (sd);
|
||||
MHD_socket_close_chk_ (sd);
|
||||
gnutls_free (cbc.buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -34,13 +34,6 @@
|
||||
#include <time.h>
|
||||
#include "mhd_sockets.h" /* only macros used */
|
||||
|
||||
void
|
||||
MHD_PANIC (char *msg)
|
||||
{
|
||||
fprintf (stderr, "%s", msg);
|
||||
abort ();
|
||||
}
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
@@ -501,7 +494,7 @@ testStopRace (int poll_flag)
|
||||
if (connect (fd, (struct sockaddr *)(&sin), sizeof(sin)) < 0)
|
||||
{
|
||||
fprintf(stderr, "connect error\n");
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
return 512;
|
||||
}
|
||||
|
||||
@@ -512,7 +505,7 @@ testStopRace (int poll_flag)
|
||||
/* printf("Stopping daemon\n"); */
|
||||
MHD_stop_daemon (d);
|
||||
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
|
||||
/* printf("good\n"); */
|
||||
return 0;
|
||||
|
||||
@@ -34,13 +34,6 @@
|
||||
#include <pthread.h>
|
||||
#include "mhd_sockets.h" /* only macros used */
|
||||
|
||||
void
|
||||
MHD_PANIC (char *msg)
|
||||
{
|
||||
fprintf (stderr, "%s", msg);
|
||||
abort ();
|
||||
}
|
||||
|
||||
|
||||
#ifndef WINDOWS
|
||||
#include <unistd.h>
|
||||
@@ -150,7 +143,7 @@ ServeOneRequest(void *param)
|
||||
if (MHD_YES != MHD_get_fdset (d, &rs, &ws, &es, &max))
|
||||
{
|
||||
MHD_stop_daemon (d);
|
||||
MHD_socket_close_(fd);
|
||||
MHD_socket_close_chk_(fd);
|
||||
return "MHD_get_fdset() failed";
|
||||
}
|
||||
tv.tv_sec = 0;
|
||||
@@ -293,7 +286,7 @@ testGet (int type, int pool_count, int poll_flag)
|
||||
fprintf(stderr, "%s\n", cbc.buf);
|
||||
curl_easy_cleanup (c);
|
||||
MHD_stop_daemon (d);
|
||||
MHD_socket_close_(fd);
|
||||
MHD_socket_close_chk_(fd);
|
||||
return 4;
|
||||
}
|
||||
if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
|
||||
@@ -301,7 +294,7 @@ testGet (int type, int pool_count, int poll_flag)
|
||||
fprintf(stderr, "%s\n", cbc.buf);
|
||||
curl_easy_cleanup (c);
|
||||
MHD_stop_daemon (d);
|
||||
MHD_socket_close_(fd);
|
||||
MHD_socket_close_chk_(fd);
|
||||
return 8;
|
||||
}
|
||||
|
||||
@@ -313,12 +306,12 @@ testGet (int type, int pool_count, int poll_flag)
|
||||
fprintf (stderr, "curl_easy_perform should fail\n");
|
||||
curl_easy_cleanup (c);
|
||||
MHD_stop_daemon (d);
|
||||
MHD_socket_close_(fd);
|
||||
MHD_socket_close_chk_(fd);
|
||||
return 2;
|
||||
}
|
||||
curl_easy_cleanup (c);
|
||||
MHD_stop_daemon (d);
|
||||
MHD_socket_close_(fd);
|
||||
MHD_socket_close_chk_(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -478,7 +471,7 @@ testExternalGet ()
|
||||
curl_multi_cleanup (multi);
|
||||
}
|
||||
MHD_stop_daemon (d);
|
||||
MHD_socket_close_ (fd);
|
||||
MHD_socket_close_chk_ (fd);
|
||||
if (cbc.pos != strlen ("/hello_world"))
|
||||
return 8192;
|
||||
if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world")))
|
||||
|
||||
Reference in New Issue
Block a user