authorgravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-06-20 00:35:08+02:00
committergravatar for kappaloris@gmail.comLoris Cro <kappaloris@gmail.com> 2020-09-24 22:06:41+02:00
log419aea54cb30b394191778fcc70effaf5181bf33
treeac929fd736e0f970c78be45402a2bae012b02af9
parent7fec5b3def36bc73e9e48a777bcca838c4b86770

sendto

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

3 files changed, 32 insertions(+), 9 deletions(-)

lib/std/event/loop.zig+21
...@@ -1088,6 +1088,27 @@ pub const Loop = struct {...@@ -1088,6 +1088,27 @@ pub const Loop = struct {
1088 }1088 }
1089 }1089 }
10901090
1091 pub fn sendto(
1092 self: *Loop,
1093 /// The file descriptor of the sending socket.
1094 sockfd: os.fd_t,
1095 /// Message to send.
1096 buf: []const u8,
1097 flags: u32,
1098 dest_addr: ?*const os.sockaddr,
1099 addrlen: os.socklen_t,
1100 ) os.SendError!usize {
1101 while (true) {
1102 return os.sendto(sockfd, buf, flags, dest_addr, addrlen) catch |err| switch (err) {
1103 error.WouldBlock => {
1104 self.waitUntilFdWritable(sockfd);
1105 continue;
1106 },
1107 else => return err,
1108 };
1109 }
1110 }
1111
1091 /// Performs an async `os.faccessatZ` using a separate thread.1112 /// Performs an async `os.faccessatZ` using a separate thread.
1092 /// `fd` must block and not return EAGAIN.1113 /// `fd` must block and not return EAGAIN.
1093 pub fn faccessatZ(1114 pub fn faccessatZ(
lib/std/net.zig+10-2
...@@ -1435,7 +1435,11 @@ fn resMSendRc(...@@ -1435,7 +1435,11 @@ fn resMSendRc(
1435 if (answers[i].len == 0) {1435 if (answers[i].len == 0) {
1436 var j: usize = 0;1436 var j: usize = 0;
1437 while (j < ns.len) : (j += 1) {1437 while (j < ns.len) : (j += 1) {
1438 _ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;1438 if (std.io.is_async) {
1439 _ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
1440 } else {
1441 _ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
1442 }
1439 }1443 }
1440 }1444 }
1441 }1445 }
...@@ -1476,7 +1480,11 @@ fn resMSendRc(...@@ -1476,7 +1480,11 @@ fn resMSendRc(
1476 0, 3 => {},1480 0, 3 => {},
1477 2 => if (servfail_retry != 0) {1481 2 => if (servfail_retry != 0) {
1478 servfail_retry -= 1;1482 servfail_retry -= 1;
1479 _ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;1483 if (std.io.is_async) {
1484 _ = std.event.Loop.instance.?.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
1485 } else {
1486 _ = os.sendto(fd, queries[i], os.MSG_NOSIGNAL, &ns[j].any, sl) catch undefined;
1487 }
1480 },1488 },
1481 else => continue,1489 else => continue,
1482 }1490 }
lib/std/os.zig+1-7
...@@ -4571,14 +4571,8 @@ pub fn sendto(...@@ -4571,14 +4571,8 @@ pub fn sendto(
4571 const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen);4571 const rc = system.sendto(sockfd, buf.ptr, buf.len, flags, dest_addr, addrlen);
4572 switch (errno(rc)) {4572 switch (errno(rc)) {
4573 0 => return @intCast(usize, rc),4573 0 => return @intCast(usize, rc),
4574
4575 EACCES => return error.AccessDenied,4574 EACCES => return error.AccessDenied,
4576 EAGAIN => if (std.event.Loop.instance) |loop| {4575 EAGAIN => return error.WouldBlock,
4577 loop.waitUntilFdWritable(sockfd);
4578 continue;
4579 } else {
4580 return error.WouldBlock;
4581 },
4582 EALREADY => return error.FastOpenAlreadyInProgress,4576 EALREADY => return error.FastOpenAlreadyInProgress,
4583 EBADF => unreachable, // always a race condition4577 EBADF => unreachable, // always a race condition
4584 ECONNRESET => return error.ConnectionResetByPeer,4578 ECONNRESET => return error.ConnectionResetByPeer,