Resolves the actual port a server binds, in the case the user requests

any available port from the OS.
This commit is contained in:
Benjamin Naecker 2021-06-21 12:36:32 -07:00
parent eaf3f9c6e6
commit 3275a53723

View File

@ -324,6 +324,13 @@ Poco::Net::SocketAddress Server::socketBindListen(Poco::Net::ServerSocket & sock
socket.bind(address, /* reuseAddress = */ true, /* reusePort = */ config().getBool("listen_reuse_port", false));
#endif
/// If caller requests any available port from the OS, discover it after binding.
if (port == 0)
{
address = socket.address();
LOG_DEBUG(&logger(), "Requested any available port (port == 0), actual port is {:d}", address.port());
}
socket.listen(/* backlog = */ config().getUInt("listen_backlog", 64));
return address;