| ... | @@ -5913,66 +5913,64 @@ pub fn sendto( | ... | @@ -5913,66 +5913,64 @@ pub fn sendto( |
| 5913 | dest_addr: ?*const sockaddr, | 5913 | dest_addr: ?*const sockaddr, |
| 5914 | addrlen: socklen_t, | 5914 | addrlen: socklen_t, |
| 5915 | ) SendToError!usize { | 5915 | ) SendToError!usize { |
| | 5916 | if (builtin.os.tag == .windows) { |
| | 5917 | switch (windows.ws2_32.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen)) { |
| | 5918 | windows.ws2_32.SOCKET_ERROR => switch (windows.ws2_32.WSAGetLastError()) { |
| | 5919 | .WSAEACCES => return error.AccessDenied, |
| | 5920 | .WSAEADDRNOTAVAIL => return error.AddressNotAvailable, |
| | 5921 | .WSAECONNRESET => return error.ConnectionResetByPeer, |
| | 5922 | .WSAEMSGSIZE => return error.MessageTooBig, |
| | 5923 | .WSAENOBUFS => return error.SystemResources, |
| | 5924 | .WSAENOTSOCK => return error.FileDescriptorNotASocket, |
| | 5925 | .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported, |
| | 5926 | .WSAEDESTADDRREQ => unreachable, // A destination address is required. |
| | 5927 | .WSAEFAULT => unreachable, // The lpBuffers, lpTo, lpOverlapped, lpNumberOfBytesSent, or lpCompletionRoutine parameters are not part of the user address space, or the lpTo parameter is too small. |
| | 5928 | .WSAEHOSTUNREACH => return error.NetworkUnreachable, |
| | 5929 | // TODO: WSAEINPROGRESS, WSAEINTR |
| | 5930 | .WSAEINVAL => unreachable, |
| | 5931 | .WSAENETDOWN => return error.NetworkSubsystemFailed, |
| | 5932 | .WSAENETRESET => return error.ConnectionResetByPeer, |
| | 5933 | .WSAENETUNREACH => return error.NetworkUnreachable, |
| | 5934 | .WSAENOTCONN => return error.SocketNotConnected, |
| | 5935 | .WSAESHUTDOWN => unreachable, // The socket has been shut down; it is not possible to WSASendTo on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH. |
| | 5936 | .WSAEWOULDBLOCK => return error.WouldBlock, |
| | 5937 | .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function. |
| | 5938 | else => |err| return windows.unexpectedWSAError(err), |
| | 5939 | }, |
| | 5940 | else => |rc| return @intCast(usize, rc), |
| | 5941 | } |
| | 5942 | } |
| 5916 | while (true) { | 5943 | while (true) { |
| 5917 | const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen); | 5944 | const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen); |
| 5918 | if (builtin.os.tag == .windows) { | 5945 | switch (errno(rc)) { |
| 5919 | if (rc == windows.ws2_32.SOCKET_ERROR) { | 5946 | .SUCCESS => return @intCast(usize, rc), |
| 5920 | switch (windows.ws2_32.WSAGetLastError()) { | | |
| 5921 | .WSAEACCES => return error.AccessDenied, | | |
| 5922 | .WSAEADDRNOTAVAIL => return error.AddressNotAvailable, | | |
| 5923 | .WSAECONNRESET => return error.ConnectionResetByPeer, | | |
| 5924 | .WSAEMSGSIZE => return error.MessageTooBig, | | |
| 5925 | .WSAENOBUFS => return error.SystemResources, | | |
| 5926 | .WSAENOTSOCK => return error.FileDescriptorNotASocket, | | |
| 5927 | .WSAEAFNOSUPPORT => return error.AddressFamilyNotSupported, | | |
| 5928 | .WSAEDESTADDRREQ => unreachable, // A destination address is required. | | |
| 5929 | .WSAEFAULT => unreachable, // The lpBuffers, lpTo, lpOverlapped, lpNumberOfBytesSent, or lpCompletionRoutine parameters are not part of the user address space, or the lpTo parameter is too small. | | |
| 5930 | .WSAEHOSTUNREACH => return error.NetworkUnreachable, | | |
| 5931 | // TODO: WSAEINPROGRESS, WSAEINTR | | |
| 5932 | .WSAEINVAL => unreachable, | | |
| 5933 | .WSAENETDOWN => return error.NetworkSubsystemFailed, | | |
| 5934 | .WSAENETRESET => return error.ConnectionResetByPeer, | | |
| 5935 | .WSAENETUNREACH => return error.NetworkUnreachable, | | |
| 5936 | .WSAENOTCONN => return error.SocketNotConnected, | | |
| 5937 | .WSAESHUTDOWN => unreachable, // The socket has been shut down; it is not possible to WSASendTo on a socket after shutdown has been invoked with how set to SD_SEND or SD_BOTH. | | |
| 5938 | .WSAEWOULDBLOCK => return error.WouldBlock, | | |
| 5939 | .WSANOTINITIALISED => unreachable, // A successful WSAStartup call must occur before using this function. | | |
| 5940 | else => |err| return windows.unexpectedWSAError(err), | | |
| 5941 | } | | |
| 5942 | } else { | | |
| 5943 | return @intCast(usize, rc); | | |
| 5944 | } | | |
| 5945 | } else { | | |
| 5946 | switch (errno(rc)) { | | |
| 5947 | .SUCCESS => return @intCast(usize, rc), | | |
| 5948 | | 5947 | |
| 5949 | .ACCES => return error.AccessDenied, | 5948 | .ACCES => return error.AccessDenied, |
| 5950 | .AGAIN => return error.WouldBlock, | 5949 | .AGAIN => return error.WouldBlock, |
| 5951 | .ALREADY => return error.FastOpenAlreadyInProgress, | 5950 | .ALREADY => return error.FastOpenAlreadyInProgress, |
| 5952 | .BADF => unreachable, // always a race condition | 5951 | .BADF => unreachable, // always a race condition |
| 5953 | .CONNRESET => return error.ConnectionResetByPeer, | 5952 | .CONNRESET => return error.ConnectionResetByPeer, |
| 5954 | .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. | 5953 | .DESTADDRREQ => unreachable, // The socket is not connection-mode, and no peer address is set. |
| 5955 | .FAULT => unreachable, // An invalid user space address was specified for an argument. | 5954 | .FAULT => unreachable, // An invalid user space address was specified for an argument. |
| 5956 | .INTR => continue, | 5955 | .INTR => continue, |
| 5957 | .INVAL => return error.UnreachableAddress, | 5956 | .INVAL => return error.UnreachableAddress, |
| 5958 | .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified | 5957 | .ISCONN => unreachable, // connection-mode socket was connected already but a recipient was specified |
| 5959 | .MSGSIZE => return error.MessageTooBig, | 5958 | .MSGSIZE => return error.MessageTooBig, |
| 5960 | .NOBUFS => return error.SystemResources, | 5959 | .NOBUFS => return error.SystemResources, |
| 5961 | .NOMEM => return error.SystemResources, | 5960 | .NOMEM => return error.SystemResources, |
| 5962 | .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. | 5961 | .NOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket. |
| 5963 | .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. | 5962 | .OPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type. |
| 5964 | .PIPE => return error.BrokenPipe, | 5963 | .PIPE => return error.BrokenPipe, |
| 5965 | .AFNOSUPPORT => return error.AddressFamilyNotSupported, | 5964 | .AFNOSUPPORT => return error.AddressFamilyNotSupported, |
| 5966 | .LOOP => return error.SymLinkLoop, | 5965 | .LOOP => return error.SymLinkLoop, |
| 5967 | .NAMETOOLONG => return error.NameTooLong, | 5966 | .NAMETOOLONG => return error.NameTooLong, |
| 5968 | .NOENT => return error.FileNotFound, | 5967 | .NOENT => return error.FileNotFound, |
| 5969 | .NOTDIR => return error.NotDir, | 5968 | .NOTDIR => return error.NotDir, |
| 5970 | .HOSTUNREACH => return error.NetworkUnreachable, | 5969 | .HOSTUNREACH => return error.NetworkUnreachable, |
| 5971 | .NETUNREACH => return error.NetworkUnreachable, | 5970 | .NETUNREACH => return error.NetworkUnreachable, |
| 5972 | .NOTCONN => return error.SocketNotConnected, | 5971 | .NOTCONN => return error.SocketNotConnected, |
| 5973 | .NETDOWN => return error.NetworkSubsystemFailed, | 5972 | .NETDOWN => return error.NetworkSubsystemFailed, |
| 5974 | else => |err| return unexpectedErrno(err), | 5973 | else => |err| return unexpectedErrno(err), |
| 5975 | } | | |
| 5976 | } | 5974 | } |
| 5977 | } | 5975 | } |
| 5978 | } | 5976 | } |