Permalink
Browse files

Close effyis#2 failed to bind socket on daemon restart

Added cmake testing prog, config option and it's usage.
  • Loading branch information...
klirichek committed Oct 29, 2017
1 parent 0dbb029 commit 0839de76b73c878d816e0d0be16f4b638236cb75
Showing with 30 additions and 1 deletion.
  1. +3 −0 CMakeLists.txt
  2. +23 −0 cmake/check_so_reuseport_availability.cmake
  3. +3 −0 config/config_cmake.h.in
  4. +1 −1 src/searchd.cpp
@@ -264,6 +264,9 @@ else ( WIN32 )
message ( STATUS "Checking for unaligned RAM access" )
include ( check_unaligned_ram_access )
message ( STATUS "Checking for SO_REUSEPORT flag" )
include ( check_so_reuseport_availability )
message ( STATUS "Configuring the options..." )
message ( STATUS "Option DISABLE_MEMROUTINES ${DISABLE_MEMROUTINES}" )
option ( DISABLE_MEMROUTINES "If the build is broken because new/delete override, this option will disable the overriding in sphinx" )
@@ -0,0 +1,23 @@
#find if SO_REUSEPORT flag is available
set ( _CHECK_SO_REUSEPORT_PROG "
#include <sys/types.h>
#include <sys/socket.h>
#ifdef __CLASSIC_C__
int main() {
int ac;
char*av[];
#else
int main(int ac, char*av[]){
#endif
int iSock = 0;
int iOn = 1;
setsockopt ( iSock, SOL_SOCKET, SO_REUSEPORT, (char*)&iOn, sizeof(iOn) );
return 0;
}" )
include ( CheckCXXSourceCompiles )
CHECK_CXX_SOURCE_COMPILES ( "${_CHECK_SO_REUSEPORT_PROG}" _RESULT )
if ( _RESULT )
set ( HAVE_SO_REUSEPORT 1 )
endif ( _RESULT )
@@ -49,6 +49,9 @@
/* Define if your system supports the eventfd system calls */
#cmakedefine01 HAVE_EVENTFD
/* Define if your system supports flag SO_REUSEPORT */
#cmakedefine01 HAVE_SO_REUSEPORT
/* Define to 1 if you have the <execinfo.h> header file. */
#cmakedefine HAVE_EXECINFO_H ${HAVE_EXECINFO_H}
@@ -2221,7 +2221,7 @@ int sphCreateInetSocket ( DWORD uAddr, int iPort )
int iOn = 1;
if ( setsockopt ( iSock, SOL_SOCKET, SO_REUSEADDR, (char*)&iOn, sizeof(iOn) ) )
sphWarning ( "setsockopt() failed: %s", sphSockError() );
#ifdef SO_REUSEPORT
#if HAVE_SO_REUSEPORT
if ( setsockopt ( iSock, SOL_SOCKET, SO_REUSEPORT, (char*)&iOn, sizeof(iOn) ) )
sphWarning ( "setsockopt() failed: %s", sphSockError() );
#endif

0 comments on commit 0839de7

Please sign in to comment.