Use non-throwing calls to local_endpoint()
@@ -104,7 +104,11 @@ namespace malmo
int TCPServer::getPort() const
{
- return this->acceptor->local_endpoint().port();
+ boost::system::error_code ec;
+ int port = this->acceptor->local_endpoint(ec).port();
+ if (ec)
+ LOGERROR(LT("TCPServer::getPort failed to resolve endpoint - port returned will be meaningless! Error: "), ec.message());
+ return port;
}
void TCPServer::bindToRandomPortInRange(boost::asio::io_service& io_service, int port_min, int port_max)
@@ -146,7 +150,10 @@ namespace malmo
LOGERROR(this->log_name, LT(" couldn't bind to "), endpt, LT(" - "), e.code().message());
throw e;
}
- LOGFINE(this->log_name, LT(" bound local endpoint "), this->acceptor->local_endpoint(), LT(" to "), endpt);
+ boost::system::error_code ec;
+ LOGFINE(this->log_name, LT(" bound local endpoint "), this->acceptor->local_endpoint(ec), LT(" to "), endpt);
+ if (ec)
+ LOGERROR(this->log_name, LT(" failed to resolve local endpoint: "), ec.message());
}
}
