Commit c196c27af8
lib/std/event/loop.zig
@@ -1109,6 +1109,24 @@ pub const Loop = struct {
}
}
+ pub fn recvfrom(
+ sockfd: os.fd_t,
+ buf: []u8,
+ flags: u32,
+ src_addr: ?*os.sockaddr,
+ addrlen: ?*os.socklen_t,
+ ) os.RecvFromError!usize {
+ while (true) {
+ return os.recvfrom(sockfd, buf, flags, src_addr, addrlen) catch |err| switch (err) {
+ error.WouldBlock => {
+ self.waitUntilFdReadable(sockfd);
+ continue;
+ },
+ else => return err,
+ };
+ }
+ }
+
/// Performs an async `os.faccessatZ` using a separate thread.
/// `fd` must block and not return EAGAIN.
pub fn faccessatZ(
lib/std/net.zig
@@ -1454,7 +1454,10 @@ fn resMSendRc(
while (true) {
var sl_copy = sl;
- const rlen = os.recvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy) catch break;
+ const rlen = if (std.io.is_async)
+ std.event.Loop.instance.?.recvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy) catch break
+ else
+ os.recvfrom(fd, answer_bufs[next], 0, &sa.any, &sl_copy) catch break;
// Ignore non-identifiable packets
if (rlen < 4) continue;
lib/std/os.zig
@@ -5068,12 +5068,7 @@ pub fn recvfrom(
ENOTCONN => unreachable,
ENOTSOCK => unreachable,
EINTR => continue,
- EAGAIN => if (std.event.Loop.instance) |loop| {
- loop.waitUntilFdReadable(sockfd);
- continue;
- } else {
- return error.WouldBlock;
- },
+ EAGAIN => return error.WouldBlock,
ENOMEM => return error.SystemResources,
ECONNREFUSED => return error.ConnectionRefused,
else => |err| return unexpectedErrno(err),