racket/port: fix busy-wait bug in make-limited-input-port

As reported by Marc Burns on the mailing list
This commit is contained in:
Matthew Flatt 2014-09-04 12:20:42 +02:00
parent c9a11c4ee4
commit 59fac3d38a
2 changed files with 17 additions and 1 deletions

View File

@ -649,6 +649,18 @@
(test 2 peek-bytes-avail!* b 0 #f s)
(test 1 peek-bytes-avail!* b 1 #f s)
(test 2 read-bytes-avail!* b s))))
;; Make sure that blocking on a limited input port doesn't
;; block in the case of a peek after available bytes:
(let ()
(define-values (i o) (make-pipe))
(write-char #\a o)
(write-char #\a o)
(thread (lambda ()
(sync (system-idle-evt))
(write-char #\b o)))
(test 1 peek-bytes-avail! (make-bytes 1) 2 #f (make-limited-input-port i 10)))
;; ----------------------------------------
;; Conversion wrappers

View File

@ -1035,7 +1035,11 @@
(if (eq? n 0)
(if (and progress-evt (sync/timeout 0 progress-evt))
#f
(wrap-evt port (lambda (x) 0)))
(wrap-evt (if (zero? skip)
port
(choice-evt (or progress-evt never-evt)
(peek-bytes-evt 1 skip progress-evt port)))
(lambda (x) 0)))
n)))))
(define (try-again)
(wrap-evt