epee: use the socket::bind variant which does not throw

When this throws in a loop, stack trace generation can take
a significant amount of CPU
This commit is contained in:
moneromooo-monero 2018-08-27 16:29:29 +00:00
parent 91c7d68b2d
commit 8eab6147f4
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
1 changed files with 18 additions and 2 deletions

View File

@ -1110,7 +1110,15 @@ POP_WARNINGS
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" ) if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{ {
boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0); boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0);
sock_.bind(local_endpoint); boost::system::error_code ec;
sock_.bind(local_endpoint, ec);
if (ec)
{
MERROR("Error binding to " << adr << ": " << ec.message());
if (sock_.is_open())
sock_.close();
return false;
}
} }
/* /*
@ -1216,7 +1224,15 @@ POP_WARNINGS
if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" ) if(bind_ip != "0.0.0.0" && bind_ip != "0" && bind_ip != "" )
{ {
boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0); boost::asio::ip::tcp::endpoint local_endpoint(boost::asio::ip::address::from_string(adr.c_str()), 0);
sock_.bind(local_endpoint); boost::system::error_code ec;
sock_.bind(local_endpoint, ec);
if (ec)
{
MERROR("Error binding to " << adr << ": " << ec.message());
if (sock_.is_open())
sock_.close();
return false;
}
} }
boost::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(io_service_)); boost::shared_ptr<boost::asio::deadline_timer> sh_deadline(new boost::asio::deadline_timer(io_service_));