Skip to content

Commit

Permalink
Use i32 instead of u32 for timeout
Browse files Browse the repository at this point in the history
Fixes:
#35
  • Loading branch information
karlseguin committed Feb 1, 2024
1 parent 96e825c commit 2f10439
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/worker.zig
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ const Manager = struct {
}

// Enforces timeouts, and returs when the next timeout should be checked.
fn prepreToWait(self: *Manager) ?u32 {
fn prepreToWait(self: *Manager) ?i32 {
const now = timestamp();
const next_active = self.enforceTimeout(self.active_list, now);
const next_keepalive = self.enforceTimeout(self.keepalive_list, now);
Expand All @@ -624,7 +624,7 @@ const Manager = struct {
return 1;
}

return next - now;
return @intCast(next - now);
}

// lists are ordered from soonest to timeout to latest, as soon as we find
Expand Down Expand Up @@ -892,7 +892,7 @@ const KQueue = struct {
self.change_count = change_count + 1;
}

fn wait(self: *KQueue, timeout_sec: ?u32) !Iterator {
fn wait(self: *KQueue, timeout_sec: ?i32) !Iterator {
const event_list = &self.event_list;
const timeout: ?os.timespec = if (timeout_sec) |ts| os.timespec{ .tv_sec = ts, .tv_nsec = 0 } else null;
const event_count = try std.os.kevent(self.q, self.change_buffer[0..self.change_count], event_list, if (timeout) |ts| &ts else null);
Expand Down Expand Up @@ -956,15 +956,15 @@ const EPoll = struct {
return std.os.epoll_ctl(self.q, os.linux.EPOLL.CTL_DEL, fd, null);
}

fn wait(self: *EPoll, timeout_sec: ?u32) !Iterator {
fn wait(self: *EPoll, timeout_sec: ?i32) !Iterator {
const event_list = &self.event_list;
const event_count = blk: while (true) {
const rc = os.linux.syscall6(
.epoll_pwait2,
@as(usize, @bitCast(@as(isize, self.q))),
@intFromPtr(event_list.ptr),
event_list.len,
if (timeout_sec) |ts| @intFromPtr(&os.timespec{ .tv_sec = ts, .tv_nsec = 0 }) else 0,
if (timeout_sec) |ts| @intFromPtr(&os.timespec{ .tv_sec = @intCast(ts), .tv_nsec = 0 }) else 0,
0,
@sizeOf(os.linux.sigset_t),
);
Expand Down

0 comments on commit 2f10439

Please sign in to comment.