mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-09-25 04:09:31 +03:00
Improved use of SO_NOSIGPIPE
This commit is contained in:
@@ -675,9 +675,9 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon,
|
||||
#else /* MHD_SOCKETS_KIND_WINSOCK */
|
||||
sk_spipe_supprs = true; /* Nothing to suppress on W32 */
|
||||
#endif /* MHD_SOCKETS_KIND_WINSOCK */
|
||||
#if defined(MHD_socket_nosignal_)
|
||||
#if defined(mhd_socket_nosignal)
|
||||
if (! sk_spipe_supprs)
|
||||
sk_spipe_supprs = MHD_socket_nosignal_ (client_socket);
|
||||
sk_spipe_supprs = mhd_socket_nosignal (client_socket);
|
||||
if (! sk_spipe_supprs)
|
||||
{
|
||||
mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED, \
|
||||
@@ -694,7 +694,7 @@ MHD_daemon_add_connection (struct MHD_Daemon *daemon,
|
||||
}
|
||||
#endif /* HAVE_DCLR_MSG_NOSIGNAL */
|
||||
}
|
||||
#endif /* MHD_socket_nosignal_ */
|
||||
#endif /* mhd_socket_nosignal */
|
||||
|
||||
if (1) // TODO: implement turbo
|
||||
{
|
||||
@@ -950,8 +950,8 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon)
|
||||
"socket.");
|
||||
}
|
||||
|
||||
#if defined(MHD_socket_nosignal_)
|
||||
if (! sk_spipe_supprs && ! MHD_socket_nosignal_ (s))
|
||||
#if defined(mhd_socket_nosignal)
|
||||
if (! sk_spipe_supprs && ! mhd_socket_nosignal (s))
|
||||
{
|
||||
mhd_LOG_MSG (daemon, MHD_SC_ACCEPT_CONFIGURE_NOSIGPIPE_FAILED,
|
||||
"Failed to suppress SIGPIPE on incoming connection " \
|
||||
@@ -968,7 +968,7 @@ mhd_daemon_accept_connection (struct MHD_Daemon *restrict daemon)
|
||||
}
|
||||
else
|
||||
sk_spipe_supprs = true;
|
||||
#endif /* MHD_socket_nosignal_ */
|
||||
#endif /* mhd_socket_nosignal */
|
||||
return (MHD_SC_OK == internal_add_connection (daemon,
|
||||
s,
|
||||
&addrstorage,
|
||||
|
||||
@@ -329,30 +329,4 @@
|
||||
/* mhd_socket_pair() implemented in "mhd_sockets_funcs.h" based on local function */
|
||||
#endif
|
||||
|
||||
#if defined(SOL_SOCKET) && defined(SO_NOSIGPIPE)
|
||||
/**
|
||||
* Helper for mhd_socket_nosignal()
|
||||
*/
|
||||
# ifdef HAVE_COMPOUND_LITERALS_LVALUES
|
||||
# define mhd_socket_nosig_helper_int_one ((int){1})
|
||||
# else
|
||||
/**
|
||||
* Internal static const helper for mhd_socket_nosignal()
|
||||
*/
|
||||
static const int mhd_socket_nosig_helper_int_one = 1;
|
||||
# endif
|
||||
|
||||
|
||||
/**
|
||||
* Change socket options to no signal on remote disconnect / broken connection.
|
||||
*
|
||||
* @param sock socket to manipulate
|
||||
* @return non-zero if succeeded, zero otherwise
|
||||
*/
|
||||
# define mhd_socket_nosignal(sock) \
|
||||
(! setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE, \
|
||||
&mhd_socket_nosig_helper_int_one, sizeof(int)))
|
||||
#endif /* SOL_SOCKET && SO_NOSIGPIPE */
|
||||
|
||||
|
||||
#endif /* ! MHD_SOCKETS_MACROS_H */
|
||||
|
||||
@@ -189,25 +189,41 @@ typedef int mhd_SCKT_SEND_SIZE;
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(MHD_socket_nosignal_) || \
|
||||
(defined(SOL_SOCKET) && defined(SO_NOSIGPIPE))
|
||||
#if defined(HAVE_DCLR_SOL_SOCKET) && defined(HAVE_DCLR_SO_NOSIGPIPE)
|
||||
/**
|
||||
* Helper for mhd_socket_nosignal()
|
||||
*/
|
||||
# ifdef HAVE_COMPOUND_LITERALS_LVALUES
|
||||
# define mhd_socket_nosig_helper_int_one ((mhd_SCKT_OPT_BOOL){1})
|
||||
# else
|
||||
/**
|
||||
* Internal static const helper for mhd_socket_nosignal()
|
||||
*/
|
||||
static const mhd_SCKT_OPT_BOOL mhd_socket_nosig_helper_int_one = 1;
|
||||
# endif
|
||||
|
||||
/**
|
||||
* Change socket options to no signal on remote disconnect / broken connection.
|
||||
*
|
||||
* @param sock socket to manipulate
|
||||
* @return non-zero if succeeded, zero otherwise
|
||||
*/
|
||||
# define mhd_socket_nosignal(sock) \
|
||||
(! setsockopt ((sock),SOL_SOCKET,SO_NOSIGPIPE, \
|
||||
&mhd_socket_nosig_helper_int_one, \
|
||||
sizeof(mhd_SCKT_OPT_BOOL)))
|
||||
#endif /* SOL_SOCKET && SO_NOSIGPIPE */
|
||||
|
||||
|
||||
#if defined(mhd_socket_nosignal) || defined(HAVE_DCLR_MSG_NOSIGNAL)
|
||||
/**
|
||||
* Indicate that SIGPIPE can be suppressed by MHD for normal send() by flags
|
||||
* or socket options.
|
||||
* If this macro is undefined, MHD cannot suppress SIGPIPE for socket functions
|
||||
* so sendfile() or writev() calls are avoided in application threads.
|
||||
* so application need to handle SIGPIPE.
|
||||
*/
|
||||
# define mhd_SEND_SPIPE_SUPPRESS_POSSIBLE 1
|
||||
#endif /* MHD_SOCKETS_KIND_WINSOCK || MHD_socket_nosignal_ || MSG_NOSIGNAL */
|
||||
|
||||
|
||||
#if ! defined(MHD_SOCKETS_KIND_WINSOCK)
|
||||
/**
|
||||
* Indicate that suppression of SIGPIPE is required for some network
|
||||
* system calls.
|
||||
*/
|
||||
# define mhd_SEND_SPIPE_SUPPRESS_NEEDED 1
|
||||
#endif
|
||||
#endif /* mhd_socket_nosignal || HAVE_DCLR_MSG_NOSIGNAL */
|
||||
|
||||
|
||||
#endif /* ! MHD_SYS_SOCKETS_HEADERS_H */
|
||||
|
||||
Reference in New Issue
Block a user