ApiListener: use setsockopt(), not tcp::acceptor#set_option()

This commit is contained in:
Alexander A. Klimov 2019-02-21 10:55:47 +01:00
parent b5fddaf3ce
commit 326bf66255
1 changed files with 14 additions and 3 deletions

View File

@ -22,7 +22,6 @@
#include "base/exception.hpp"
#include <boost/asio/buffer.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ip/v6_only.hpp>
#include <boost/asio/spawn.hpp>
#include <boost/asio/ssl/context.hpp>
#include <boost/asio/ssl/verify_context.hpp>
@ -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<const char *>(&optFalse), sizeof(optFalse));
const int optTrue = 1;
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast<const char *>(&optTrue), sizeof(optTrue));
#ifndef _WIN32
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<const char *>(&optTrue), sizeof(optTrue));
#endif /* _WIN32 */
}
acceptor->bind(current->endpoint());
break;