From d8628d6698ae7e5d7b83069db947358abd2e3b84 Mon Sep 17 00:00:00 2001 From: Peter Bex Date: Sun, 29 Jul 2018 17:33:27 +0200 Subject: [PATCH] Restore read-string semantics when reading 0 bytes by not attempting to peek We accidentally changed this behaviour when we changed read-string to return #!eof on EOF. The code was slightly restructured under the assumption that calling peek-char will never hurt, and then return "" when asking for zero bytes. Logically, this is correct, but in some cases the FD might not be ready. In those cases you may run into a read timeout, but reading zero bytes should arguably always succeed immediately, regardless of port/FD state. --- extras.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/extras.scm b/extras.scm index bc04f161..ec504fc6 100644 --- a/extras.scm +++ b/extras.scm @@ -153,8 +153,8 @@ (define read-string/port (lambda (n p) - (cond ((eof-object? (##sys#peek-char-0 p)) - (if (eq? n 0) "" #!eof)) + (cond ((eq? n 0) "") ; Don't attempt to peek (fd might not be ready) + ((eof-object? (##sys#peek-char-0 p)) #!eof) (n (let* ((str (##sys#make-string n)) (n2 (read-string!/port n str p 0))) (if (eq? n n2) -- 2.11.0