bind stream server to configurable interface

This commit is contained in:
badaix 2019-10-12 11:26:47 +02:00
parent 9ced0aa438
commit 484cd5e672
6 changed files with 66 additions and 56 deletions

View file

@ -140,14 +140,34 @@ void ControlServer::start()
if (tcp_settings_.enabled)
{
for (const auto& address : tcp_settings_.bind_to_address)
acceptor_tcp_.emplace_back(
make_unique<tcp::acceptor>(*io_context_, tcp::endpoint(boost::asio::ip::address::from_string(address), tcp_settings_.port)));
{
try
{
LOG(INFO) << "Creating TCP acceptor for address: " << address << ", port: " << tcp_settings_.port << "\n";
acceptor_tcp_.emplace_back(
make_unique<tcp::acceptor>(*io_context_, tcp::endpoint(boost::asio::ip::address::from_string(address), tcp_settings_.port)));
}
catch (const boost::system::system_error& e)
{
LOG(ERROR) << "error creating TCP acceptor: " << e.what() << ", code: " << e.code() << "\n";
}
}
}
if (http_settings_.enabled)
{
for (const auto& address : http_settings_.bind_to_address)
acceptor_http_.emplace_back(
make_unique<tcp::acceptor>(*io_context_, tcp::endpoint(boost::asio::ip::address::from_string(address), http_settings_.port)));
{
try
{
LOG(INFO) << "Creating HTTP acceptor for address: " << address << ", port: " << http_settings_.port << "\n";
acceptor_http_.emplace_back(
make_unique<tcp::acceptor>(*io_context_, tcp::endpoint(boost::asio::ip::address::from_string(address), http_settings_.port)));
}
catch (const boost::system::system_error& e)
{
LOG(ERROR) << "error creating HTTP acceptor: " << e.what() << ", code: " << e.code() << "\n";
}
}
}
startAccept();
@ -162,6 +182,9 @@ void ControlServer::stop()
for (auto& acceptor : acceptor_http_)
acceptor->cancel();
acceptor_tcp_.clear();
acceptor_http_.clear();
std::lock_guard<std::recursive_mutex> mlock(session_mutex_);
cleanup();
for (auto s : sessions_)