Io: fix compile error in receive and receiveTimeout

Correctly uses the `netReceive` API. If an error was
returned, we propagate that error, otherwise assert
we only received one message.
This commit is contained in:
David Rubin 2025-11-06 10:29:42 -08:00
parent b2895f356f
commit 654a5b20d7
No known key found for this signature in database
GPG Key ID: 5CF5B5A4747520AA

View File

@ -1119,7 +1119,13 @@ pub const Socket = struct {
/// * `receiveTimeout`
pub fn receive(s: *const Socket, io: Io, buffer: []u8) ReceiveError!IncomingMessage {
var message: IncomingMessage = undefined;
assert(1 == try io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, .none));
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, .none);
if (maybe_err) |err| switch (err) {
// No timeout is passed to `netReceieve`, so it must not return timeout related errors.
error.Timeout, error.UnsupportedClock => unreachable,
else => |e| return e,
};
assert(1 == count);
return message;
}
@ -1139,7 +1145,9 @@ pub const Socket = struct {
timeout: Io.Timeout,
) ReceiveTimeoutError!IncomingMessage {
var message: IncomingMessage = undefined;
assert(1 == try io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, timeout));
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, timeout);
if (maybe_err) |err| return err;
assert(1 == count);
return message;
}