authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-06-20 00:45:51+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-09-24 22:06:41+02:00
logc196c27af86f0f10b2f53240a68477391c4b9820
tree2933eee628b0a106184a0ea9dbb76f063e222921
parent419aea54cb30b394191778fcc70effaf5181bf33

recvfrom

Signed-off-by: Loris Cro <kappaloris@gmail.com>

3 files changed, 23 insertions(+), 7 deletions(-)

lib/std/event/loop.zig+18
...@@ -1109,6 +1109,24 @@ pub const Loop = struct {...@@ -1109,6 +1109,24 @@ pub const Loop = struct {
1109 }1109 }
1110 }1110 }
11111111
1112 pub fn recvfrom(
1113 sockfd: os.fd_t,
1114 buf: []u8,
1115 flags: u32,
1116 src_addr: ?*os.sockaddr,
1117 addrlen: ?*os.socklen_t,
1118 ) os.RecvFromError!usize {
1119 while (true) {
1120 return os.recvfrom(sockfd, buf, flags, src_addr, addrlen) catch |err| switch (err) {
1121 error.WouldBlock => {
1122 self.waitUntilFdReadable(sockfd);
1123 continue;
1124 },
1125 else => return err,
1126 };
1127 }
1128 }
1129
1112 /// Performs an async `os.faccessatZ` using a separate thread.1130 /// Performs an async `os.faccessatZ` using a separate thread.
1113 /// `fd` must block and not return EAGAIN.1131 /// `fd` must block and not return EAGAIN.
1114 pub fn faccessatZ(1132 pub fn faccessatZ(
lib/std/net.zig+4-1
...@@ -1454,7 +1454,10 @@ fn resMSendRc(...@@ -1454,7 +1454,10 @@ fn resMSendRc(
14541454
1455 while (true) {1455 while (true) {
1456 var sl_copy = sl;1456 var sl_copy = sl;
1457 const rlen = os.recvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy) catch break;1457 const rlen = if (std.io.is_async)
1458 std.event.Loop.instance.?.recvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy) catch break
1459 else
1460 os.recvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy) catch break;
14581461
1459 // Ignore non-identifiable packets1462 // Ignore non-identifiable packets
1460 if (rlen < 4) continue;1463 if (rlen < 4) continue;
lib/std/os.zig+1-6
...@@ -5068,12 +5068,7 @@ pub fn recvfrom(...@@ -5068,12 +5068,7 @@ pub fn recvfrom(
5068 ENOTCONN => unreachable,5068 ENOTCONN => unreachable,
5069 ENOTSOCK => unreachable,5069 ENOTSOCK => unreachable,
5070 EINTR => continue,5070 EINTR => continue,
5071 EAGAIN => if (std.event.Loop.instance) |loop| {5071 EAGAIN => return error.WouldBlock,
5072 loop.waitUntilFdReadable(sockfd);
5073 continue;
5074 } else {
5075 return error.WouldBlock;
5076 },
5077 ENOMEM => return error.SystemResources,5072 ENOMEM => return error.SystemResources,
5078 ECONNREFUSED => return error.ConnectionRefused,5073 ECONNREFUSED => return error.ConnectionRefused,
5079 else => |err| return unexpectedErrno(err),5074 else => |err| return unexpectedErrno(err),