mirror of
https://github.com/ziglang/zig.git
synced 2026-02-20 08:14:48 +00:00
add StreamServer.Options.reuse_address
this uses a bad direct interface with std.os.linux, this should add setsockopt to std.os.
This commit is contained in:
parent
73e535e112
commit
631eb6783d
@ -1290,6 +1290,9 @@ pub const StreamServer = struct {
|
||||
/// If more than this many connections pool in the kernel, clients will start
|
||||
/// seeing "Connection refused".
|
||||
kernel_backlog: u32 = 128,
|
||||
|
||||
/// Enable SO_REUSEADDR on the socket.
|
||||
reuse_address: bool = false,
|
||||
};
|
||||
|
||||
/// After this call succeeds, resources have been acquired and must
|
||||
@ -1320,6 +1323,19 @@ 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,
|
||||
@ptrCast([*]const u8, &optval),
|
||||
@sizeOf(c_int),
|
||||
);
|
||||
}
|
||||
|
||||
var socklen = address.getOsSockLen();
|
||||
try os.bind(sockfd, &address.any, socklen);
|
||||
try os.listen(sockfd, self.kernel_backlog);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user