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

@@ -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),
);