authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-30 19:35:05-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-30 19:35:05-05:00
log99f6f8ead90d36eab9b50fc1f2792a2bdfab8867
tree0460754507f6112ee4dcb59d7dfd2d98c7a42d66
parent22f6297157d713ba7a511773b6dc2b095c722346
signature Commit is signed but in an unrecognized format.

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.

1 files changed, 20 insertions(+), 3 deletions(-)

lib/std/os.zig+20-3
...@@ -3251,16 +3251,33 @@ pub fn sched_yield() SchedYieldError!void {...@@ -3251,16 +3251,33 @@ pub fn sched_yield() SchedYieldError!void {
3251 }3251 }
3252}3252}
32533253
3254pub const SetSockOptError = error{
3255 /// The socket is already connected, and a specified option cannot be set while the socket is connected.
3256 AlreadyConnected,
3257
3258 /// The option is not supported by the protocol.
3259 InvalidProtocolOption,
3260
3261 /// The send and receive timeout values are too big to fit into the timeout fields in the socket structure.
3262 TimeoutTooBig,
3263
3264 /// Insufficient resources are available in the system to complete the call.
3265 SystemResources,
3266} || UnexpectedError;
3267
3254/// Set a socket's options.3268/// Set a socket's options.
3255pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) !void {3269pub fn setsockopt(fd: fd_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
3256 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {3270 switch (errno(system.setsockopt(fd, level, optname, opt.ptr, @intCast(socklen_t, opt.len)))) {
3257 0 => {},3271 0 => {},
3258 EBADF => unreachable,3272 EBADF => unreachable, // always a race condition
3273 ENOTSOCK => unreachable, // always a race condition
3259 EINVAL => unreachable,3274 EINVAL => unreachable,
3260 EFAULT => unreachable,3275 EFAULT => unreachable,
3276 EDOM => return error.TimeoutTooBig,
3261 EISCONN => return error.AlreadyConnected,3277 EISCONN => return error.AlreadyConnected,
3262 ENOPROTOOPT => return error.InvalidProtocolOption,3278 ENOPROTOOPT => return error.InvalidProtocolOption,
3263 ENOTSOCK => unreachable,3279 ENOMEM => return error.SystemResources,
3280 ENOBUFS => return error.SystemResources,
3264 else => |err| return unexpectedErrno(err),3281 else => |err| return unexpectedErrno(err),
3265 }3282 }
3266}3283}