authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-13 15:53:19-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:49-07:00
logbe1ae430a1d6dff12c6cd7199dd6504fda880caf
treebee5da42b0dd48fe64d7a749d42ecae54cd11643
parent71ff6e0ef748fbc78cd469317f546c99c0dc5074

std.Io.Threaded.netReadPosix: support cancelation


3 files changed, 86 insertions(+), 36 deletions(-)

lib/std/Io/Threaded.zig+51-6
...@@ -1988,7 +1988,7 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: Io.net.Socket.Handle) Io.net...@@ -1988,7 +1988,7 @@ fn netAcceptPosix(userdata: ?*anyopaque, listen_fd: Io.net.Socket.Handle) Io.net
19881988
1989fn netReadPosix(userdata: ?*anyopaque, stream: Io.net.Stream, data: [][]u8) Io.net.Stream.Reader.Error!usize {1989fn netReadPosix(userdata: ?*anyopaque, stream: Io.net.Stream, data: [][]u8) Io.net.Stream.Reader.Error!usize {
1990 const pool: *Pool = @ptrCast(@alignCast(userdata));1990 const pool: *Pool = @ptrCast(@alignCast(userdata));
1991 try pool.checkCancel();1991 const fd = stream.socket.handle;
19921992
1993 var iovecs_buffer: [max_iovecs_len]posix.iovec = undefined;1993 var iovecs_buffer: [max_iovecs_len]posix.iovec = undefined;
1994 var i: usize = 0;1994 var i: usize = 0;
...@@ -2001,9 +2001,54 @@ fn netReadPosix(userdata: ?*anyopaque, stream: Io.net.Stream, data: [][]u8) Io.n...@@ -2001,9 +2001,54 @@ fn netReadPosix(userdata: ?*anyopaque, stream: Io.net.Stream, data: [][]u8) Io.n
2001 }2001 }
2002 const dest = iovecs_buffer[0..i];2002 const dest = iovecs_buffer[0..i];
2003 assert(dest[0].len > 0);2003 assert(dest[0].len > 0);
2004 const n = try posix.readv(stream.socket.handle, dest);2004
2005 if (n == 0) return error.EndOfStream;2005 if (native_os == .wasi and !builtin.link_libc) while (true) {
2006 return n;2006 try pool.checkCancel();
2007 var n: usize = undefined;
2008 switch (std.os.wasi.fd_read(fd, dest.ptr, dest.len, &n)) {
2009 .SUCCESS => {
2010 if (n == 0) return error.EndOfStream;
2011 return n;
2012 },
2013 .INTR => continue,
2014 .INVAL => |err| return errnoBug(err),
2015 .FAULT => |err| return errnoBug(err),
2016 .AGAIN => |err| return errnoBug(err),
2017 .BADF => |err| return errnoBug(err),
2018 .NOBUFS => return error.SystemResources,
2019 .NOMEM => return error.SystemResources,
2020 .NOTCONN => return error.SocketUnconnected,
2021 .CONNRESET => return error.ConnectionResetByPeer,
2022 .TIMEDOUT => return error.ConnectionTimedOut,
2023 .NOTCAPABLE => return error.AccessDenied,
2024 else => |err| return posix.unexpectedErrno(err),
2025 }
2026 };
2027
2028 while (true) {
2029 try pool.checkCancel();
2030 const rc = posix.system.readv(fd, dest.ptr, @intCast(dest.len));
2031 switch (posix.errno(rc)) {
2032 .SUCCESS => {
2033 const n: usize = @intCast(rc);
2034 if (n == 0) return error.EndOfStream;
2035 return n;
2036 },
2037 .INTR => continue,
2038 .INVAL => |err| return errnoBug(err),
2039 .FAULT => |err| return errnoBug(err),
2040 .AGAIN => |err| return errnoBug(err),
2041 .BADF => |err| return errnoBug(err), // Always a race condition.
2042 .NOBUFS => return error.SystemResources,
2043 .NOMEM => return error.SystemResources,
2044 .NOTCONN => return error.SocketUnconnected,
2045 .CONNRESET => return error.ConnectionResetByPeer,
2046 .TIMEDOUT => return error.ConnectionTimedOut,
2047 .PIPE => return error.BrokenPipe,
2048 .NETDOWN => return error.NetworkDown,
2049 else => |err| return posix.unexpectedErrno(err),
2050 }
2051 }
2007}2052}
20082053
2009const have_sendmmsg = builtin.os.tag == .linux;2054const have_sendmmsg = builtin.os.tag == .linux;
...@@ -2071,7 +2116,7 @@ fn netSendOne(...@@ -2071,7 +2116,7 @@ fn netSendOne(
2071 .WSAEHOSTUNREACH => return error.NetworkUnreachable,2116 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
2072 // TODO: WSAEINPROGRESS, WSAEINTR2117 // TODO: WSAEINPROGRESS, WSAEINTR
2073 .WSAEINVAL => unreachable,2118 .WSAEINVAL => unreachable,
2074 .WSAENETDOWN => return error.NetworkSubsystemFailed,2119 .WSAENETDOWN => return error.NetworkDown,
2075 .WSAENETRESET => return error.ConnectionResetByPeer,2120 .WSAENETRESET => return error.ConnectionResetByPeer,
2076 .WSAENETUNREACH => return error.NetworkUnreachable,2121 .WSAENETUNREACH => return error.NetworkUnreachable,
2077 .WSAENOTCONN => return error.SocketUnconnected,2122 .WSAENOTCONN => return error.SocketUnconnected,
...@@ -2114,7 +2159,7 @@ fn netSendOne(...@@ -2114,7 +2159,7 @@ fn netSendOne(
2114 .HOSTUNREACH => return error.NetworkUnreachable,2159 .HOSTUNREACH => return error.NetworkUnreachable,
2115 .NETUNREACH => return error.NetworkUnreachable,2160 .NETUNREACH => return error.NetworkUnreachable,
2116 .NOTCONN => return error.SocketUnconnected,2161 .NOTCONN => return error.SocketUnconnected,
2117 .NETDOWN => return error.NetworkSubsystemFailed,2162 .NETDOWN => return error.NetworkDown,
2118 else => |err| return posix.unexpectedErrno(err),2163 else => |err| return posix.unexpectedErrno(err),
2119 }2164 }
2120 }2165 }
lib/std/Io/net.zig+11-6
...@@ -1087,13 +1087,18 @@ pub const Stream = struct {...@@ -1087,13 +1087,18 @@ pub const Stream = struct {
1087 stream: Stream,1087 stream: Stream,
1088 err: ?Error,1088 err: ?Error,
10891089
1090 pub const Error = std.posix.ReadError || error{1090 pub const Error = error{
1091 SocketNotBound,1091 SystemResources,
1092 MessageTooBig,1092 BrokenPipe,
1093 NetworkSubsystemFailed,
1094 ConnectionResetByPeer,1093 ConnectionResetByPeer,
1094 ConnectionTimedOut,
1095 SocketUnconnected,1095 SocketUnconnected,
1096 } || Io.Cancelable || Io.Writer.Error || error{EndOfStream};1096 /// The file descriptor does not hold the required rights to read
1097 /// from it.
1098 AccessDenied,
1099 NetworkDown,
1100 EndOfStream,
1101 } || Io.Cancelable || Io.UnexpectedError;
10971102
1098 pub fn init(stream: Stream, io: Io, buffer: []u8) Reader {1103 pub fn init(stream: Stream, io: Io, buffer: []u8) Reader {
1099 return .{1104 return .{
...@@ -1140,7 +1145,7 @@ pub const Stream = struct {...@@ -1140,7 +1145,7 @@ pub const Stream = struct {
1140 ConnectionResetByPeer,1145 ConnectionResetByPeer,
1141 SocketNotBound,1146 SocketNotBound,
1142 MessageTooBig,1147 MessageTooBig,
1143 NetworkSubsystemFailed,1148 NetworkDown,
1144 SystemResources,1149 SystemResources,
1145 SocketUnconnected,1150 SocketUnconnected,
1146 Unexpected,1151 Unexpected,
lib/std/posix.zig+24-24
...@@ -3613,7 +3613,7 @@ pub const ShutdownError = error{...@@ -3613,7 +3613,7 @@ pub const ShutdownError = error{
3613 BlockingOperationInProgress,3613 BlockingOperationInProgress,
36143614
3615 /// The network subsystem has failed.3615 /// The network subsystem has failed.
3616 NetworkSubsystemFailed,3616 NetworkDown,
36173617
3618 /// The socket is not connected (connection-oriented sockets only).3618 /// The socket is not connected (connection-oriented sockets only).
3619 SocketUnconnected,3619 SocketUnconnected,
...@@ -3635,7 +3635,7 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {...@@ -3635,7 +3635,7 @@ pub fn shutdown(sock: socket_t, how: ShutdownHow) ShutdownError!void {
3635 .WSAECONNRESET => return error.ConnectionResetByPeer,3635 .WSAECONNRESET => return error.ConnectionResetByPeer,
3636 .WSAEINPROGRESS => return error.BlockingOperationInProgress,3636 .WSAEINPROGRESS => return error.BlockingOperationInProgress,
3637 .WSAEINVAL => unreachable,3637 .WSAEINVAL => unreachable,
3638 .WSAENETDOWN => return error.NetworkSubsystemFailed,3638 .WSAENETDOWN => return error.NetworkDown,
3639 .WSAENOTCONN => return error.SocketUnconnected,3639 .WSAENOTCONN => return error.SocketUnconnected,
3640 .WSAENOTSOCK => unreachable,3640 .WSAENOTSOCK => unreachable,
3641 .WSANOTINITIALISED => unreachable,3641 .WSANOTINITIALISED => unreachable,
...@@ -3697,7 +3697,7 @@ pub const BindError = error{...@@ -3697,7 +3697,7 @@ pub const BindError = error{
3697 ReadOnlyFileSystem,3697 ReadOnlyFileSystem,
36983698
3699 /// The network subsystem has failed.3699 /// The network subsystem has failed.
3700 NetworkSubsystemFailed,3700 NetworkDown,
37013701
3702 FileDescriptorNotASocket,3702 FileDescriptorNotASocket,
37033703
...@@ -3718,7 +3718,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi...@@ -3718,7 +3718,7 @@ pub fn bind(sock: socket_t, addr: *const sockaddr, len: socklen_t) BindError!voi
3718 .WSAEFAULT => unreachable, // invalid pointers3718 .WSAEFAULT => unreachable, // invalid pointers
3719 .WSAEINVAL => return error.AlreadyBound,3719 .WSAEINVAL => return error.AlreadyBound,
3720 .WSAENOBUFS => return error.SystemResources,3720 .WSAENOBUFS => return error.SystemResources,
3721 .WSAENETDOWN => return error.NetworkSubsystemFailed,3721 .WSAENETDOWN => return error.NetworkDown,
3722 else => |err| return windows.unexpectedWSAError(err),3722 else => |err| return windows.unexpectedWSAError(err),
3723 }3723 }
3724 unreachable;3724 unreachable;
...@@ -3763,7 +3763,7 @@ pub const ListenError = error{...@@ -3763,7 +3763,7 @@ pub const ListenError = error{
3763 OperationNotSupported,3763 OperationNotSupported,
37643764
3765 /// The network subsystem has failed.3765 /// The network subsystem has failed.
3766 NetworkSubsystemFailed,3766 NetworkDown,
37673767
3768 /// Ran out of system resources3768 /// Ran out of system resources
3769 /// On Windows it can either run out of socket descriptors or buffer space3769 /// On Windows it can either run out of socket descriptors or buffer space
...@@ -3782,7 +3782,7 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void {...@@ -3782,7 +3782,7 @@ pub fn listen(sock: socket_t, backlog: u31) ListenError!void {
3782 if (rc == windows.ws2_32.SOCKET_ERROR) {3782 if (rc == windows.ws2_32.SOCKET_ERROR) {
3783 switch (windows.ws2_32.WSAGetLastError()) {3783 switch (windows.ws2_32.WSAGetLastError()) {
3784 .WSANOTINITIALISED => unreachable, // not initialized WSA3784 .WSANOTINITIALISED => unreachable, // not initialized WSA
3785 .WSAENETDOWN => return error.NetworkSubsystemFailed,3785 .WSAENETDOWN => return error.NetworkDown,
3786 .WSAEADDRINUSE => return error.AddressInUse,3786 .WSAEADDRINUSE => return error.AddressInUse,
3787 .WSAEISCONN => return error.AlreadyConnected,3787 .WSAEISCONN => return error.AlreadyConnected,
3788 .WSAEINVAL => return error.SocketNotBound,3788 .WSAEINVAL => return error.SocketNotBound,
...@@ -3840,7 +3840,7 @@ pub const AcceptError = error{...@@ -3840,7 +3840,7 @@ pub const AcceptError = error{
3840 ConnectionResetByPeer,3840 ConnectionResetByPeer,
38413841
3842 /// The network subsystem has failed.3842 /// The network subsystem has failed.
3843 NetworkSubsystemFailed,3843 NetworkDown,
38443844
3845 /// The referenced socket is not a type that supports connection-oriented service.3845 /// The referenced socket is not a type that supports connection-oriented service.
3846 OperationNotSupported,3846 OperationNotSupported,
...@@ -3893,7 +3893,7 @@ pub fn accept(...@@ -3893,7 +3893,7 @@ pub fn accept(
3893 .WSAENOTSOCK => return error.FileDescriptorNotASocket,3893 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
3894 .WSAEINVAL => return error.SocketNotListening,3894 .WSAEINVAL => return error.SocketNotListening,
3895 .WSAEMFILE => return error.ProcessFdQuotaExceeded,3895 .WSAEMFILE => return error.ProcessFdQuotaExceeded,
3896 .WSAENETDOWN => return error.NetworkSubsystemFailed,3896 .WSAENETDOWN => return error.NetworkDown,
3897 .WSAENOBUFS => return error.FileDescriptorNotASocket,3897 .WSAENOBUFS => return error.FileDescriptorNotASocket,
3898 .WSAEOPNOTSUPP => return error.OperationNotSupported,3898 .WSAEOPNOTSUPP => return error.OperationNotSupported,
3899 .WSAEWOULDBLOCK => return error.WouldBlock,3899 .WSAEWOULDBLOCK => return error.WouldBlock,
...@@ -3964,7 +3964,7 @@ fn setSockFlags(sock: socket_t, flags: u32) !void {...@@ -3964,7 +3964,7 @@ fn setSockFlags(sock: socket_t, flags: u32) !void {
3964 if (windows.ws2_32.ioctlsocket(sock, windows.ws2_32.FIONBIO, &mode) == windows.ws2_32.SOCKET_ERROR) {3964 if (windows.ws2_32.ioctlsocket(sock, windows.ws2_32.FIONBIO, &mode) == windows.ws2_32.SOCKET_ERROR) {
3965 switch (windows.ws2_32.WSAGetLastError()) {3965 switch (windows.ws2_32.WSAGetLastError()) {
3966 .WSANOTINITIALISED => unreachable,3966 .WSANOTINITIALISED => unreachable,
3967 .WSAENETDOWN => return error.NetworkSubsystemFailed,3967 .WSAENETDOWN => return error.NetworkDown,
3968 .WSAENOTSOCK => return error.FileDescriptorNotASocket,3968 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
3969 // TODO: handle more errors3969 // TODO: handle more errors
3970 else => |err| return windows.unexpectedWSAError(err),3970 else => |err| return windows.unexpectedWSAError(err),
...@@ -4105,7 +4105,7 @@ pub const GetSockNameError = error{...@@ -4105,7 +4105,7 @@ pub const GetSockNameError = error{
4105 SystemResources,4105 SystemResources,
41064106
4107 /// The network subsystem has failed.4107 /// The network subsystem has failed.
4108 NetworkSubsystemFailed,4108 NetworkDown,
41094109
4110 /// Socket hasn't been bound yet4110 /// Socket hasn't been bound yet
4111 SocketNotBound,4111 SocketNotBound,
...@@ -4119,7 +4119,7 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock...@@ -4119,7 +4119,7 @@ pub fn getsockname(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
4119 if (rc == windows.ws2_32.SOCKET_ERROR) {4119 if (rc == windows.ws2_32.SOCKET_ERROR) {
4120 switch (windows.ws2_32.WSAGetLastError()) {4120 switch (windows.ws2_32.WSAGetLastError()) {
4121 .WSANOTINITIALISED => unreachable,4121 .WSANOTINITIALISED => unreachable,
4122 .WSAENETDOWN => return error.NetworkSubsystemFailed,4122 .WSAENETDOWN => return error.NetworkDown,
4123 .WSAEFAULT => unreachable, // addr or addrlen have invalid pointers or addrlen points to an incorrect value4123 .WSAEFAULT => unreachable, // addr or addrlen have invalid pointers or addrlen points to an incorrect value
4124 .WSAENOTSOCK => return error.FileDescriptorNotASocket,4124 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
4125 .WSAEINVAL => return error.SocketNotBound,4125 .WSAEINVAL => return error.SocketNotBound,
...@@ -4148,7 +4148,7 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock...@@ -4148,7 +4148,7 @@ pub fn getpeername(sock: socket_t, addr: *sockaddr, addrlen: *socklen_t) GetSock
4148 if (rc == windows.ws2_32.SOCKET_ERROR) {4148 if (rc == windows.ws2_32.SOCKET_ERROR) {
4149 switch (windows.ws2_32.WSAGetLastError()) {4149 switch (windows.ws2_32.WSAGetLastError()) {
4150 .WSANOTINITIALISED => unreachable,4150 .WSANOTINITIALISED => unreachable,
4151 .WSAENETDOWN => return error.NetworkSubsystemFailed,4151 .WSAENETDOWN => return error.NetworkDown,
4152 .WSAEFAULT => unreachable, // addr or addrlen have invalid pointers or addrlen points to an incorrect value4152 .WSAEFAULT => unreachable, // addr or addrlen have invalid pointers or addrlen points to an incorrect value
4153 .WSAENOTSOCK => return error.FileDescriptorNotASocket,4153 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
4154 .WSAEINVAL => return error.SocketNotBound,4154 .WSAEINVAL => return error.SocketNotBound,
...@@ -6057,7 +6057,7 @@ pub const SendError = error{...@@ -6057,7 +6057,7 @@ pub const SendError = error{
6057 NetworkUnreachable,6057 NetworkUnreachable,
60586058
6059 /// The local network interface used to reach the destination is down.6059 /// The local network interface used to reach the destination is down.
6060 NetworkSubsystemFailed,6060 NetworkDown,
60616061
6062 /// The destination address is not listening.6062 /// The destination address is not listening.
6063 ConnectionRefused,6063 ConnectionRefused,
...@@ -6106,7 +6106,7 @@ pub fn sendmsg(...@@ -6106,7 +6106,7 @@ pub fn sendmsg(
6106 .WSAEHOSTUNREACH => return error.NetworkUnreachable,6106 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
6107 // TODO: WSAEINPROGRESS, WSAEINTR6107 // TODO: WSAEINPROGRESS, WSAEINTR
6108 .WSAEINVAL => unreachable,6108 .WSAEINVAL => unreachable,
6109 .WSAENETDOWN => return error.NetworkSubsystemFailed,6109 .WSAENETDOWN => return error.NetworkDown,
6110 .WSAENETRESET => return error.ConnectionResetByPeer,6110 .WSAENETRESET => return error.ConnectionResetByPeer,
6111 .WSAENETUNREACH => return error.NetworkUnreachable,6111 .WSAENETUNREACH => return error.NetworkUnreachable,
6112 .WSAENOTCONN => return error.SocketUnconnected,6112 .WSAENOTCONN => return error.SocketUnconnected,
...@@ -6146,7 +6146,7 @@ pub fn sendmsg(...@@ -6146,7 +6146,7 @@ pub fn sendmsg(
6146 .HOSTUNREACH => return error.NetworkUnreachable,6146 .HOSTUNREACH => return error.NetworkUnreachable,
6147 .NETUNREACH => return error.NetworkUnreachable,6147 .NETUNREACH => return error.NetworkUnreachable,
6148 .NOTCONN => return error.SocketUnconnected,6148 .NOTCONN => return error.SocketUnconnected,
6149 .NETDOWN => return error.NetworkSubsystemFailed,6149 .NETDOWN => return error.NetworkDown,
6150 else => |err| return unexpectedErrno(err),6150 else => |err| return unexpectedErrno(err),
6151 }6151 }
6152 }6152 }
...@@ -6209,7 +6209,7 @@ pub fn sendto(...@@ -6209,7 +6209,7 @@ pub fn sendto(
6209 .WSAEHOSTUNREACH => return error.NetworkUnreachable,6209 .WSAEHOSTUNREACH => return error.NetworkUnreachable,
6210 // TODO: WSAEINPROGRESS, WSAEINTR6210 // TODO: WSAEINPROGRESS, WSAEINTR
6211 .WSAEINVAL => unreachable,6211 .WSAEINVAL => unreachable,
6212 .WSAENETDOWN => return error.NetworkSubsystemFailed,6212 .WSAENETDOWN => return error.NetworkDown,
6213 .WSAENETRESET => return error.ConnectionResetByPeer,6213 .WSAENETRESET => return error.ConnectionResetByPeer,
6214 .WSAENETUNREACH => return error.NetworkUnreachable,6214 .WSAENETUNREACH => return error.NetworkUnreachable,
6215 .WSAENOTCONN => return error.SocketUnconnected,6215 .WSAENOTCONN => return error.SocketUnconnected,
...@@ -6251,7 +6251,7 @@ pub fn sendto(...@@ -6251,7 +6251,7 @@ pub fn sendto(
6251 .HOSTUNREACH => return error.NetworkUnreachable,6251 .HOSTUNREACH => return error.NetworkUnreachable,
6252 .NETUNREACH => return error.NetworkUnreachable,6252 .NETUNREACH => return error.NetworkUnreachable,
6253 .NOTCONN => return error.SocketUnconnected,6253 .NOTCONN => return error.SocketUnconnected,
6254 .NETDOWN => return error.NetworkSubsystemFailed,6254 .NETDOWN => return error.NetworkDown,
6255 else => |err| return unexpectedErrno(err),6255 else => |err| return unexpectedErrno(err),
6256 }6256 }
6257 }6257 }
...@@ -6390,7 +6390,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len...@@ -6390,7 +6390,7 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
63906390
6391pub const PollError = error{6391pub const PollError = error{
6392 /// The network subsystem has failed.6392 /// The network subsystem has failed.
6393 NetworkSubsystemFailed,6393 NetworkDown,
63946394
6395 /// The kernel had no space to allocate file descriptor tables.6395 /// The kernel had no space to allocate file descriptor tables.
6396 SystemResources,6396 SystemResources,
...@@ -6401,7 +6401,7 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {...@@ -6401,7 +6401,7 @@ pub fn poll(fds: []pollfd, timeout: i32) PollError!usize {
6401 switch (windows.poll(fds.ptr, @intCast(fds.len), timeout)) {6401 switch (windows.poll(fds.ptr, @intCast(fds.len), timeout)) {
6402 windows.ws2_32.SOCKET_ERROR => switch (windows.ws2_32.WSAGetLastError()) {6402 windows.ws2_32.SOCKET_ERROR => switch (windows.ws2_32.WSAGetLastError()) {
6403 .WSANOTINITIALISED => unreachable,6403 .WSANOTINITIALISED => unreachable,
6404 .WSAENETDOWN => return error.NetworkSubsystemFailed,6404 .WSAENETDOWN => return error.NetworkDown,
6405 .WSAENOBUFS => return error.SystemResources,6405 .WSAENOBUFS => return error.SystemResources,
6406 // TODO: handle more errors6406 // TODO: handle more errors
6407 else => |err| return windows.unexpectedWSAError(err),6407 else => |err| return windows.unexpectedWSAError(err),
...@@ -6473,7 +6473,7 @@ pub const RecvFromError = error{...@@ -6473,7 +6473,7 @@ pub const RecvFromError = error{
6473 MessageTooBig,6473 MessageTooBig,
64746474
6475 /// The network subsystem has failed.6475 /// The network subsystem has failed.
6476 NetworkSubsystemFailed,6476 NetworkDown,
64776477
6478 /// The socket is not connected (connection-oriented sockets only).6478 /// The socket is not connected (connection-oriented sockets only).
6479 SocketUnconnected,6479 SocketUnconnected,
...@@ -6504,7 +6504,7 @@ pub fn recvfrom(...@@ -6504,7 +6504,7 @@ pub fn recvfrom(
6504 .WSAECONNRESET => return error.ConnectionResetByPeer,6504 .WSAECONNRESET => return error.ConnectionResetByPeer,
6505 .WSAEINVAL => return error.SocketNotBound,6505 .WSAEINVAL => return error.SocketNotBound,
6506 .WSAEMSGSIZE => return error.MessageTooBig,6506 .WSAEMSGSIZE => return error.MessageTooBig,
6507 .WSAENETDOWN => return error.NetworkSubsystemFailed,6507 .WSAENETDOWN => return error.NetworkDown,
6508 .WSAENOTCONN => return error.SocketUnconnected,6508 .WSAENOTCONN => return error.SocketUnconnected,
6509 .WSAEWOULDBLOCK => return error.WouldBlock,6509 .WSAEWOULDBLOCK => return error.WouldBlock,
6510 .WSAETIMEDOUT => return error.ConnectionTimedOut,6510 .WSAETIMEDOUT => return error.ConnectionTimedOut,
...@@ -6578,7 +6578,7 @@ pub fn recvmsg(...@@ -6578,7 +6578,7 @@ pub fn recvmsg(
6578 .PIPE => return error.BrokenPipe,6578 .PIPE => return error.BrokenPipe,
6579 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.6579 .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
6580 .CONNRESET => return error.ConnectionResetByPeer,6580 .CONNRESET => return error.ConnectionResetByPeer,
6581 .NETDOWN => return error.NetworkSubsystemFailed,6581 .NETDOWN => return error.NetworkDown,
6582 else => |err| return unexpectedErrno(err),6582 else => |err| return unexpectedErrno(err),
6583 }6583 }
6584 }6584 }
...@@ -6601,7 +6601,7 @@ pub const SetSockOptError = error{...@@ -6601,7 +6601,7 @@ pub const SetSockOptError = error{
6601 PermissionDenied,6601 PermissionDenied,
66026602
6603 OperationNotSupported,6603 OperationNotSupported,
6604 NetworkSubsystemFailed,6604 NetworkDown,
6605 FileDescriptorNotASocket,6605 FileDescriptorNotASocket,
6606 SocketNotBound,6606 SocketNotBound,
6607 NoDevice,6607 NoDevice,
...@@ -6614,7 +6614,7 @@ pub fn setsockopt(fd: socket_t, level: i32, optname: u32, opt: []const u8) SetSo...@@ -6614,7 +6614,7 @@ pub fn setsockopt(fd: socket_t, level: i32, optname: u32, opt: []const u8) SetSo
6614 if (rc == windows.ws2_32.SOCKET_ERROR) {6614 if (rc == windows.ws2_32.SOCKET_ERROR) {
6615 switch (windows.ws2_32.WSAGetLastError()) {6615 switch (windows.ws2_32.WSAGetLastError()) {
6616 .WSANOTINITIALISED => unreachable,6616 .WSANOTINITIALISED => unreachable,
6617 .WSAENETDOWN => return error.NetworkSubsystemFailed,6617 .WSAENETDOWN => return error.NetworkDown,
6618 .WSAEFAULT => unreachable,6618 .WSAEFAULT => unreachable,
6619 .WSAENOTSOCK => return error.FileDescriptorNotASocket,6619 .WSAENOTSOCK => return error.FileDescriptorNotASocket,
6620 .WSAEINVAL => return error.SocketNotBound,6620 .WSAEINVAL => return error.SocketNotBound,