╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
280 const address = try std.Io.net.IpAddress.parseIp4(listen_address.host, listen_address.port); 281 return switch (policy) { 282 // so a restart can bind past the old process's connections in TIME_WAIT. 283 // not for fallback, where it would let a second instance share the port. 284 .exact => try address.listen(io, .{ .reuse_address = true }), 285 .fallback => address.listen(io, .{}) catch |listen_err| switch (listen_err) { 286 error.AddressInUse => blk: { 287 const any_port = try std.Io.net.IpAddress.parseIp4(listen_address.host, 0); 288 break :blk try any_port.listen(io, .{}); 289 }, 290 else => |e| return e, 291 }, 292 }; 293 } 294 295 fn parseListenAddress(value: []const u8) !ListenAddress { 296 const colon = std.mem.lastIndexOfScalar(u8, value, ':') orelse return error.InvalidListenAddress; 297 if (colon == 0 or colon + 1 >= value.len) return error.InvalidListenAddress; 298 const port = try std.fmt.parseInt(u16, value[colon + 1 ..], 10); 299 return .{ .host = value[0..colon], .port = port }; 300 } 301