mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-10-08 23:43:54 +03:00
Implement MHD_socket, MHD_INVALID_SOCKET
This commit is contained in:
1 parent
cc5f66001e
commit
c311027f28
28 files changed
+161
-116
No files matched your search
@@ -705,7 +705,7 @@ main (int argc, char *const *argv)
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
MHD_UNSIGNED_LONG_LONG mhd_timeout;
|
||||
|
||||
if (argc != 2)
|
||||
|
||||
+27
-10
@@ -105,12 +105,12 @@ extern "C"
|
||||
"standard" includes won't be used (which might be a good
|
||||
idea, especially on platforms where they do not exist). */
|
||||
#ifndef MHD_PLATFORM_H
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#ifdef __MINGW32__
|
||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -160,6 +160,23 @@ extern "C"
|
||||
#define _MHD_EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifndef MHD_SOCKET_DEFINED
|
||||
/**
|
||||
* MHD_socket is type for socket FDs
|
||||
*/
|
||||
#if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
|
||||
#define MHD_POSIX_SOCKETS 1
|
||||
typedef int MHD_socket;
|
||||
#define MHD_INVALID_SOCKET (-1)
|
||||
#else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
|
||||
#define MHD_WINSOCK_SOCKETS 1
|
||||
#include <winsock2.h>
|
||||
typedef SOCKET MHD_socket;
|
||||
#define MHD_INVALID_SOCKET (INVALID_SOCKET)
|
||||
#endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
|
||||
#define MHD_SOCKET_DEFINED 1
|
||||
#endif /* MHD_SOCKET_DEFINED */
|
||||
|
||||
/**
|
||||
* Not all architectures and `printf()`'s support the `long long` type.
|
||||
* This gives the ability to replace `long long` with just a `long`,
|
||||
@@ -948,7 +965,7 @@ union MHD_ConnectionInfo
|
||||
/**
|
||||
* Connect socket
|
||||
*/
|
||||
int connect_fd;
|
||||
MHD_socket connect_fd;
|
||||
|
||||
/**
|
||||
* GNUtls session handle, of type "gnutls_session_t".
|
||||
@@ -1335,14 +1352,14 @@ MHD_start_daemon (unsigned int flags,
|
||||
* Note that some thread modes require the caller to have passed
|
||||
* #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is
|
||||
* in one of those modes and this option was not given to
|
||||
* #MHD_start_daemon, this function will return -1.
|
||||
* #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
|
||||
*
|
||||
* @param daemon daemon to stop accepting new connections for
|
||||
* @return old listen socket on success, -1 if the daemon was
|
||||
* already not listening anymore
|
||||
* @return old listen socket on success, #MHD_INVALID_SOCKET if
|
||||
* the daemon was already not listening anymore
|
||||
* @ingroup specialized
|
||||
*/
|
||||
_MHD_EXTERN int
|
||||
_MHD_EXTERN MHD_socket
|
||||
MHD_quiesce_daemon (struct MHD_Daemon *daemon);
|
||||
|
||||
|
||||
@@ -1387,7 +1404,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon);
|
||||
*/
|
||||
_MHD_EXTERN int
|
||||
MHD_add_connection (struct MHD_Daemon *daemon,
|
||||
int client_socket,
|
||||
MHD_socket client_socket,
|
||||
const struct sockaddr *addr,
|
||||
socklen_t addrlen);
|
||||
|
||||
@@ -1414,7 +1431,7 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
|
||||
fd_set *read_fd_set,
|
||||
fd_set *write_fd_set,
|
||||
fd_set *except_fd_set,
|
||||
int *max_fd);
|
||||
MHD_socket *max_fd);
|
||||
|
||||
|
||||
/**
|
||||
@@ -2224,7 +2241,7 @@ union MHD_DaemonInfo
|
||||
/**
|
||||
* Listen socket file descriptor
|
||||
*/
|
||||
int listen_fd;
|
||||
MHD_socket listen_fd;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -118,4 +118,21 @@
|
||||
|
||||
#include <plibc.h>
|
||||
|
||||
#ifndef MHD_SOCKET_DEFINED
|
||||
/**
|
||||
* MHD_socket is type for socket FDs
|
||||
*/
|
||||
#if !defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
|
||||
#define MHD_POSIX_SOCKETS 1
|
||||
typedef int MHD_socket;
|
||||
#define MHD_INVALID_SOCKET (-1)
|
||||
#else /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
|
||||
#define MHD_WINSOCK_SOCKETS 1
|
||||
#include <winsock2.h>
|
||||
typedef SOCKET MHD_socket;
|
||||
#define MHD_INVALID_SOCKET (INVALID_SOCKET)
|
||||
#endif /* !defined(_WIN32) || defined(_SYS_TYPES_FD_SET) */
|
||||
#define MHD_SOCKET_DEFINED 1
|
||||
#endif /* MHD_SOCKET_DEFINED */
|
||||
|
||||
#endif
|
||||
@@ -338,7 +338,7 @@ try_ready_normal_body (struct MHD_Connection *connection)
|
||||
connection->response_write_position) )
|
||||
return MHD_YES; /* response already ready */
|
||||
#if LINUX
|
||||
if ( (-1 != response->fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != response->fd) &&
|
||||
(0 == (connection->daemon->options & MHD_USE_SSL)) )
|
||||
{
|
||||
/* will use sendfile, no need to bother response crc */
|
||||
|
||||
+80
-71
@@ -554,13 +554,13 @@ MHD_TLS_init (struct MHD_Daemon *daemon)
|
||||
* @param max_fd maximum value to potentially update
|
||||
*/
|
||||
static void
|
||||
add_to_fd_set (int fd,
|
||||
add_to_fd_set (MHD_socket fd,
|
||||
fd_set *set,
|
||||
int *max_fd)
|
||||
MHD_socket *max_fd)
|
||||
{
|
||||
FD_SET (fd, set);
|
||||
if ( (NULL != max_fd) &&
|
||||
(fd > *max_fd) )
|
||||
if ( (NULL != max_fd) && (MHD_INVALID_SOCKET != fd) &&
|
||||
((fd > *max_fd) || (MHD_INVALID_SOCKET == *max_fd)) )
|
||||
*max_fd = fd;
|
||||
}
|
||||
|
||||
@@ -587,10 +587,10 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
|
||||
fd_set *read_fd_set,
|
||||
fd_set *write_fd_set,
|
||||
fd_set *except_fd_set,
|
||||
int *max_fd)
|
||||
MHD_socket *max_fd)
|
||||
{
|
||||
struct MHD_Connection *pos;
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
|
||||
if ( (NULL == daemon)
|
||||
|| (NULL == read_fd_set)
|
||||
@@ -615,11 +615,12 @@ MHD_get_fdset (struct MHD_Daemon *daemon,
|
||||
}
|
||||
#endif
|
||||
fd = daemon->socket_fd;
|
||||
if (-1 != fd)
|
||||
if (MHD_INVALID_SOCKET != fd)
|
||||
{
|
||||
FD_SET (fd, read_fd_set);
|
||||
/* update max file descriptor */
|
||||
if ( (NULL != max_fd) && ((*max_fd) < fd))
|
||||
if ( (NULL != max_fd) &&
|
||||
((*max_fd) < fd || MHD_INVALID_SOCKET == (*max_fd)))
|
||||
*max_fd = fd;
|
||||
}
|
||||
for (pos = daemon->connections_head; NULL != pos; pos = pos->next)
|
||||
@@ -667,7 +668,7 @@ MHD_handle_connection (void *data)
|
||||
int num_ready;
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
struct timeval tv;
|
||||
struct timeval *tvp;
|
||||
unsigned int timeout;
|
||||
@@ -843,7 +844,7 @@ recv_param_adapter (struct MHD_Connection *connection,
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
if ( (-1 == connection->socket_fd) ||
|
||||
if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
|
||||
(MHD_CONNECTION_CLOSED == connection->state) )
|
||||
{
|
||||
errno = ENOTCONN;
|
||||
@@ -876,12 +877,12 @@ send_param_adapter (struct MHD_Connection *connection,
|
||||
{
|
||||
ssize_t ret;
|
||||
#if LINUX
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
off_t offset;
|
||||
off_t left;
|
||||
#endif
|
||||
|
||||
if ( (-1 == connection->socket_fd) ||
|
||||
if ( (MHD_INVALID_SOCKET == connection->socket_fd) ||
|
||||
(MHD_CONNECTION_CLOSED == connection->state) )
|
||||
{
|
||||
errno = ENOTCONN;
|
||||
@@ -893,7 +894,7 @@ send_param_adapter (struct MHD_Connection *connection,
|
||||
if ( (connection->write_buffer_append_offset ==
|
||||
connection->write_buffer_send_offset) &&
|
||||
(NULL != connection->response) &&
|
||||
(-1 != (fd = connection->response->fd)) )
|
||||
(MHD_INVALID_SOCKET != (fd = connection->response->fd)) )
|
||||
{
|
||||
/* can use sendfile */
|
||||
offset = (off_t) connection->response_write_position + connection->response->fd_off;
|
||||
@@ -1027,7 +1028,7 @@ create_thread (pthread_t *thread,
|
||||
*/
|
||||
static int
|
||||
internal_add_connection (struct MHD_Daemon *daemon,
|
||||
int client_socket,
|
||||
MHD_socket client_socket,
|
||||
const struct sockaddr *addr,
|
||||
socklen_t addrlen,
|
||||
int external_add)
|
||||
@@ -1572,7 +1573,7 @@ resume_suspended_connections (struct MHD_Daemon *daemon)
|
||||
*/
|
||||
static void
|
||||
make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
|
||||
int sock)
|
||||
MHD_socket sock)
|
||||
{
|
||||
#ifdef WINDOWS
|
||||
DWORD dwFlags;
|
||||
@@ -1652,7 +1653,7 @@ make_nonblocking_noninheritable (struct MHD_Daemon *daemon,
|
||||
*/
|
||||
int
|
||||
MHD_add_connection (struct MHD_Daemon *daemon,
|
||||
int client_socket,
|
||||
MHD_socket client_socket,
|
||||
const struct sockaddr *addr,
|
||||
socklen_t addrlen)
|
||||
{
|
||||
@@ -1687,13 +1688,13 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
|
||||
#endif
|
||||
struct sockaddr *addr = (struct sockaddr *) &addrstorage;
|
||||
socklen_t addrlen;
|
||||
int s;
|
||||
int fd;
|
||||
MHD_socket s;
|
||||
MHD_socket fd;
|
||||
int nonblock;
|
||||
|
||||
addrlen = sizeof (addrstorage);
|
||||
memset (addr, 0, sizeof (addrstorage));
|
||||
if (-1 == (fd = daemon->socket_fd))
|
||||
if (MHD_INVALID_SOCKET == (fd = daemon->socket_fd))
|
||||
return MHD_NO;
|
||||
#ifdef HAVE_SOCK_NONBLOCK
|
||||
nonblock = SOCK_NONBLOCK;
|
||||
@@ -1709,7 +1710,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
|
||||
#else
|
||||
s = ACCEPT (fd, addr, &addrlen);
|
||||
#endif
|
||||
if ((-1 == s) || (addrlen <= 0))
|
||||
if ((MHD_INVALID_SOCKET == s) || (addrlen <= 0))
|
||||
{
|
||||
#if HAVE_MESSAGES
|
||||
/* This could be a common occurance with multiple worker threads */
|
||||
@@ -1718,7 +1719,7 @@ MHD_accept_connection (struct MHD_Daemon *daemon)
|
||||
"Error accepting connection: %s\n",
|
||||
STRERROR (errno));
|
||||
#endif
|
||||
if (-1 != s)
|
||||
if (MHD_INVALID_SOCKET != s)
|
||||
{
|
||||
if (0 != CLOSE (s))
|
||||
MHD_PANIC ("close failed\n");
|
||||
@@ -1788,7 +1789,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
|
||||
pos->epoll_state &= ~MHD_EPOLL_STATE_IN_EREADY_EDLL;
|
||||
}
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
|
||||
(-1 != daemon->epoll_fd) &&
|
||||
(MHD_INVALID_SOCKET != daemon->epoll_fd) &&
|
||||
(0 != (pos->epoll_state & MHD_EPOLL_STATE_IN_EPOLL_SET)) )
|
||||
{
|
||||
/* epoll documentation suggests that closing a FD
|
||||
@@ -1810,7 +1811,7 @@ MHD_cleanup_connections (struct MHD_Daemon *daemon)
|
||||
MHD_destroy_response (pos->response);
|
||||
pos->response = NULL;
|
||||
}
|
||||
if (-1 != pos->socket_fd)
|
||||
if (MHD_INVALID_SOCKET != pos->socket_fd)
|
||||
{
|
||||
#ifdef WINDOWS
|
||||
SHUTDOWN (pos->socket_fd, SHUT_WR);
|
||||
@@ -1939,7 +1940,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
|
||||
const fd_set *write_fd_set,
|
||||
const fd_set *except_fd_set)
|
||||
{
|
||||
int ds;
|
||||
MHD_socket ds;
|
||||
char tmp;
|
||||
struct MHD_Connection *pos;
|
||||
struct MHD_Connection *next;
|
||||
@@ -1958,7 +1959,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
|
||||
#endif
|
||||
|
||||
/* select connection thread handling type */
|
||||
if ( (-1 != (ds = daemon->socket_fd)) &&
|
||||
if ( (MHD_INVALID_SOCKET != (ds = daemon->socket_fd)) &&
|
||||
(FD_ISSET (ds, read_fd_set)) )
|
||||
(void) MHD_accept_connection (daemon);
|
||||
/* drain signaling pipe to avoid spinning select */
|
||||
@@ -1974,7 +1975,7 @@ MHD_run_from_select (struct MHD_Daemon *daemon,
|
||||
{
|
||||
next = pos->next;
|
||||
ds = pos->socket_fd;
|
||||
if (-1 == ds)
|
||||
if (MHD_INVALID_SOCKET == ds)
|
||||
continue;
|
||||
switch (pos->event_loop_info)
|
||||
{
|
||||
@@ -2026,7 +2027,7 @@ MHD_select (struct MHD_Daemon *daemon,
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
struct timeval timeout;
|
||||
struct timeval *tv;
|
||||
MHD_UNSIGNED_LONG_LONG ltimeout;
|
||||
@@ -2038,7 +2039,7 @@ MHD_select (struct MHD_Daemon *daemon,
|
||||
FD_ZERO (&rs);
|
||||
FD_ZERO (&ws);
|
||||
FD_ZERO (&es);
|
||||
max = -1;
|
||||
max = MHD_INVALID_SOCKET;
|
||||
if (0 == (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
|
||||
{
|
||||
if (MHD_USE_SUSPEND_RESUME == (daemon->options & MHD_USE_SUSPEND_RESUME))
|
||||
@@ -2051,13 +2052,13 @@ MHD_select (struct MHD_Daemon *daemon,
|
||||
/* If we're at the connection limit, no need to
|
||||
accept new connections. */
|
||||
if ( (0 == daemon->max_connections) &&
|
||||
(-1 != daemon->socket_fd) )
|
||||
(MHD_INVALID_SOCKET != daemon->socket_fd) )
|
||||
FD_CLR (daemon->socket_fd, &rs);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* accept only, have one thread per connection */
|
||||
if (-1 != daemon->socket_fd)
|
||||
if (MHD_INVALID_SOCKET != daemon->socket_fd)
|
||||
{
|
||||
max = daemon->socket_fd;
|
||||
FD_SET (daemon->socket_fd, &rs);
|
||||
@@ -2067,7 +2068,7 @@ MHD_select (struct MHD_Daemon *daemon,
|
||||
{
|
||||
FD_SET (daemon->wpipe[0], &rs);
|
||||
/* update max file descriptor */
|
||||
if (max < daemon->wpipe[0])
|
||||
if (max < daemon->wpipe[0] || max == MHD_INVALID_SOCKET)
|
||||
max = daemon->wpipe[0];
|
||||
}
|
||||
|
||||
@@ -2086,7 +2087,7 @@ MHD_select (struct MHD_Daemon *daemon,
|
||||
timeout.tv_sec = ltimeout / 1000;
|
||||
tv = &timeout;
|
||||
}
|
||||
if (-1 == max)
|
||||
if (MHD_INVALID_SOCKET == max)
|
||||
return MHD_YES;
|
||||
num_ready = SELECT (max + 1, &rs, &ws, &es, tv);
|
||||
if (MHD_YES == daemon->shutdown)
|
||||
@@ -2139,7 +2140,7 @@ MHD_poll_all (struct MHD_Daemon *daemon,
|
||||
memset (p, 0, sizeof (p));
|
||||
poll_server = 0;
|
||||
poll_listen = -1;
|
||||
if ( (-1 != daemon->socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != daemon->socket_fd) &&
|
||||
(0 != daemon->max_connections) )
|
||||
{
|
||||
/* only listen if we are not at the connection limit */
|
||||
@@ -2275,7 +2276,7 @@ MHD_poll_listen_socket (struct MHD_Daemon *daemon,
|
||||
memset (&p, 0, sizeof (p));
|
||||
poll_count = 0;
|
||||
poll_listen = -1;
|
||||
if (-1 != daemon->socket_fd)
|
||||
if (MHD_INVALID_SOCKET != daemon->socket_fd)
|
||||
{
|
||||
p[poll_count].fd = daemon->socket_fd;
|
||||
p[poll_count].events = POLLIN;
|
||||
@@ -2380,7 +2381,7 @@ MHD_epoll (struct MHD_Daemon *daemon,
|
||||
return MHD_NO; /* we're down! */
|
||||
if (MHD_YES == daemon->shutdown)
|
||||
return MHD_NO;
|
||||
if ( (-1 != daemon->socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != daemon->socket_fd) &&
|
||||
(0 != daemon->max_connections) &&
|
||||
(MHD_NO == daemon->listen_socket_in_epoll) )
|
||||
{
|
||||
@@ -2675,22 +2676,22 @@ MHD_start_daemon (unsigned int flags,
|
||||
* Note that some thread modes require the caller to have passed
|
||||
* #MHD_USE_PIPE_FOR_SHUTDOWN when using this API. If this daemon is
|
||||
* in one of those modes and this option was not given to
|
||||
* #MHD_start_daemon, this function will return -1.
|
||||
* #MHD_start_daemon, this function will return #MHD_INVALID_SOCKET.
|
||||
*
|
||||
* @param daemon daemon to stop accepting new connections for
|
||||
* @return old listen socket on success, -1 if the daemon was
|
||||
* already not listening anymore
|
||||
* @return old listen socket on success, #MHD_INVALID_SOCKET if
|
||||
* the daemon was already not listening anymore
|
||||
* @ingroup specialized
|
||||
*/
|
||||
int
|
||||
MHD_socket
|
||||
MHD_quiesce_daemon (struct MHD_Daemon *daemon)
|
||||
{
|
||||
unsigned int i;
|
||||
int ret;
|
||||
MHD_socket ret;
|
||||
|
||||
ret = daemon->socket_fd;
|
||||
if (-1 == ret)
|
||||
return -1;
|
||||
if (MHD_INVALID_SOCKET == ret)
|
||||
return MHD_INVALID_SOCKET;
|
||||
if ( (-1 == daemon->wpipe[1]) &&
|
||||
(0 != (daemon->options & MHD_USE_SELECT_INTERNALLY)) )
|
||||
{
|
||||
@@ -2698,13 +2699,13 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
|
||||
MHD_DLOG (daemon,
|
||||
"Using MHD_quiesce_daemon in this mode requires MHD_USE_PIPE_FOR_SHUTDOWN\n");
|
||||
#endif
|
||||
return -1;
|
||||
return MHD_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (NULL != daemon->worker_pool)
|
||||
for (i = 0; i < daemon->worker_pool_size; i++)
|
||||
{
|
||||
daemon->worker_pool[i].socket_fd = -1;
|
||||
daemon->worker_pool[i].socket_fd = MHD_INVALID_SOCKET;
|
||||
#if EPOLL_SUPPORT
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
|
||||
(-1 != daemon->worker_pool[i].epoll_fd) &&
|
||||
@@ -2719,7 +2720,7 @@ MHD_quiesce_daemon (struct MHD_Daemon *daemon)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
daemon->socket_fd = -1;
|
||||
daemon->socket_fd = MHD_INVALID_SOCKET;
|
||||
#if EPOLL_SUPPORT
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
|
||||
(-1 != daemon->epoll_fd) &&
|
||||
@@ -2928,7 +2929,7 @@ parse_options_va (struct MHD_Daemon *daemon,
|
||||
break;
|
||||
#endif
|
||||
case MHD_OPTION_LISTEN_SOCKET:
|
||||
daemon->socket_fd = va_arg (ap, int);
|
||||
daemon->socket_fd = va_arg (ap, MHD_socket);
|
||||
break;
|
||||
case MHD_OPTION_EXTERNAL_LOGGER:
|
||||
#if HAVE_MESSAGES
|
||||
@@ -2974,9 +2975,8 @@ parse_options_va (struct MHD_Daemon *daemon,
|
||||
MHD_OPTION_END))
|
||||
return MHD_NO;
|
||||
break;
|
||||
/* all options taking 'int' or 'enum' */
|
||||
/* all options taking 'enum' */
|
||||
case MHD_OPTION_HTTPS_CRED_TYPE:
|
||||
case MHD_OPTION_LISTEN_SOCKET:
|
||||
if (MHD_YES != parse_options (daemon,
|
||||
servaddr,
|
||||
opt,
|
||||
@@ -2984,6 +2984,15 @@ parse_options_va (struct MHD_Daemon *daemon,
|
||||
MHD_OPTION_END))
|
||||
return MHD_NO;
|
||||
break;
|
||||
/* all options taking 'MHD_socket' */
|
||||
case MHD_OPTION_LISTEN_SOCKET:
|
||||
if (MHD_YES != parse_options (daemon,
|
||||
servaddr,
|
||||
opt,
|
||||
(MHD_socket) oa[i].value,
|
||||
MHD_OPTION_END))
|
||||
return MHD_NO;
|
||||
break;
|
||||
/* all options taking one pointer */
|
||||
case MHD_OPTION_SOCK_ADDR:
|
||||
case MHD_OPTION_HTTPS_MEM_KEY:
|
||||
@@ -3064,23 +3073,23 @@ parse_options_va (struct MHD_Daemon *daemon,
|
||||
* @param type socket type (usually SOCK_STREAM)
|
||||
* @param protocol desired protocol, 0 for default
|
||||
*/
|
||||
static int
|
||||
static MHD_socket
|
||||
create_socket (struct MHD_Daemon *daemon,
|
||||
int domain, int type, int protocol)
|
||||
{
|
||||
int ctype = type | SOCK_CLOEXEC;
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
|
||||
/* use SOCK_STREAM rather than ai_socktype: some getaddrinfo
|
||||
* implementations do not set ai_socktype, e.g. RHL6.2. */
|
||||
fd = SOCKET (domain, ctype, protocol);
|
||||
if ( (-1 == fd) && (EINVAL == errno) && (0 != SOCK_CLOEXEC) )
|
||||
if ( (MHD_INVALID_SOCKET == fd) && (EINVAL == errno) && (0 != SOCK_CLOEXEC) )
|
||||
{
|
||||
ctype = type;
|
||||
fd = SOCKET(domain, type, protocol);
|
||||
}
|
||||
if (-1 == fd)
|
||||
return -1;
|
||||
if (MHD_INVALID_SOCKET == fd)
|
||||
return MHD_INVALID_SOCKET;
|
||||
if (type == ctype)
|
||||
make_nonblocking_noninheritable (daemon, fd);
|
||||
return fd;
|
||||
@@ -3114,7 +3123,7 @@ setup_epoll_to_listen (struct MHD_Daemon *daemon)
|
||||
if (0 == EPOLL_CLOEXEC)
|
||||
make_nonblocking_noninheritable (daemon,
|
||||
daemon->epoll_fd);
|
||||
if (-1 == daemon->socket_fd)
|
||||
if (MHD_INVALID_SOCKET == daemon->socket_fd)
|
||||
return MHD_YES; /* non-listening daemon */
|
||||
event.events = EPOLLIN;
|
||||
event.data.ptr = daemon;
|
||||
@@ -3184,7 +3193,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
{
|
||||
const int on = 1;
|
||||
struct MHD_Daemon *daemon;
|
||||
int socket_fd;
|
||||
MHD_socket socket_fd;
|
||||
struct sockaddr_in servaddr4;
|
||||
#if HAVE_INET6
|
||||
struct sockaddr_in6 servaddr6;
|
||||
@@ -3224,7 +3233,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
NULL);
|
||||
}
|
||||
#endif
|
||||
daemon->socket_fd = -1;
|
||||
daemon->socket_fd = MHD_INVALID_SOCKET;
|
||||
daemon->options = (enum MHD_OPTION) flags;
|
||||
#if WINDOWS
|
||||
/* Winsock is broken with respect to 'shutdown';
|
||||
@@ -3417,7 +3426,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
goto free_and_fail;
|
||||
}
|
||||
#endif
|
||||
if ( (-1 == daemon->socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET == daemon->socket_fd) &&
|
||||
(0 == (daemon->options & MHD_USE_NO_LISTEN_SOCKET)) )
|
||||
{
|
||||
/* try to open listen socket */
|
||||
@@ -3427,7 +3436,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
else
|
||||
socket_fd = create_socket (daemon,
|
||||
PF_INET, SOCK_STREAM, 0);
|
||||
if (-1 == socket_fd)
|
||||
if (MHD_INVALID_SOCKET == socket_fd)
|
||||
{
|
||||
#if HAVE_MESSAGES
|
||||
if (0 != (flags & MHD_USE_DEBUG))
|
||||
@@ -3582,7 +3591,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
MHD_DLOG (daemon,
|
||||
"MHD failed to initialize IP connection limit mutex\n");
|
||||
#endif
|
||||
if ( (-1 != socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != socket_fd) &&
|
||||
(0 != CLOSE (socket_fd)) )
|
||||
MHD_PANIC ("close failed\n");
|
||||
goto free_and_fail;
|
||||
@@ -3594,7 +3603,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
"MHD failed to initialize IP connection limit mutex\n");
|
||||
#endif
|
||||
pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
|
||||
if ( (-1 != socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != socket_fd) &&
|
||||
(0 != CLOSE (socket_fd)) )
|
||||
MHD_PANIC ("close failed\n");
|
||||
goto free_and_fail;
|
||||
@@ -3608,7 +3617,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
MHD_DLOG (daemon,
|
||||
"Failed to initialize TLS support\n");
|
||||
#endif
|
||||
if ( (-1 != socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != socket_fd) &&
|
||||
(0 != CLOSE (socket_fd)) )
|
||||
MHD_PANIC ("close failed\n");
|
||||
pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
|
||||
@@ -3630,7 +3639,7 @@ MHD_start_daemon_va (unsigned int flags,
|
||||
#endif
|
||||
pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
|
||||
pthread_mutex_destroy (&daemon->per_ip_connection_mutex);
|
||||
if ( (-1 != socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != socket_fd) &&
|
||||
(0 != CLOSE (socket_fd)) )
|
||||
MHD_PANIC ("close failed\n");
|
||||
goto free_and_fail;
|
||||
@@ -3773,7 +3782,7 @@ thread_failed:
|
||||
MHD_USE_SELECT_INTERNALLY mode. */
|
||||
if (0 == i)
|
||||
{
|
||||
if ( (-1 != socket_fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != socket_fd) &&
|
||||
(0 != CLOSE (socket_fd)) )
|
||||
MHD_PANIC ("close failed\n");
|
||||
pthread_mutex_destroy (&daemon->cleanup_connection_mutex);
|
||||
@@ -3923,7 +3932,7 @@ void
|
||||
MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
{
|
||||
void *unused;
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
unsigned int i;
|
||||
int rc;
|
||||
|
||||
@@ -3931,7 +3940,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
return;
|
||||
daemon->shutdown = MHD_YES;
|
||||
fd = daemon->socket_fd;
|
||||
daemon->socket_fd = -1;
|
||||
daemon->socket_fd = MHD_INVALID_SOCKET;
|
||||
/* Prepare workers for shutdown */
|
||||
if (NULL != daemon->worker_pool)
|
||||
{
|
||||
@@ -3939,11 +3948,11 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
for (i = 0; i < daemon->worker_pool_size; ++i)
|
||||
{
|
||||
daemon->worker_pool[i].shutdown = MHD_YES;
|
||||
daemon->worker_pool[i].socket_fd = -1;
|
||||
daemon->worker_pool[i].socket_fd = MHD_INVALID_SOCKET;
|
||||
#if EPOLL_SUPPORT
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
|
||||
(-1 != daemon->worker_pool[i].epoll_fd) &&
|
||||
(-1 == fd) )
|
||||
(MHD_INVALID_SOCKET == fd) )
|
||||
epoll_shutdown (&daemon->worker_pool[i]);
|
||||
#endif
|
||||
}
|
||||
@@ -3956,15 +3965,15 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
#ifdef HAVE_LISTEN_SHUTDOWN
|
||||
else
|
||||
{
|
||||
/* fd might be -1 here due to 'MHD_quiesce_daemon' */
|
||||
if (-1 != fd)
|
||||
/* fd might be MHD_INVALID_SOCKET here due to 'MHD_quiesce_daemon' */
|
||||
if (MHD_INVALID_SOCKET != fd)
|
||||
(void) SHUTDOWN (fd, SHUT_RDWR);
|
||||
}
|
||||
#endif
|
||||
#if EPOLL_SUPPORT
|
||||
if ( (0 != (daemon->options & MHD_USE_EPOLL_LINUX_ONLY)) &&
|
||||
(-1 != daemon->epoll_fd) &&
|
||||
(-1 == fd) )
|
||||
(MHD_INVALID_SOCKET == fd) )
|
||||
epoll_shutdown (daemon);
|
||||
#endif
|
||||
|
||||
@@ -4022,7 +4031,7 @@ MHD_stop_daemon (struct MHD_Daemon *daemon)
|
||||
}
|
||||
}
|
||||
close_all_connections (daemon);
|
||||
if ( (-1 != fd) &&
|
||||
if ( (MHD_INVALID_SOCKET != fd) &&
|
||||
(0 != CLOSE (fd)) )
|
||||
MHD_PANIC ("close failed\n");
|
||||
|
||||
|
||||
@@ -711,11 +711,11 @@ struct MHD_Connection
|
||||
int client_aware;
|
||||
|
||||
/**
|
||||
* Socket for this connection. Set to -1 if
|
||||
* Socket for this connection. Set to MHD_INVALID_SOCKET if
|
||||
* this connection has died (daemon should clean
|
||||
* up in that case).
|
||||
*/
|
||||
int socket_fd;
|
||||
MHD_socket socket_fd;
|
||||
|
||||
/**
|
||||
* Has this socket been closed for reading (i.e. other side closed
|
||||
@@ -1082,7 +1082,7 @@ struct MHD_Daemon
|
||||
/**
|
||||
* Listen socket.
|
||||
*/
|
||||
int socket_fd;
|
||||
MHD_socket socket_fd;
|
||||
|
||||
#if EPOLL_SUPPORT
|
||||
/**
|
||||
|
||||
@@ -241,7 +241,7 @@ MHD_create_response_from_callback (uint64_t size,
|
||||
if (NULL == (response = malloc (sizeof (struct MHD_Response) + block_size)))
|
||||
return NULL;
|
||||
memset (response, 0, sizeof (struct MHD_Response));
|
||||
response->fd = -1;
|
||||
response->fd = MHD_INVALID_SOCKET;
|
||||
response->data = (void *) &response[1];
|
||||
response->data_buffer_size = block_size;
|
||||
if (0 != pthread_mutex_init (&response->mutex, NULL))
|
||||
@@ -296,7 +296,7 @@ free_callback (void *cls)
|
||||
struct MHD_Response *response = cls;
|
||||
|
||||
(void) close (response->fd);
|
||||
response->fd = -1;
|
||||
response->fd = MHD_INVALID_SOCKET;
|
||||
}
|
||||
|
||||
|
||||
@@ -380,7 +380,7 @@ MHD_create_response_from_data (size_t size,
|
||||
if (NULL == (response = malloc (sizeof (struct MHD_Response))))
|
||||
return NULL;
|
||||
memset (response, 0, sizeof (struct MHD_Response));
|
||||
response->fd = -1;
|
||||
response->fd = MHD_INVALID_SOCKET;
|
||||
if (0 != pthread_mutex_init (&response->mutex, NULL))
|
||||
{
|
||||
free (response);
|
||||
|
||||
@@ -91,7 +91,7 @@ testExternalRun ()
|
||||
{
|
||||
struct MHD_Daemon *d;
|
||||
fd_set rs;
|
||||
int maxfd;
|
||||
MHD_socket maxfd;
|
||||
int i;
|
||||
|
||||
d = MHD_start_daemon (MHD_USE_DEBUG,
|
||||
|
||||
@@ -70,7 +70,7 @@ testInternalSelectGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -84,7 +84,7 @@ testExternalGet (int flags)
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -41,7 +41,8 @@ static const char *http_get_req = "GET / HTTP/1.1\r\n\r\n";
|
||||
static int
|
||||
test_tls_session_time_out (gnutls_session_t session)
|
||||
{
|
||||
int sd, ret;
|
||||
int ret;
|
||||
MHD_socket sd;
|
||||
struct sockaddr_in sa;
|
||||
|
||||
sd = socket (AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
@@ -46,7 +46,8 @@ static int
|
||||
test_hello_extension (gnutls_session_t session, extensions_t exten_t,
|
||||
int ext_count, int ext_length)
|
||||
{
|
||||
int i, sd, ret = 0, pos = 0;
|
||||
int i, ret = 0, pos = 0;
|
||||
MHD_socket sd;
|
||||
int exten_data_len, ciphersuite_len, datalen;
|
||||
struct sockaddr_in sa;
|
||||
char url[255];
|
||||
|
||||
@@ -361,7 +361,7 @@ testExternalGet (int port)
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -280,7 +280,7 @@ testExternalGet (int port)
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
struct timeval tv;
|
||||
MHD_UNSIGNED_LONG_LONG tt;
|
||||
int tret;
|
||||
|
||||
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
CURL *c;
|
||||
CURLM *multi;
|
||||
CURLMcode mret;
|
||||
@@ -130,7 +130,7 @@ int main(int argc, char **argv)
|
||||
extra = 10;
|
||||
while ( (c != NULL) || (--extra > 0) )
|
||||
{
|
||||
max = -1;
|
||||
max = MHD_INVALID_SOCKET;
|
||||
FD_ZERO(&ws);
|
||||
FD_ZERO(&rs);
|
||||
FD_ZERO(&es);
|
||||
|
||||
@@ -259,7 +259,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
@@ -448,7 +448,7 @@ static int
|
||||
testStopRace (int poll_flag)
|
||||
{
|
||||
struct sockaddr_in sin;
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
struct MHD_Daemon *d;
|
||||
|
||||
d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | MHD_USE_DEBUG | poll_flag,
|
||||
|
||||
@@ -284,7 +284,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -217,7 +217,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
time_t start;
|
||||
struct timeval tv;
|
||||
pid_t curl;
|
||||
|
||||
@@ -265,7 +265,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -323,7 +323,7 @@ testExternalPut ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -117,7 +117,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -319,7 +319,7 @@ testExternalPost ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -304,7 +304,7 @@ testExternalPost ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -344,7 +344,7 @@ testExternalPost ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -120,7 +120,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -298,7 +298,7 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -304,7 +304,7 @@ testExternalPut ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
|
||||
@@ -112,7 +112,7 @@ ServeOneRequest(int fd)
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
time_t start;
|
||||
struct timeval tv;
|
||||
int done = 0;
|
||||
@@ -182,7 +182,7 @@ testGet (int type, int pool_count, int poll_flag)
|
||||
char buf[2048];
|
||||
struct CBC cbc;
|
||||
CURLcode errornum;
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
|
||||
cbc.buf = buf;
|
||||
cbc.size = 2048;
|
||||
@@ -290,13 +290,13 @@ testExternalGet ()
|
||||
fd_set rs;
|
||||
fd_set ws;
|
||||
fd_set es;
|
||||
int max;
|
||||
MHD_socket max;
|
||||
int running;
|
||||
struct CURLMsg *msg;
|
||||
time_t start;
|
||||
struct timeval tv;
|
||||
int i;
|
||||
int fd;
|
||||
MHD_socket fd;
|
||||
|
||||
multi = NULL;
|
||||
cbc.buf = buf;
|
||||
@@ -384,7 +384,7 @@ testExternalGet ()
|
||||
if (i == 0) {
|
||||
/* quiesce the daemon on the 1st iteration, so the 2nd should fail */
|
||||
fd = MHD_quiesce_daemon(d);
|
||||
if (-1 == fd)
|
||||
if (MHD_INVALID_SOCKET == fd)
|
||||
abort ();
|
||||
close (fd);
|
||||
c = setupCURL (&cbc);
|
||||
|
||||
Reference in new issue
Block a user