diff --git a/CMakeLists.txt b/CMakeLists.txt index 6db68a49..567b3ba7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -294,6 +294,14 @@ endif() # configuration-specific source files + +# we don't check for win32 as on win32 socket operations are handled directly through return values +# Check if SO_NOSIGPIPE exists +check_symbol_exists(SO_NOSIGPIPE "sys/socket.h" HAVE_SO_NOSIGPIPE) + +# Check if MSG_NOSIGNAL exists +check_symbol_exists(MSG_NOSIGNAL "sys/socket.h" HAVE_MSG_NOSIGNAL) + if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") set(SUPPORT_ABSTRACT_SOCKET_NAMES TRUE) list(APPEND STUMPLESS_SOURCES ${PROJECT_SOURCE_DIR}/src/config/abstract_socket_names_supported.c) diff --git a/include/private/config.h.in b/include/private/config.h.in index 60f25ce6..a6d96d26 100644 --- a/include/private/config.h.in +++ b/include/private/config.h.in @@ -43,6 +43,9 @@ #cmakedefine HAVE_VSNPRINTF_S 1 #cmakedefine HAVE_WCSRTOMBS_S 1 #cmakedefine HAVE_WCSTOMBS_S 1 +#cmakedefine HAVE_SO_NOSIGPIPE 1 +#cmakedefine HAVE_MSG_NOSIGNAL 1 + /* function support checks */ #cmakedefine SUPPORT_ABSTRACT_SOCKET_NAMES 1 diff --git a/include/private/config/have_sys_socket.h b/include/private/config/have_sys_socket.h index ea6c2bd0..00fe89be 100644 --- a/include/private/config/have_sys_socket.h +++ b/include/private/config/have_sys_socket.h @@ -20,8 +20,15 @@ # define __STUMPLESS_PRIVATE_CONFIG_HAVE_SYS_SOCKET_H # include +# include # include "private/target/network.h" +# ifdef HAVE_SO_NOSIGPIPE +# define config_disallow_signal_during_sending_flag SO_NOSIGPIPE +# elif defined(HAVE_MSG_NOSIGNAL) +# define config_disallow_signal_during_sending_flag MSG_NOSIGNAL +# endif + void sys_socket_close_network_target( const struct network_target *target ); diff --git a/src/config/have_sys_socket.c b/src/config/have_sys_socket.c index e7bba5cc..268abf57 100644 --- a/src/config/have_sys_socket.c +++ b/src/config/have_sys_socket.c @@ -204,7 +204,7 @@ sys_socket_sendto_tcp_target( struct network_target *target, send_result = send( target->handle, msg, msg_size - sent_bytes, - MSG_NOSIGNAL ); + config_disallow_signal_during_sending_flag ); if( unlikely( send_result == -1 ) ){ raise_socket_send_failure( L10N_SEND_SYS_SOCKET_FAILED_ERROR_MESSAGE, @@ -231,7 +231,7 @@ sys_socket_sendto_udp_target( const struct network_target *target, send_result = send( target->handle, msg, msg_size, - MSG_NOSIGNAL ); + config_disallow_signal_during_sending_flag ); if( unlikely( send_result == -1 ) ){ unlock_network_target( target );