parent
7fec5b3def
commit
419aea54cb
|
@ -1088,6 +1088,27 @@ pub const Loop = struct {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn sendto(
|
||||
self: *Loop,
|
||||
/// The file descriptor of the sending socket.
|
||||
sockfd: os.fd_t,
|
||||
/// Message to send.
|
||||
buf: []const u8,
|
||||
flags: u32,
|
||||
dest_addr: ?*const os.sockaddr,
|
||||
addrlen: os.socklen_t,
|
||||
) os.SendError!usize {
|
||||
while (true) {
|
||||
return os.sendto(sockfd, buf, flags, dest_addr, addrlen) catch |err| switch (err) {
|
||||
error.WouldBlock => {
|
||||
self.waitUntilFdWritable(sockfd);
|
||||
continue;
|
||||
},
|
||||
else => return err,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Performs an async `os.faccessatZ` using a separate thread.
|
||||
/// `fd` must block and not return EAGAIN.
|
||||
pub fn faccessatZ(
|
||||
|
|
|
@ -1435,10 +1435,14 @@ fn resMSendRc(
|
|||
if (answers[i].len == 0) {
|
||||
var j: usize = 0;
|
||||
while (j < ns.len) : (j += 1) {
|
||||
if (std.io.is_async) {
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
} else {
|
||||
_ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
t1 = t2;
|
||||
servfail_retry = 2 * queries.len;
|
||||
}
|
||||
|
@ -1476,7 +1480,11 @@ fn resMSendRc(
|
|||
0, 3 => {},
|
||||
2 => if (servfail_retry != 0) {
|
||||
servfail_retry -= 1;
|
||||
if (std.io.is_async) {
|
||||
_ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
} else {
|
||||
_ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
|
||||
}
|
||||
},
|
||||
else => continue,
|
||||
}
|
||||
|
|
|
@ -4571,14 +4571,8 @@ pub fn sendto(
|
|||
const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen);
|
||||
switch (errno(rc)) {
|
||||
0 => return @intCast(usize, rc),
|
||||
|
||||
EACCES => return error.AccessDenied,
|
||||
EAGAIN => if (std.event.Loop.instance) |loop| {
|
||||
loop.waitUntilFdWritable(sockfd);
|
||||
continue;
|
||||
} else {
|
||||
return error.WouldBlock;
|
||||
},
|
||||
EAGAIN => return error.WouldBlock,
|
||||
EALREADY => return error.FastOpenAlreadyInProgress,
|
||||
EBADF => unreachable, // always a race condition
|
||||
ECONNRESET => return error.ConnectionResetByPeer,
|
||||
|
|
Loading…
Reference in New Issue