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.
This commit is contained in:
2026-05-14 08:53:16 -04:00
parent 07cea571ef
commit 1637c3352c

View File

@@ -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)
;; 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))))
(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))))))))