@@ -50,9 +50,9 @@ socket::socket(const logger& log, asio::io_context& service) NOEXCEPT
5050// authority_.port() nonzero implies outbound connection.
5151socket::socket (const logger& log, asio::io_context& service,
5252 const config::address& address) NOEXCEPT
53- : address_(address),
54- strand_ (service.get_executor()),
53+ : strand_(service.get_executor()),
5554 socket_ (strand_),
55+ address_(address),
5656 reporter(log),
5757 tracker<socket>(log)
5858{
@@ -228,8 +228,10 @@ void socket::handle_accept(const error::boost_code& ec,
228228{
229229 // This is running in the acceptor (not socket) execution context.
230230 // socket_ and authority_ are not guarded here, see comments on accept.
231+ // address_ remains defaulted for inbound (accepted) connections.
231232
232- if (!ec) authority_ = { socket_.remote_endpoint () };
233+ if (!ec)
234+ authority_ = { socket_.remote_endpoint () };
233235
234236 if (error::asio_is_canceled (ec))
235237 {
@@ -256,6 +258,10 @@ void socket::handle_connect(const error::boost_code& ec,
256258
257259 authority_ = peer;
258260
261+ // Outgoing connection requires address_ for .inbound() resolution.
262+ if (is_zero (address_.port ()))
263+ address_ = config::endpoint{ peer };
264+
259265 if (error::asio_is_canceled (ec))
260266 {
261267 handler (error::operation_canceled);
0 commit comments