From d4f3881bdbdeea7b4ec4974da77acbc3f462328c Mon Sep 17 00:00:00 2001 From: Brandon Black Date: Tue, 5 May 2026 11:07:15 -0500 Subject: [PATCH] std.Io.Threaded.lookupDns: use sendTimeout Mostly I did this to test sendTimeout with something other than my own code. Now that send is Operation-based, it can also honor the timeout deadlines lookupDns is already enforcing on the receive side (which may matter if the socket output buffer gets filled - sends are not always immediately-successful!). --- lib/std/Io/Threaded.zig | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index c40f2a922b11bf077d2d8b1a8f6d5fe20f5160a4..5ed8b097ea8ebe6b1fc88ff47e785f2be73ffa74 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -14655,6 +14655,11 @@ fn lookupDns( }; send: while (now_ts.nanoseconds < final_ts.nanoseconds) : (now_ts = clock.now(t_io)) { + const timeout: Io.Timeout = .{ .deadline = .{ + .raw = now_ts.addDuration(attempt_duration), + .clock = clock, + } }; + const max_messages = queries_buffer.len * HostName.ResolvConf.max_nameservers; { var message_buffer: [max_messages]net.OutgoingMessage = undefined; @@ -14670,14 +14675,14 @@ fn lookupDns( message_i += 1; } } - _ = netSendPosix(t, socket.handle, message_buffer[0..message_i], .{}, false); + const send_err, _ = socket.sendManyTimeout(t_io, message_buffer[0..message_i], .{}, timeout); + if (send_err) |err| switch (err) { + error.Canceled => |e| return e, + error.Timeout => continue :send, + else => {}, + }; } - const timeout: Io.Timeout = .{ .deadline = .{ - .raw = now_ts.addDuration(attempt_duration), - .clock = clock, - } }; - while (true) { var message_buffer: [max_messages]net.IncomingMessage = @splat(.init); const buf = answer_buffer[answer_buffer_i..]; @@ -14713,12 +14718,11 @@ fn lookupDns( if (answers_remaining == 0) break :send; }, 2 => { - var retry_message: net.OutgoingMessage = .{ - .address = ns, - .data_ptr = query.ptr, - .data_len = query.len, + socket.sendTimeout(t_io, ns, query, timeout) catch |err| switch (err) { + error.Canceled => |e| return e, + error.Timeout => continue :send, + else => {}, }; - _ = netSendPosix(t, socket.handle, (&retry_message)[0..1], .{}, false); continue; }, else => continue, -- 2.54.0