Signed-off-by: Loris Cro <kappaloris@gmail.com>
master
Loris Cro 2020-06-20 00:45:51 +02:00
parent 419aea54cb
commit c196c27af8
3 changed files with 23 additions and 7 deletions

View File

@ -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(

View File

@ -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;

View File

@ -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),