mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-09 22:17:34 +02:00
Interleave reading/writing to subprocess in process-pipe-bytevector,
using u8-ready? to avoid blocking. Fixes issue #253.
This commit is contained in:
parent
aa3f869798
commit
4267164e92
1 changed files with 23 additions and 6 deletions
|
@ -17,12 +17,29 @@
|
|||
(call-with-process-io
|
||||
cmd
|
||||
(lambda (pid proc-in proc-out proc-err)
|
||||
;; This could overflow the pipe.
|
||||
(write-bytevector bvec proc-in)
|
||||
(close-output-port proc-in)
|
||||
(let ((res (port->bytevector proc-out)))
|
||||
(waitpid pid 0)
|
||||
res))))
|
||||
(let ((len (bytevector-length bvec))
|
||||
(out (open-output-bytevector)))
|
||||
(let lp ((i 0))
|
||||
(cond
|
||||
((u8-ready? proc-out)
|
||||
(let ((u8 (read-u8 proc-out)))
|
||||
(cond
|
||||
((eof-object? u8)
|
||||
(get-output-bytevector out))
|
||||
(else
|
||||
(write-u8 u8 out)
|
||||
(lp i)))))
|
||||
((< i len)
|
||||
(write-u8 (bytevector-u8-ref bvec i) proc-in)
|
||||
(if (= len (+ i 1))
|
||||
(close-output-port proc-in))
|
||||
(lp (+ i 1)))
|
||||
(else
|
||||
;; Once we've completed sending the input we busy wait
|
||||
;; until all output has been read. We can't just waitpid
|
||||
;; here because the remaining output may still overflow the
|
||||
;; pipe buffer.
|
||||
(lp i))))))))
|
||||
|
||||
;;> Gzip compress a string or bytevector in memory.
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue