mirror of
https://github.com/ziglang/zig.git
synced 2026-01-20 14:25:16 +00:00
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:
parent
b2895f356f
commit
654a5b20d7
@ -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;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user