From fbaa6ca8dfc4e6904fb98f3fee48604de3b21ae6 Mon Sep 17 00:00:00 2001 From: Rylee Lyman Date: Fri, 31 May 2024 08:02:29 -0400 Subject: [PATCH] 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. --- src/xev.zig | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/xev.zig b/src/xev.zig index 84f7e0f..b03c89c 100644 --- a/src/xev.zig +++ b/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; } }; }