From 20ed31fb30fdf40788a2443bf21d1d628cb78b18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kochma=C5=84ski?= Date: Thu, 7 Dec 2023 16:55:20 +0100 Subject: [PATCH] buffer-read-default: handle gracefully eof and partial reads When some data is read (but not all), return a non-NIL value: - :end-of-file when no data is read - :truncated when some (but not all) data is read This change in behavior was proposed and initially implemented by Alastair Bridgewater here: https://github.com/sharplispers/clx/pull/203. --- common.lisp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common.lisp b/common.lisp index 7450c72..f5c3d4b 100644 --- a/common.lisp +++ b/common.lisp @@ -13,16 +13,18 @@ (type array-index start end) (type (or null (real 0 *)) timeout)) #.(declare-buffun) - (cond ((and (not (null timeout)) - (zerop timeout) - (not (listen (display-input-stream display)))) - :timeout) - (t - (read-sequence vector - (display-input-stream display) - :start start - :end end) - nil))) + (if (and (not (null timeout)) + (zerop timeout) + (not (listen (display-input-stream display)))) + :timeout + (let ((n (read-sequence vector + (display-input-stream display) + :start start + :end end))) + (cond + ((= n end) nil) + ((= n start) :end-of-file) + (t :truncated))))) ;;; This is a legacy and obsolete fallback implementation. ;;;