mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-06-11 01:25:53 -04:00
Merge pull request #2333 from webcoyote/display-dynamic-port
Display actual port when binding --port 0
This commit is contained in:
@@ -57,8 +57,9 @@ pub fn init(app: *App, address: net.Address) !*Server {
|
||||
.clients_pool = std.heap.MemoryPool(Client).init(allocator),
|
||||
};
|
||||
|
||||
try self.app.network.bind(address, self, onAccept);
|
||||
log.info(.app, "server running", .{ .address = address });
|
||||
var bound_address = address;
|
||||
try self.app.network.bind(&bound_address, self, onAccept);
|
||||
log.info(.app, "server running", .{ .address = bound_address });
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ pub fn deinit(self: *Network) void {
|
||||
|
||||
pub fn bind(
|
||||
self: *Network,
|
||||
address: net.Address,
|
||||
address: *net.Address,
|
||||
ctx: *anyopaque,
|
||||
on_accept: *const fn (ctx: *anyopaque, socket: posix.socket_t) void,
|
||||
) !void {
|
||||
@@ -367,6 +367,13 @@ pub fn bind(
|
||||
try posix.bind(listener, &address.any, address.getOsSockLen());
|
||||
try posix.listen(listener, self.config.maxPendingConnections());
|
||||
|
||||
// When the caller requests port 0, the OS assigns an ephemeral port; read
|
||||
// the actual bound address back so callers (e.g. logging) see the real port.
|
||||
var bound: posix.sockaddr.storage = undefined;
|
||||
var bound_len: posix.socklen_t = @sizeOf(posix.sockaddr.storage);
|
||||
try posix.getsockname(listener, @ptrCast(&bound), &bound_len);
|
||||
address.* = net.Address.initPosix(@ptrCast(@alignCast(&bound)));
|
||||
|
||||
if (self.listener != null) return error.TooManyListeners;
|
||||
|
||||
self.listener = .{
|
||||
|
||||
Reference in New Issue
Block a user