aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-08-27 16:29:29 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2018-08-27 17:02:07 +0000
commit8eab6147f414a47d12e00d6c67ca8c466f8a583b (patch)
treece4a108994401f9bafb60fc47bb05919aae7132b /contrib/epee/include
parentMerge pull request #4223 (diff)
downloadmonero-8eab6147f414a47d12e00d6c67ca8c466f8a583b.tar.xz
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
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl20
1 files changed, 18 insertions, 2 deletions
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 59a126163..d837208d3 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -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;
+ }
}
/*
@@ -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_));