aboutsummaryrefslogtreecommitdiff
path: root/lib/std/os.zig
diff options
context:
space:
mode:
authorluna <git@l4.pm>2020-12-22 18:47:11 -0300
committerGitHub <noreply@github.com>2020-12-22 16:47:11 -0500
commit6a75cfd0f6d45de3b4d1ad74eaec892dc1cd6e30 (patch)
treeafdcfa48b211d5ea9ebde4b09f9868f403c72765 /lib/std/os.zig
parent43dbe86226fe89c6364fa0261297f1a9d8eb2a58 (diff)
downloadzig-6a75cfd0f6d45de3b4d1ad74eaec892dc1cd6e30.tar.gz
zig-6a75cfd0f6d45de3b4d1ad74eaec892dc1cd6e30.zip
cast sendto to SendError inside send (#7481)
* cast sendto to SendError inside send * remove WouldBlock from SendToError * add missing ENOTCONN mapping * remove SystemResources duplicate * move NetworkUnreachable to SendError * add NetworkSubsystemFailed to SendError * Use zig's implicit error set casting Co-authored-by: Andrew Kelley <andrew@ziglang.org>
Diffstat (limited to 'lib/std/os.zig')
-rw-r--r--lib/std/os.zig30
1 files changed, 20 insertions, 10 deletions
diff --git a/lib/std/os.zig b/lib/std/os.zig
index fb67b89d0a..5a57fed5cf 100644
--- a/lib/std/os.zig
+++ b/lib/std/os.zig
@@ -4774,6 +4774,12 @@ pub const SendError = error{
BrokenPipe,
FileDescriptorNotASocket,
+
+ /// Network is unreachable.
+ NetworkUnreachable,
+
+ /// The local network interface used to reach the destination is down.
+ NetworkSubsystemFailed,
} || UnexpectedError;
pub const SendToError = SendError || error{
@@ -4790,15 +4796,8 @@ pub const SendToError = SendError || error{
FileNotFound,
NotDir,
- /// Network is unreachable.
- NetworkUnreachable,
-
- /// Insufficient memory was available to fulfill the request.
- SystemResources,
-
/// The socket is not connected (connection-oriented sockets only).
SocketNotConnected,
- WouldBlock,
AddressNotAvailable,
};
@@ -4853,7 +4852,7 @@ pub fn sendto(
.WSAEHOSTUNREACH => return error.NetworkUnreachable,
// TODO: WSAEINPROGRESS, WSAEINTR
.WSAEINVAL => unreachable,
- .WSAENETDOWN => return error.NetworkUnreachable,
+ .WSAENETDOWN => return error.NetworkSubsystemFailed,
.WSAENETRESET => return error.ConnectionResetByPeer,
.WSAENETUNREACH => return error.NetworkUnreachable,
.WSAENOTCONN => return error.SocketNotConnected,
@@ -4882,7 +4881,6 @@ pub fn sendto(
EMSGSIZE => return error.MessageTooBig,
ENOBUFS => return error.SystemResources,
ENOMEM => return error.SystemResources,
- ENOTCONN => unreachable, // The socket is not connected, and no target has been given.
ENOTSOCK => unreachable, // The file descriptor sockfd does not refer to a socket.
EOPNOTSUPP => unreachable, // Some bit in the flags argument is inappropriate for the socket type.
EPIPE => return error.BrokenPipe,
@@ -4892,6 +4890,9 @@ pub fn sendto(
ENOENT => return error.FileNotFound,
ENOTDIR => return error.NotDir,
EHOSTUNREACH => return error.NetworkUnreachable,
+ ENETUNREACH => return error.NetworkUnreachable,
+ ENOTCONN => return error.SocketNotConnected,
+ ENETDOWN => return error.NetworkSubsystemFailed,
else => |err| return unexpectedErrno(err),
}
}
@@ -4923,7 +4924,16 @@ pub fn send(
buf: []const u8,
flags: u32,
) SendError!usize {
- return sendto(sockfd, buf, flags, null, 0);
+ return sendto(sockfd, buf, flags, null, 0) catch |err| switch (err) {
+ error.AddressFamilyNotSupported => unreachable,
+ error.SymLinkLoop => unreachable,
+ error.NameTooLong => unreachable,
+ error.FileNotFound => unreachable,
+ error.NotDir => unreachable,
+ error.NetworkUnreachable => unreachable,
+ error.AddressNotAvailable => unreachable,
+ else => |e| return e,
+ };
}
pub const SendFileError = PReadError || WriteError || SendError;