diff options
| author | Loris Cro <kappaloris@gmail.com> | 2020-06-16 22:38:51 +0200 |
|---|---|---|
| committer | Loris Cro <kappaloris@gmail.com> | 2020-09-24 21:56:27 +0200 |
| commit | e85c89630e78ccc0e4bab44064779a07a029cecd (patch) | |
| tree | ad8818dd35b5a9a0f781a69bb2c2a3fe6a681cb9 /lib/std/net.zig | |
| parent | bd89bd6fdbcc0ce5ea7763a8043fd46099022b19 (diff) | |
| download | zig-e85c89630e78ccc0e4bab44064779a07a029cecd.tar.gz zig-e85c89630e78ccc0e4bab44064779a07a029cecd.zip | |
accept
Signed-off-by: Loris Cro <kappaloris@gmail.com>
Diffstat (limited to 'lib/std/net.zig')
| -rw-r--r-- | lib/std/net.zig | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/lib/std/net.zig b/lib/std/net.zig index 45d8f07f04..6b6d234843 100644 --- a/lib/std/net.zig +++ b/lib/std/net.zig @@ -1661,18 +1661,23 @@ pub const StreamServer = struct { /// If this function succeeds, the returned `Connection` is a caller-managed resource. pub fn accept(self: *StreamServer) AcceptError!Connection { - const nonblock = if (std.io.is_async) os.SOCK_NONBLOCK else 0; - const accept_flags = nonblock | os.SOCK_CLOEXEC; var accepted_addr: Address = undefined; var adr_len: os.socklen_t = @sizeOf(Address); - if (os.accept(self.sockfd.?, &accepted_addr.any, &adr_len, accept_flags)) |fd| { + const accept_result = blk: { + if (std.io.is_async) { + const loop = std.event.Loop.instance orelse return error.UnexpectedError; + break :blk loop.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK_CLOEXEC); + } else { + break :blk os.accept(self.sockfd.?, &accepted_addr.any, &adr_len, os.SOCK_CLOEXEC); + } + }; + + if (accept_result) |fd| { return Connection{ .file = fs.File{ .handle = fd }, .address = accepted_addr, }; } else |err| switch (err) { - // We only give SOCK_NONBLOCK when I/O mode is async, in which case this error - // is handled by os.accept4. error.WouldBlock => unreachable, else => |e| return e, } |
