Set the SO_REUSEPORT flag on OS X whenever we set the SO_REUSEADDR

This commit is contained in:
Eric Frias 2014-05-13 21:14:40 -07:00
parent 0a11b29984
commit eb501387e8

View file

@ -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 )
{