From c459d509b7c7fe7d8200ea3791d1ef0b245126ab Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 5 Mar 2017 09:29:37 +0000 Subject: [PATCH 1/3] build: Probe MSG_DONTWAIT in the same way as MSG_NOSIGNAL Instead of the WIN32-specific workaround, detect lack of `MSG_DONTWAIT` in the build system. This allows other platforms without `MSG_DONTWAIT` to work too. --- configure.ac | 9 +++++++++ src/compat.h | 9 ++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index d25bebeb1..65f7fa073 100644 --- a/configure.ac +++ b/configure.ac @@ -558,6 +558,15 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [ AC_MSG_RESULT(no)] ) +dnl Check for MSG_DONTWAIT +AC_MSG_CHECKING(for MSG_DONTWAIT) +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], + [[ int f = MSG_DONTWAIT; ]])], + [ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_DONTWAIT, 1,[Define this symbol if you have MSG_DONTWAIT]) ], + [ AC_MSG_RESULT(no)] +) + + AC_MSG_CHECKING([for visibility attribute]) AC_LINK_IFELSE([AC_LANG_SOURCE([ int foo_def( void ) __attribute__((visibility("default"))); diff --git a/src/compat.h b/src/compat.h index 28aa77eea..6f4d4e65f 100644 --- a/src/compat.h +++ b/src/compat.h @@ -47,9 +47,7 @@ #include #endif -#ifdef WIN32 -#define MSG_DONTWAIT 0 -#else +#ifndef WIN32 typedef u_int SOCKET; #include "errno.h" #define WSAGetLastError() errno @@ -79,6 +77,11 @@ typedef u_int SOCKET; #define MSG_NOSIGNAL 0 #endif +// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0 +#if !defined(HAVE_MSG_DONTWAIT) && !defined(MSG_DONTWAIT) +#define MSG_DONTWAIT 0 +#endif + #if HAVE_DECL_STRNLEN == 0 size_t strnlen( const char *start, size_t max_len); #endif // HAVE_DECL_STRNLEN From 25da1ee36cfb99f6ef60e7883952c2370c718725 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 5 Mar 2017 09:32:00 +0000 Subject: [PATCH 2/3] build: cleanup: define MSG_DONTWAIT/MSG_NO_SIGNAL locally Define MSG_DONTWAIT and MSG_NO_SIGNAL in the implementation files that use them (`net.cpp` and `netbase.cpp`), instead of compat.h which is included all over the place. This avoids putting them in the global namespace, as defining them as 0 is a hack that works for our specific usage, but it is not a general solution. Also makes sure they are defined only once so the `!defined(MSG_x)` guard can go. --- src/compat.h | 10 ---------- src/net.cpp | 7 ++++++- src/netbase.cpp | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/compat.h b/src/compat.h index 6f4d4e65f..fca6e6101 100644 --- a/src/compat.h +++ b/src/compat.h @@ -72,16 +72,6 @@ typedef u_int SOCKET; #define MAX_PATH 1024 #endif -// As Solaris does not have the MSG_NOSIGNAL flag for send(2) syscall, it is defined as 0 -#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) -#define MSG_NOSIGNAL 0 -#endif - -// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0 -#if !defined(HAVE_MSG_DONTWAIT) && !defined(MSG_DONTWAIT) -#define MSG_DONTWAIT 0 -#endif - #if HAVE_DECL_STRNLEN == 0 size_t strnlen( const char *start, size_t max_len); #endif // HAVE_DECL_STRNLEN diff --git a/src/net.cpp b/src/net.cpp index e38d3b344..8dc234d86 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -44,10 +44,15 @@ // We add a random period time (0 to 1 seconds) to feeler connections to prevent synchronization. #define FEELER_SLEEP_WINDOW 1 -#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) +#if !defined(HAVE_MSG_NOSIGNAL) #define MSG_NOSIGNAL 0 #endif +// MSG_DONTWAIT is not available on some platforms, if it doesn't exist define it as 0 +#if !defined(HAVE_MSG_DONTWAIT) +#define MSG_DONTWAIT 0 +#endif + // Fix for ancient MinGW versions, that don't have defined these in ws2tcpip.h. // Todo: Can be removed when our pull-tester is upgraded to a modern MinGW version. #ifdef WIN32 diff --git a/src/netbase.cpp b/src/netbase.cpp index fc9a6ed0b..0f02e93e4 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -25,7 +25,7 @@ #include // for to_lower() #include // for startswith() and endswith() -#if !defined(HAVE_MSG_NOSIGNAL) && !defined(MSG_NOSIGNAL) +#if !defined(HAVE_MSG_NOSIGNAL) #define MSG_NOSIGNAL 0 #endif From a4d1c9f0417e25b0aac937f07edf2bb642b84f09 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Sun, 5 Mar 2017 09:51:21 +0000 Subject: [PATCH 3/3] compat: use `unsigned int` instead of `u_int` `u_int` is not available on some platforms (not sure what standard it's supposed to be part of), we don't use it anywhere else, and it doesn't hurt to simply write `unsigned int` out here. --- src/compat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compat.h b/src/compat.h index fca6e6101..e76ab94c8 100644 --- a/src/compat.h +++ b/src/compat.h @@ -48,7 +48,7 @@ #endif #ifndef WIN32 -typedef u_int SOCKET; +typedef unsigned int SOCKET; #include "errno.h" #define WSAGetLastError() errno #define WSAEINVAL EINVAL