mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
os: add setsockopt
- net: use os.setsockopt()
This commit is contained in:
parent
631eb6783d
commit
4a4d2c0d80
@ -1323,14 +1323,12 @@ pub const StreamServer = struct {
|
|||||||
self.sockfd = null;
|
self.sockfd = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO proper interface with errors in std.os
|
|
||||||
var optval: c_int = 1;
|
|
||||||
|
|
||||||
if (self.options.reuse_address) {
|
if (self.options.reuse_address) {
|
||||||
_ = os.linux.setsockopt(
|
var optval: c_int = 1;
|
||||||
server.sockfd.?,
|
try os.setsockopt(
|
||||||
os.linux.SOL_SOCKET,
|
self.sockfd.?,
|
||||||
os.linux.SO_REUSEADDR,
|
os.SOL_SOCKET,
|
||||||
|
os.SO_REUSEADDR,
|
||||||
@ptrCast([*]const u8, &optval),
|
@ptrCast([*]const u8, &optval),
|
||||||
@sizeOf(c_int),
|
@sizeOf(c_int),
|
||||||
);
|
);
|
||||||
|
|||||||
@ -3250,3 +3250,23 @@ pub fn sched_yield() SchedYieldError!void {
|
|||||||
else => return error.SystemCannotYield,
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user