Skip to content

Commit

Permalink
fix: Use std.os.windows.poll rather than libc
Browse files Browse the repository at this point in the history
  • Loading branch information
mochalins authored and andrewrk committed Jul 10, 2024
1 parent 9363e99 commit f58ee38
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions lib/std/posix.zig
Original file line number Diff line number Diff line change
Expand Up @@ -6479,33 +6479,31 @@ pub const PollError = error{
} || UnexpectedError;

pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
if (native_os == .windows) {
switch (windows.poll(fds.ptr, @intCast(fds.len), timeout)) {
windows.ws2_32.SOCKET_ERROR => switch (windows.ws2_32.WSAGetLastError()) {
.WSANOTINITIALISED => unreachable,
.WSAENETDOWN => return error.NetworkSubsystemFailed,
.WSAENOBUFS => return error.SystemResources,
// TODO: handle more errors
else => |err| return windows.unexpectedWSAError(err),
},
else => |rc| return @intCast(rc),
}
}
while (true) {
const fds_count = cast(nfds_t, fds.len) orelse return error.SystemResources;
const rc = system.poll(fds.ptr, fds_count, timeout);
if (native_os == .windows) {
if (rc == windows.ws2_32.SOCKET_ERROR) {
switch (windows.ws2_32.WSAGetLastError()) {
.WSANOTINITIALISED => unreachable,
.WSAENETDOWN => return error.NetworkSubsystemFailed,
.WSAENOBUFS => return error.SystemResources,
// TODO: handle more errors
else => |err| return windows.unexpectedWSAError(err),
}
} else {
return @intCast(rc);
}
} else {
switch (errno(rc)) {
.SUCCESS => return @intCast(rc),
.FAULT => unreachable,
.INTR => continue,
.INVAL => unreachable,
.NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
switch (errno(rc)) {
.SUCCESS => return @intCast(rc),
.FAULT => unreachable,
.INTR => continue,
.INVAL => unreachable,
.NOMEM => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
unreachable;
}
unreachable;
}

pub const PPollError = error{
Expand Down

0 comments on commit f58ee38

Please sign in to comment.