Skip to content

Commit

Permalink
buffer-read-default: handle gracefully eof and partial reads
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dkochmanski committed Dec 7, 2023
1 parent 73c76e3 commit 20ed31f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions common.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
;;;
Expand Down

0 comments on commit 20ed31f

Please sign in to comment.