commit 99f6f8ead90d36eab9b50fc1f2792a2bdfab8867 (tree)
parent 22f6297157d713ba7a511773b6dc2b095c722346
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 30 Dec 2019 19:35:05 -0500
update setsockopt error set according to POSIX
In the code review I accidentally encouraged Luna to remove some
handling of errors that are possible according to POSIX, but I think how
Luna had it before was better, so I fixed it, and now the branch should
be good to merge.
Diffstat:
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/lib/std/os.zig b/lib/std/os.zig
@@ -3251,16 +3251,33 @@ pub fn sched_yield() SchedYieldError!void {
}
}
+pub const SetSockOptError = error{
+ /// The socket is already connected, and a specified option cannot be set while the socket is connected.
+ AlreadyConnected,
+
+ /// The option is not supported by the protocol.
+ InvalidProtocolOption,
+
+ /// The send and receive timeout values are too big to fit into the timeout fields in the socket structure.
+ TimeoutTooBig,
+
+ /// Insufficient resources are available in the system to complete the call.
+ SystemResources,
+} || UnexpectedError;
+
/// Set a socket's options.
-pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) !void {
+pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
0 => {},
- EBADF => unreachable,
+ EBADF => unreachable, // always a race condition
+ ENOTSOCK => unreachable, // always a race condition
EINVAL => unreachable,
EFAULT => unreachable,
+ EDOM => return error.TimeoutTooBig,
EISCONN => return error.AlreadyConnected,
ENOPROTOOPT => return error.InvalidProtocolOption,
- ENOTSOCK => unreachable,
+ ENOMEM => return error.SystemResources,
+ ENOBUFS => return error.SystemResources,
else => |err| return unexpectedErrno(err),
}
}