parent
631eb6783d
commit
4a4d2c0d80
|
@ -1323,14 +1323,12 @@ pub const StreamServer = struct {
|
|||
self.sockfd = null;
|
||||
}
|
||||
|
||||
// TODO proper interface with errors in std.os
|
||||
var optval: c_int = 1;
|
||||
|
||||
if (self.options.reuse_address) {
|
||||
_ = os.linux.setsockopt(
|
||||
server.sockfd.?,
|
||||
os.linux.SOL_SOCKET,
|
||||
os.linux.SO_REUSEADDR,
|
||||
var optval: c_int = 1;
|
||||
try os.setsockopt(
|
||||
self.sockfd.?,
|
||||
os.SOL_SOCKET,
|
||||
os.SO_REUSEADDR,
|
||||
@ptrCast([*]const u8, &optval),
|
||||
@sizeOf(c_int),
|
||||
);
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue