Use const for option. Include proper header files.

This commit is contained in:
Mathias Gug 2016-05-13 20:49:50 -07:00 committed by Patrick Niklaus
parent fe397e6953
commit 520b29d0d5
No known key found for this signature in database
GPG Key ID: E426891B5F978B1B

View File

@ -13,6 +13,9 @@
#include <zlib.h> #include <zlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <thread> #include <thread>
@ -50,11 +53,10 @@ class Server
acceptor.open(endpoint.protocol()); acceptor.open(endpoint.protocol());
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
int one = 1; const int option = 1;
setsockopt(acceptor.native_handle(), SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &one, sizeof(one)); setsockopt(acceptor.native_handle(), SOL_SOCKET, SO_REUSEPORT, &option, sizeof(option));
#else
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
#endif #endif
acceptor.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true));
acceptor.bind(endpoint); acceptor.bind(endpoint);
acceptor.listen(); acceptor.listen();