From bf16fc210bc765202489ae83e0ad1dce8d9b4e16 Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 26 Oct 2019 22:00:50 -0300 Subject: [PATCH 1/2] fix std.os.accept4 - add WouldBlock to list of errors in AcceptError - ptrCast addr_size to the system's socklen_t, instead of assuming it's usize --- lib/std/os.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index a1fe051997..50467c4c21 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -1630,6 +1630,10 @@ pub const AcceptError = error{ /// Firewall rules forbid connection. BlockedByFirewall, + + /// This error occurs when no global event loop is configured, + /// and accepting from the socket would block. + WouldBlock, } || UnexpectedError; /// Accept a connection on a socket. @@ -1661,7 +1665,7 @@ pub fn accept4( flags: u32, ) AcceptError!i32 { while (true) { - const rc = system.accept4(sockfd, addr, addr_size, flags); + const rc = system.accept4(sockfd, addr, @ptrCast(*system.socklen_t, addr_size), flags); switch (errno(rc)) { 0 => return @intCast(i32, rc), EINTR => continue, From d4e41c5bc616114beb44969585b47c1ec2a8c9ed Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 26 Oct 2019 22:05:17 -0300 Subject: [PATCH 2/2] std: make addr_size parameter be a pointer to socklen_t removes ptrCast --- lib/std/os.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/os.zig b/lib/std/os.zig index 50467c4c21..40041c8ef7 100644 --- a/lib/std/os.zig +++ b/lib/std/os.zig @@ -1654,7 +1654,7 @@ pub fn accept4( /// /// The returned address is truncated if the buffer provided is too small; in this case, `addr_size` /// will return a value greater than was supplied to the call. - addr_size: *usize, + addr_size: *socklen_t, /// If flags is 0, then `accept4` is the same as `accept`. The following values can be bitwise /// ORed in flags to obtain different behavior: /// * `SOCK_NONBLOCK` - Set the `O_NONBLOCK` file status flag on the open file description (see `open`) @@ -1665,7 +1665,7 @@ pub fn accept4( flags: u32, ) AcceptError!i32 { while (true) { - const rc = system.accept4(sockfd, addr, @ptrCast(*system.socklen_t, addr_size), flags); + const rc = system.accept4(sockfd, addr, addr_size, flags); switch (errno(rc)) { 0 => return @intCast(i32, rc), EINTR => continue,