mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-22 07:09:18 +02:00
Binary-safe send-file.
This commit is contained in:
parent
46a8b11645
commit
7685d1f097
1 changed files with 7 additions and 6 deletions
|
@ -175,17 +175,18 @@
|
|||
(out (if (pair? o) (car o) (current-output-port)))
|
||||
(fd (if (port? in) (port-fileno in) in))
|
||||
(sock (if (port? out) (port-fileno out) out)))
|
||||
(define (copy-bytes)
|
||||
(let ((b (read-u8 in)))
|
||||
(cond ((not (eof-object? b))
|
||||
(write-u8 b out)
|
||||
(copy-bytes)))))
|
||||
(if (and fd sock (is-a-socket? sock))
|
||||
(let lp ((start 0))
|
||||
(let ((res (%send-file fd sock start)))
|
||||
(cond
|
||||
((not res) (lp start))
|
||||
((not res) (copy-bytes))
|
||||
((not (zero? res)) (lp (+ start res))))))
|
||||
(let lp ()
|
||||
(let ((str (read-string 8192 in)))
|
||||
(cond ((not (eof-object? str))
|
||||
(display str out)
|
||||
(lp))))))))
|
||||
(copy-bytes))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; higher order port operations
|
||||
|
|
Loading…
Add table
Reference in a new issue