diff options
| author | Bas van den Berg <BarabasGitHub@users.noreply.github.com> | 2020-09-10 20:20:27 +0200 |
|---|---|---|
| committer | Bas van den Berg <BarabasGitHub@users.noreply.github.com> | 2020-09-10 20:20:27 +0200 |
| commit | 127fa8009011e19d552ffdd834c6a607498f1c1e (patch) | |
| tree | cd3895e82a0fd773358faf9f0c45ec38cfd51581 /lib/std/os.zig | |
| parent | f5b9e445aa9d2b344b87d4868f9fbb8021577f55 (diff) | |
| download | zig-127fa8009011e19d552ffdd834c6a607498f1c1e.tar.gz zig-127fa8009011e19d552ffdd834c6a607498f1c1e.zip | |
implement poll for windows with WSAPoll (only available on vista and higher)
Diffstat (limited to 'lib/std/os.zig')
| -rw-r--r-- | lib/std/os.zig | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig index 54c80eb788..fdd25fde35 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -5208,6 +5208,9 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len } pub const PollError = error{ + /// The network subsystem has failed. + NetworkSubsystemFailed, + /// The kernel had no space to allocate file descriptor tables. SystemResources, } || UnexpectedError; @@ -5215,14 +5218,29 @@ pub const PollError = error{ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize { while (true) { const rc = system.poll(fds.ptr, fds.len, timeout); - switch (errno(rc)) { - 0 => return @intCast(usize, rc), - EFAULT => unreachable, - EINTR => continue, - EINVAL => unreachable, - ENOMEM => return error.SystemResources, - else => |err| return unexpectedErrno(err), + if (builtin.os.tag == .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(usize, rc); + } + } else { + switch (errno(rc)) { + 0 => return @intCast(usize, rc), + EFAULT => unreachable, + EINTR => continue, + EINVAL => unreachable, + ENOMEM => return error.SystemResources, + else => |err| return unexpectedErrno(err), + } } + unreachable; } } |
