Skip to content

Commit 654a5b2

Browse files
committed
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.
1 parent b2895f3 commit 654a5b2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/std/Io/net.zig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,13 @@ pub const Socket = struct {
11191119
/// * `receiveTimeout`
11201120
pub fn receive(s: *const Socket, io: Io, buffer: []u8) ReceiveError!IncomingMessage {
11211121
var message: IncomingMessage = undefined;
1122-
assert(1 == try io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, .none));
1122+
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, .none);
1123+
if (maybe_err) |err| switch (err) {
1124+
// No timeout is passed to `netReceieve`, so it must not return timeout related errors.
1125+
error.Timeout, error.UnsupportedClock => unreachable,
1126+
else => |e| return e,
1127+
};
1128+
assert(1 == count);
11231129
return message;
11241130
}
11251131

@@ -1139,7 +1145,9 @@ pub const Socket = struct {
11391145
timeout: Io.Timeout,
11401146
) ReceiveTimeoutError!IncomingMessage {
11411147
var message: IncomingMessage = undefined;
1142-
assert(1 == try io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, timeout));
1148+
const maybe_err, const count = io.vtable.netReceive(io.userdata, s.handle, (&message)[0..1], buffer, .{}, timeout);
1149+
if (maybe_err) |err| return err;
1150+
assert(1 == count);
11431151
return message;
11441152
}
11451153

0 commit comments

Comments
 (0)