fix: manually reschedule to avoid hang on macOS
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.
This commit is contained in:
parent
49cc8ae7c4
commit
fbaa6ca8df
1 changed files with 21 additions and 4 deletions
25
src/xev.zig
25
src/xev.zig
|
@ -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;
|
||||
|
@ -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| {
|
||||
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue