Skip to content

Commit

Permalink
epee: use the socket::bind variant which does not throw
Browse files Browse the repository at this point in the history
When this throws in a loop, stack trace generation can take
a significant amount of CPU
  • Loading branch information
moneromooo-monero committed Aug 27, 2018
1 parent 91c7d68 commit 8eab614
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions contrib/epee/include/net/abstract_tcp_server2.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,15 @@ POP_WARNINGS
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);
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;
}
}

/*
Expand Down Expand Up @@ -1216,7 +1224,15 @@ POP_WARNINGS
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);
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_));
Expand Down

0 comments on commit 8eab614

Please sign in to comment.