From 326bf6625578180dc5a21ebcceb2043fd538714b Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Thu, 21 Feb 2019 10:55:47 +0100 Subject: [PATCH] ApiListener: use setsockopt(), not tcp::acceptor#set_option() --- lib/remote/apilistener.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/remote/apilistener.cpp b/lib/remote/apilistener.cpp index 4928c285c..f3057c289 100644 --- a/lib/remote/apilistener.cpp +++ b/lib/remote/apilistener.cpp @@ -22,7 +22,6 @@ #include "base/exception.hpp" #include #include -#include #include #include #include @@ -370,8 +369,20 @@ bool ApiListener::AddListener(const String& node, const String& service) for (;;) { try { acceptor->open(current->endpoint().protocol()); - acceptor->set_option(ip::v6_only(false)); - acceptor->set_option(tcp::acceptor::reuse_address(true)); + + { + auto fd (acceptor->native_handle()); + + const int optFalse = 0; + setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, reinterpret_cast(&optFalse), sizeof(optFalse)); + + const int optTrue = 1; + setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&optTrue), sizeof(optTrue)); +#ifndef _WIN32 + setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast(&optTrue), sizeof(optTrue)); +#endif /* _WIN32 */ + } + acceptor->bind(current->endpoint()); break;