From 0e67568bcac0c4aea795969e2c8b733326b87bec Mon Sep 17 00:00:00 2001 From: Luna Date: Fri, 29 Nov 2019 17:36:05 -0300 Subject: [PATCH] net: fix Options - os: fix typos on setsockopt --- lib/std/net.zig | 4 +++- lib/std/os.zig | 6 ++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/std/net.zig b/lib/std/net.zig index effe8e74c..531900cf9 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -1279,6 +1279,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8) pub const StreamServer = struct { /// Copied from `Options` on `init`. kernel_backlog: u32, + reuse_address: bool, /// `undefined` until `listen` returns successfully. listen_address: Address, @@ -1301,6 +1302,7 @@ pub const StreamServer = struct { return StreamServer{ .sockfd = null, .kernel_backlog = options.kernel_backlog, + .reuse_address = options.reuse_address, .listen_address = undefined, }; } @@ -1323,7 +1325,7 @@ pub const StreamServer = struct { self.sockfd = null; } - if (self.options.reuse_address) { + if (self.reuse_address) { var optval: c_int = 1; try os.setsockopt( self.sockfd.?, diff --git a/lib/std/os.zig b/lib/std/os.zig index 27327c101..7d20802ba 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -3252,16 +3252,14 @@ pub fn sched_yield() SchedYieldError!void { } /// 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(); - +pub fn setsockopt(fd: fd_t, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) !void { 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, + ENOPROTOOPT => return error.InvalidProtocolOption, ENOTSOCK => return error.NotSocket, ENOMEM => return error.OutOfMemory,