Skip to content

Commit 20ed31f

Browse files
committed
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: #203.
1 parent 73c76e3 commit 20ed31f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

common.lisp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313
(type array-index start end)
1414
(type (or null (real 0 *)) timeout))
1515
#.(declare-buffun)
16-
(cond ((and (not (null timeout))
17-
(zerop timeout)
18-
(not (listen (display-input-stream display))))
19-
:timeout)
20-
(t
21-
(read-sequence vector
22-
(display-input-stream display)
23-
:start start
24-
:end end)
25-
nil)))
16+
(if (and (not (null timeout))
17+
(zerop timeout)
18+
(not (listen (display-input-stream display))))
19+
:timeout
20+
(let ((n (read-sequence vector
21+
(display-input-stream display)
22+
:start start
23+
:end end)))
24+
(cond
25+
((= n end) nil)
26+
((= n start) :end-of-file)
27+
(t :truncated)))))
2628

2729
;;; This is a legacy and obsolete fallback implementation.
2830
;;;

0 commit comments

Comments
 (0)