╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve.zig ────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯
232 fn listen(io: std.Io, listen_address: ListenAddress, policy: PortPolicy) !std.Io.net.Server { 233 const address = try std.Io.net.IpAddress.parseIp4(listen_address.host, listen_address.port); 234 return switch (policy) { 235 .exact => try address.listen(io, .{}), 236 .fallback => address.listen(io, .{}) catch |listen_err| switch (listen_err) { 237 error.AddressInUse => blk: { 238 const any_port = try std.Io.net.IpAddress.parseIp4(listen_address.host, 0); 239 break :blk try any_port.listen(io, .{}); 240 }, 241 else => |e| return e, 242 }, 243 }; 244 } 245 246 fn parseListenAddress(value: []const u8) !ListenAddress { 247 const colon = std.mem.lastIndexOfScalar(u8, value, ':') orelse return error.InvalidListenAddress; 248 if (colon == 0 or colon + 1 >= value.len) return error.InvalidListenAddress; 249 const port = try std.fmt.parseInt(u16, value[colon + 1 ..], 10); 250 return .{ .host = value[0..colon], .port = port }; 251 } 252