From 1637c3352cfb9767c2ceb501e1f839455bf5faae Mon Sep 17 00:00:00 2001 From: Amr Gharbeia Date: Thu, 14 May 2026 08:53:16 -0400 Subject: [PATCH] fix: read-raw-byte checks poll result before unix-read The original code called unix-simple-poll then unconditionally called unix-read, ignoring the poll result. When poll returned nil (no data), unix-read would block indefinitely. Fixed by checking poll result: only read if poll says data is ready. --- src/components/input.lisp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/components/input.lisp b/src/components/input.lisp index 6e95a7d..ce237cc 100644 --- a/src/components/input.lisp +++ b/src/components/input.lisp @@ -74,9 +74,11 @@ (sb-sys:with-pinned-objects (buf) (let ((sap (sb-sys:vector-sap buf))) (if timeout-ms - (progn (sb-unix:unix-simple-poll fd :input timeout-ms) - (let ((n (sb-unix:unix-read fd sap 1))) - (if (= n 1) (aref buf 0) (values nil :eof)))) + ;; Poll first: only read if data is ready + (if (sb-unix:unix-simple-poll fd :input timeout-ms) + (let ((n (sb-unix:unix-read fd sap 1))) + (if (= n 1) (aref buf 0) (values nil :eof))) + nil) (let ((n (sb-unix:unix-read fd sap 1))) (if (= n 1) (aref buf 0) (values nil :eof))))))))