Skip to content

Commit a97ab01

Browse files
authored
Merge pull request cpp-netlib#679 from vovams/0.13-release-integration
Fix cpp-netlib#677 in 0.13: Exception in async_server_base/async_connection during port scanning (nmap)
2 parents 87dd551 + 524b999 commit a97ab01

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

boost/network/protocol/http/server/async_connection.hpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,18 @@ struct async_connection
462462
enum state_t { method, uri, version, headers };
463463

464464
void start() {
465-
typename ostringstream<Tag>::type ip_stream;
466-
ip_stream << socket_.remote_endpoint().address().to_string() << ':'
467-
<< socket_.remote_endpoint().port();
468-
request_.source = ip_stream.str();
469-
read_more(method);
465+
boost::system::error_code ec;
466+
auto remote_endpoint = socket_.remote_endpoint(ec);
467+
468+
if (ec) {
469+
error_encountered = in_place<boost::system::system_error>(ec);
470+
} else {
471+
typename ostringstream<Tag>::type ip_stream;
472+
ip_stream << remote_endpoint.address().to_string() << ':'
473+
<< remote_endpoint.port();
474+
request_.source = ip_stream.str();
475+
read_more(method);
476+
}
470477
}
471478

472479
void read_more(state_t state) {

boost/network/protocol/stream_handler.hpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,21 @@ struct stream_handler {
103103
}
104104
}
105105

106-
tcp_socket::endpoint_type remote_endpoint() const {
106+
tcp_socket::endpoint_type remote_endpoint(boost::system::error_code& ec) const {
107107
if (ssl_enabled) {
108-
return ssl_sock_->next_layer().remote_endpoint();
108+
return ssl_sock_->next_layer().remote_endpoint(ec);
109109
} else {
110-
return tcp_sock_->remote_endpoint();
110+
return tcp_sock_->remote_endpoint(ec);
111+
}
112+
}
113+
114+
tcp_socket::endpoint_type remote_endpoint() const {
115+
boost::system::error_code ec;
116+
tcp_socket::endpoint_type r = remote_endpoint(ec);
117+
if (ec) {
118+
boost::asio::detail::throw_error(ec, "remote_endpoint");
111119
}
120+
return r;
112121
}
113122

114123
void shutdown(boost::asio::socket_base::shutdown_type st,

0 commit comments

Comments
 (0)