Skip to content

Commit

Permalink
fix(windows): remove unix sockets on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mookums committed Dec 4, 2024
1 parent d1adbd0 commit 2f9808b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/http/router.zig
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub fn Router(comptime Server: type) type {
.body = null,
});

const headers = try provision.response.headers_into_buffer(provision.buffer, stat.size);
const headers = try provision.response.headers_into_buffer(provision.buffer, @intCast(stat.size));
provision.current_length = headers.len;

try rt.fs.read(
Expand Down
42 changes: 27 additions & 15 deletions src/http/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,35 @@ pub fn Server(comptime security: Security) type {
}
}

const BindOptions = union(enum) {
ip: struct { host: []const u8, port: u16 },
unix: []const u8,
const BindOptions = switch (builtin.os.tag) {
// Currently, don't support unix sockets
// on Windows.
.windows => union(enum) {
ip: struct { host: []const u8, port: u16 },
},
else => union(enum) {
ip: struct { host: []const u8, port: u16 },
unix: []const u8,
},
};

pub fn bind(self: *Self, options: BindOptions) !void {
self.addr = blk: {
switch (options) {
.ip => |inner| {
assert(inner.host.len > 0);
assert(inner.port > 0);
if (options == .ip) {
const inner = options.ip;
assert(inner.host.len > 0);
assert(inner.port > 0);

if (comptime tag.isDarwin() or tag.isBSD() or tag == .windows) {
break :blk try std.net.Address.parseIp(inner.host, inner.port);
} else {
break :blk try std.net.Address.resolveIp(inner.host, inner.port);
}
},
.unix => |path| {
if (comptime builtin.os.tag == .linux) {
break :blk try std.net.Address.resolveIp(inner.host, inner.port);
} else {
break :blk try std.net.Address.parseIp(inner.host, inner.port);
}
} else unreachable;

if (@hasDecl(BindOptions, "unix")) {
if (options == .unix) {
const path = options.unix;
assert(path.len > 0);

// Unlink the existing file if it exists.
Expand All @@ -220,8 +230,10 @@ pub fn Server(comptime security: Security) type {
};

break :blk try std.net.Address.initUnix(path);
},
}
}

unreachable;
};
}

Expand Down

0 comments on commit 2f9808b

Please sign in to comment.