Skip to content

Commit

Permalink
fix: manually reschedule to avoid hang on macOS
Browse files Browse the repository at this point in the history
libxev's .rearm semantics are unfortunately not very
portable---rescheduling the exact same event on macOS / kqueue seems
to cause the event loop to hang, while manually rescheduling and
returning .disarm does not.
  • Loading branch information
robbielyman authored and rockorager committed May 31, 2024
1 parent 49cc8ae commit fbaa6ca
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/xev.zig
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ pub fn TtyWatcher(comptime Userdata: type) type {
buf: xev.ReadBuffer,
r: xev.ReadError!usize,
) xev.CallbackAction {
_ = c; // autofix
const n = r catch |err| {
log.err("read error: {}", .{err});
return .disarm;
Expand Down Expand Up @@ -230,13 +229,21 @@ pub fn TtyWatcher(comptime Userdata: type) type {
}
}

return .rearm;
self.file.read(
loop,
c,
.{ .slice = &self.read_buf },
Self,
self,
Self.ttyReadCallback,
);
return .disarm;
}

fn winsizeCallback(
ud: ?*Self,
l: *xev.Loop,
_: *xev.Completion,
c: *xev.Completion,
r: xev.Async.WaitError!void,
) xev.CallbackAction {
_ = r catch |err| {
Expand All @@ -248,7 +255,17 @@ pub fn TtyWatcher(comptime Userdata: type) type {
log.err("couldn't get winsize: {}", .{err});
return .disarm;
};
return self.callback(self.ud, l, self, .{ .winsize = winsize });
const ret = self.callback(self.ud, l, self, .{ .winsize = winsize });
if (ret == .disarm) return .disarm;

self.winsize_wakeup.wait(
l,
c,
Self,
self,
winsizeCallback,
);
return .disarm;
}
};
}

0 comments on commit fbaa6ca

Please sign in to comment.