os: add setsockopt

- net: use os.setsockopt()
This commit is contained in:
Luna
2019-11-29 17:17:09 -03:00
committed by Andrew Kelley
parent 631eb6783d
commit 4a4d2c0d80
2 changed files with 25 additions and 7 deletions

View File

@@ -3250,3 +3250,23 @@ pub fn sched_yield() SchedYieldError!void {
else => return error.SystemCannotYield,
}
}
/// Set a socket's options.
pub fn setsockopt(fd: fd_t, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) SetSockOptError!void {
const rc = system.setsockopt();
switch (errno(system.setsockopt(fd, level, optname, optval, optlen))) {
0 => {},
EBADF => unreachable,
EINVAL => unreachable,
EDOM => return error.TimeoutTooBig,
EISCONN => return error.AlreadyConnected,
ENOPROTOOOPT => return error.InvalidProtocolOption,
ENOTSOCK => return error.NotSocket,
ENOMEM => return error.OutOfMemory,
ENOBUFS => return error.SystemResources,
else => |err| return std.os.unexpectedErrno(err),
}
}