mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 22:35:24 +00:00
std.Io.net: make it easier to use netReceiveMany correctly
This commit is contained in:
parent
c87fbd5878
commit
ecdc00466c
@ -5009,7 +5009,7 @@ fn lookupDns(
|
||||
} };
|
||||
|
||||
while (true) {
|
||||
var message_buffer: [max_messages]Io.net.IncomingMessage = undefined;
|
||||
var message_buffer: [max_messages]Io.net.IncomingMessage = @splat(.init);
|
||||
const buf = answer_buffer[answer_buffer_i..];
|
||||
const recv_err, const recv_n = socket.receiveManyTimeout(t_io, &message_buffer, buf, .{}, timeout);
|
||||
for (message_buffer[0..recv_n]) |*received_message| {
|
||||
|
||||
@ -904,10 +904,18 @@ pub const IncomingMessage = struct {
|
||||
data: []u8,
|
||||
/// Supplied by caller before calling receive functions; mutated by receive
|
||||
/// functions.
|
||||
control: []u8 = &.{},
|
||||
control: []u8,
|
||||
/// Populated by receive functions.
|
||||
flags: Flags,
|
||||
|
||||
/// Useful for initializing before calling `receiveManyTimeout`.
|
||||
pub const init: IncomingMessage = .{
|
||||
.from = undefined,
|
||||
.data = undefined,
|
||||
.control = &.{},
|
||||
.flags = undefined,
|
||||
};
|
||||
|
||||
pub const Flags = packed struct(u8) {
|
||||
/// indicates end-of-record; the data returned completed a record
|
||||
/// (generally used with sockets of type SOCK_SEQPACKET).
|
||||
@ -1146,6 +1154,8 @@ pub const Socket = struct {
|
||||
pub fn receiveManyTimeout(
|
||||
s: *const Socket,
|
||||
io: Io,
|
||||
/// Function assumes each element has initialized `control` field.
|
||||
/// Initializing with `IncomingMessage.init` may be helpful.
|
||||
message_buffer: []IncomingMessage,
|
||||
data_buffer: []u8,
|
||||
flags: ReceiveFlags,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user