Support SO_REUSEPORT option

so that multiple osrm-routed processes can bind to the same port.
This commit is contained in:
Mathias Gug 2016-05-11 16:23:50 -07:00 committed by Patrick Niklaus
parent dcb741d827
commit fe397e6953
No known key found for this signature in database
GPG Key ID: E426891B5F978B1B

View File

@ -49,7 +49,12 @@ class Server
boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
acceptor.open(endpoint.protocol());
#ifdef SO_REUSEPORT
int one = 1;
setsockopt(acceptor.native_handle(), SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &one, sizeof(one));
#else
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
#endif
acceptor.bind(endpoint);
acceptor.listen();