From eb501387e8e81947eb4b6df611a897d246e2db4a Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Tue, 13 May 2014 21:14:40 -0700 Subject: [PATCH] Set the SO_REUSEPORT flag on OS X whenever we set the SO_REUSEADDR --- src/network/tcp_socket.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/network/tcp_socket.cpp b/src/network/tcp_socket.cpp index b9fdab7..b1a6dbe 100644 --- a/src/network/tcp_socket.cpp +++ b/src/network/tcp_socket.cpp @@ -136,6 +136,14 @@ namespace fc { FC_ASSERT(my->_sock.is_open()); boost::asio::socket_base::reuse_address option(enable); my->_sock.set_option(option); +#if defined(__APPLE__) + // OSX needs SO_REUSEPORT in addition to SO_REUSEADDR. + // This probably needs to be set for any BSD + int reuseport_value = 1; + if (setsockopt(my->_sock.native(), SOL_SOCKET, SO_REUSEPORT, + (char*)&reuseport_value, sizeof(reuseport_value)) < 0) + wlog("Error setting SO_REUSEPORT"); +#endif // __APPLE__ } @@ -187,6 +195,14 @@ namespace fc { my = new impl; boost::asio::ip::tcp::acceptor::reuse_address option(enable); my->_accept.set_option(option); +#if defined(__APPLE__) + // OSX needs SO_REUSEPORT in addition to SO_REUSEADDR. + // This probably needs to be set for any BSD + int reuseport_value = 1; + if (setsockopt(my->_accept.native(), SOL_SOCKET, SO_REUSEPORT, + (char*)&reuseport_value, sizeof(reuseport_value)) < 0) + wlog("Error setting SO_REUSEPORT"); +#endif // __APPLE__ } void tcp_server::listen( uint16_t port ) {