authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-23 20:33:34-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:51-07:00
logecdc00466c34424ec8467d05efe0421f868c739a
tree69c4874db516beacd20388640ab70314ac92a433
parentc87fbd58787823da6db48e0bc488b5344fe52d43

std.Io.net: make it easier to use netReceiveMany correctly


2 files changed, 12 insertions(+), 2 deletions(-)

lib/std/Io/Threaded.zig+1-1
......@@ -5009,7 +5009,7 @@ fn lookupDns(
50095009 } };
50105010
50115011 while (true) {
5012 var message_buffer: [max_messages]Io.net.IncomingMessage = undefined;
5012 var message_buffer: [max_messages]Io.net.IncomingMessage = @splat(.init);
50135013 const buf = answer_buffer[answer_buffer_i..];
50145014 const recv_err, const recv_n = socket.receiveManyTimeout(t_io, &message_buffer, buf, .{}, timeout);
50155015 for (message_buffer[0..recv_n]) |*received_message| {
lib/std/Io/net.zig+11-1
......@@ -904,10 +904,18 @@ pub const IncomingMessage = struct {
904904 data: []u8,
905905 /// Supplied by caller before calling receive functions; mutated by receive
906906 /// functions.
907 control: []u8 = &.{},
907 control: []u8,
908908 /// Populated by receive functions.
909909 flags: Flags,
910910
911 /// Useful for initializing before calling `receiveManyTimeout`.
912 pub const init: IncomingMessage = .{
913 .from = undefined,
914 .data = undefined,
915 .control = &.{},
916 .flags = undefined,
917 };
918
911919 pub const Flags = packed struct(u8) {
912920 /// indicates end-of-record; the data returned completed a record
913921 /// (generally used with sockets of type SOCK_SEQPACKET).
......@@ -1146,6 +1154,8 @@ pub const Socket = struct {
11461154 pub fn receiveManyTimeout(
11471155 s: *const Socket,
11481156 io: Io,
1157 /// Function assumes each element has initialized `control` field.
1158 /// Initializing with `IncomingMessage.init` may be helpful.
11491159 message_buffer: []IncomingMessage,
11501160 data_buffer: []u8,
11511161 flags: ReceiveFlags,