Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/html/window.zig
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,20 @@ pub const Window = struct {
if (self.timeoutid >= self.timeoutids.len) return error.TooMuchTimeout;

const ddelay: u63 = delay orelse 0;
const id = loop.timeout(ddelay * std.time.ns_per_ms, cbk);
const id = try loop.timeout(ddelay * std.time.ns_per_ms, cbk);

self.timeoutids[self.timeoutid] = id;
defer self.timeoutid += 1;

return self.timeoutid;
}

pub fn _clearTimeout(self: *Window, loop: *Loop, id: u32) void {
pub fn _clearTimeout(self: *Window, loop: *Loop, id: u32) !void {
// I do would prefer return an error in this case, but it seems some JS
// uses invalid id, in particular id 0.
// So we silently ignore invalid id for now.
if (id >= self.timeoutid) return;

loop.cancel(self.timeoutids[id], null);
try loop.cancel(self.timeoutids[id], null);
}
};
19 changes: 11 additions & 8 deletions src/http/client.zig
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ pub const Request = struct {
};
}

loop.connect(AsyncHandlerT, async_handler, &async_handler.read_completion, AsyncHandlerT.connected, socket, address);
try loop.connect(AsyncHandlerT, async_handler, &async_handler.read_completion, AsyncHandlerT.connected, socket, address);
}

// Does additional setup of the request for the firsts (i.e. non-redirect) call.
Expand Down Expand Up @@ -490,7 +490,6 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
}

fn connected(self: *Self, _: *IO.Completion, result: IO.ConnectError!void) void {
self.loop.onConnect(result);
result catch |err| return self.handleError("Connection failed", err);
self.connection.connected() catch |err| {
self.handleError("connected handler error", err);
Expand Down Expand Up @@ -518,11 +517,12 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
sent,
self.socket,
node.data,
);
) catch |err| {
self.handleError("loop send error", err);
};
}

fn sent(self: *Self, _: *IO.Completion, n_: IO.SendError!usize) void {
self.loop.onSend(n_);
const n = n_ catch |err| {
return self.handleError("Write error", err);
};
Expand All @@ -548,7 +548,9 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
sent,
self.socket,
next_.data,
);
) catch |err| {
self.handleError("loop send error", err);
};
return;
}

Expand All @@ -567,18 +569,19 @@ fn AsyncHandler(comptime H: type, comptime L: type) type {
}

self.is_receiving = true;
return self.loop.recv(
self.loop.recv(
Self,
self,
&self.read_completion,
Self.received,
self.socket,
self.read_buf[self.read_pos..],
);
) catch |err| {
self.handleError("loop recv error", err);
};
}

fn received(self: *Self, _: *IO.Completion, n_: IO.RecvError!usize) void {
self.loop.onRecv(n_);
self.is_receiving = false;
const n = n_ catch |err| {
return self.handleError("Read error", err);
Expand Down