Compare commits

...

4 Commits

Author SHA1 Message Date
autofix-ci[bot]
3c3b9e8fa3 [autofix.ci] apply automated fixes 2024-01-11 11:10:41 +00:00
cirospaciari
2adb9b5f0f clarify HOST_MAME_MAX on windows 2024-01-11 08:09:25 -03:00
cirospaciari
2893086fba comment 2024-01-11 08:00:03 -03:00
cirospaciari
8a92b66e67 fix compilation and types for FD option using usockets 2024-01-11 07:49:39 -03:00
3 changed files with 12 additions and 4 deletions

View File

@@ -951,7 +951,13 @@ pub const Listener = struct {
const connection: Listener.UnixOrHost = blk: {
if (opts.getTruthy(globalObject, "fd")) |fd_| {
if (fd_.isNumber()) {
const fd: bun.FileDescriptor = fd_.asInt32();
if (Environment.isWindows) {
// SOCKET is actually a u32 but we are casting to a *anyopaque, so we are conservative here
const socket: bun.FDImpl.System = @ptrFromInt(fd_.to(u64));
const fd: bun.FileDescriptor = bun.toFD(socket);
break :blk .{ .fd = fd };
}
const fd: bun.FileDescriptor = bun.toFD(fd_.to(i32));
break :blk .{ .fd = fd };
}
}

View File

@@ -2544,7 +2544,9 @@ pub inline fn socketcast(fd: anytype) std.os.socket_t {
}
pub const HOST_NAME_MAX = if (Environment.isWindows)
// TODO: i have no idea what this value should be
// On Windows the maximum length, in bytes, of the string returned in the buffer pointed to by the name parameter is dependent on the namespace provider, but this string must be 256 bytes or less.
// So if a buffer of 256 bytes is passed in the name parameter and the namelen parameter is set to 256, the buffer size will always be adequate.
// https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-gethostname
256
else
std.os.HOST_NAME_MAX;

View File

@@ -450,7 +450,7 @@ pub fn NewSocketHandler(comptime is_ssl: bool) type {
this: *This,
comptime socket_field_name: ?[]const u8,
) ?ThisSocket {
const socket_ = ThisSocket{ .socket = us_socket_from_fd(ctx, @sizeOf(*anyopaque), handle) orelse return null };
const socket_ = ThisSocket{ .socket = us_socket_from_fd(ctx, @sizeOf(*anyopaque), bun.socketcast(handle)) orelse return null };
const holder = socket_.ext(*anyopaque) orelse {
if (comptime bun.Environment.allow_assert) unreachable;
@@ -2366,7 +2366,7 @@ pub const LIBUS_RECV_BUFFER_LENGTH = 524288;
pub const LIBUS_TIMEOUT_GRANULARITY = @as(i32, 4);
pub const LIBUS_RECV_BUFFER_PADDING = @as(i32, 32);
pub const LIBUS_EXT_ALIGNMENT = @as(i32, 16);
pub const LIBUS_SOCKET_DESCRIPTOR = i32;
pub const LIBUS_SOCKET_DESCRIPTOR = if (Environment.isWindows) std.os.socket_t else i32;
pub const _COMPRESSOR_MASK: i32 = 255;
pub const _DECOMPRESSOR_MASK: i32 = 3840;