(define (flush-binary-output-port port)
(flush-output-buffer (check-output-port port 'flush-output-port)))
+(define (synchronize-binary-output-port port)
+ (synchronize-output-buffer (check-output-port port 'synchronize-output-port)))
+
(define (binary-output-port-buffered-byte-count port)
(let ((ob (check-output-port port 'output-port-buffered-byte-count)))
(fix:- (buffer-end ob) (buffer-start ob))))
(set-buffer-end! ob (fix:- be bi))
bi)
(else n))))))
-
+\f
(define (flush-output-buffer ob)
+ (if (fix:< (buffer-start ob) (buffer-end ob))
+ (let ((channel (buffer-channel ob))
+ (do-flush (lambda () (%flush-output-buffer ob))))
+ (if channel
+ (with-channel-blocking channel #t do-flush)
+ (do-flush)))))
+
+(define (%flush-output-buffer ob)
(let ((bv (buffer-bytes ob))
(bs (buffer-start ob))
(be (buffer-end ob))
(bytevector-length bv))))
(fix:- bi bs))))
0)))
+
+(define (synchronize-output-buffer ob)
+ (flush-output-buffer ob)
+ (let ((oc (buffer-channel ob)))
+ (if oc
+ (channel-synchronize oc))))
\f
;;;; Buffers
(else generic-type11)))))
(define (generic-i/o-port->binary-port port)
- (or (let ((ib (port-input-buffer port)))
- (and ib
- (input-buffer-binary-port ib)))
- (output-buffer-binary-port (port-output-buffer port))))
+ (if (port-input-buffer port)
+ (input-port->binary-port port)
+ (output-port->binary-port port)))
+
+(define (input-port->binary-port port)
+ (input-buffer-binary-port (port-input-buffer port)))
+
+(define (output-port->binary-port port)
+ (output-buffer-binary-port (port-output-buffer port)))
\f
(define (make-gstate source sink coder-name normalizer-name caller . extra)
(let ((binary-port (make-binary-port source sink caller)))
(if (not ib)
(error:bad-range-argument port #f))
(input-buffer-channel ib)))
+
+(define (generic-io/buffer-contents port)
+ (binary-input-port-buffer-contents (input-port->binary-port port)))
+
+(define (generic-io/set-buffer-contents port contents)
+ (set-binary-input-port-buffer-contents! (input-port->binary-port port)
+ contents))
\f
;;;; Output operations
(fix:- end start)))))
(define (generic-io/flush-output port)
- (flush-output-buffer (port-output-buffer port)))
+ (flush-binary-output-port (output-port->binary-port port)))
(define (generic-io/output-column port)
(output-buffer-column (port-output-buffer port)))
(output-buffer-channel ob)))
(define (generic-io/synchronize-output port)
- (let ((channel (generic-io/output-channel port)))
- (if channel
- (channel-synchronize channel))))
+ (synchronize-binary-output-port (output-port->binary-port port)))
(define (generic-io/buffered-output-bytes port)
- (binary-output-port-buffered-byte-count
- (output-buffer-binary-port (port-output-buffer port))))
+ (binary-output-port-buffered-byte-count (output-port->binary-port port)))
(define (generic-io/bytes-written port)
(output-buffer-total (port-output-buffer port)))
(ob (close-binary-output-port (output-buffer-binary-port ob))))))
(define (generic-io/close-input port)
- (close-binary-input-port
- (input-buffer-binary-port (port-input-buffer port))))
+ (close-binary-input-port (input-port->binary-port port)))
(define (generic-io/close-output port)
- (close-binary-output-port
- (output-buffer-binary-port (port-output-buffer port))))
+ (close-binary-output-port (output-port->binary-port port)))
(define (generic-io/open? port)
(and (let ((ib (port-input-buffer port)))
(define (input-buffer-at-eof? ib)
(binary-input-port-at-eof? (input-buffer-binary-port ib)))
\f
-(define (generic-io/buffer-contents port)
- (binary-input-port-buffer-contents
- (input-buffer-binary-port (port-input-buffer port))))
-
-(define (generic-io/set-buffer-contents port contents)
- (set-binary-input-port-buffer-contents!
- (input-buffer-binary-port (port-input-buffer port))
- contents))
-
;; Next two for use only in normalizers.
(define (decode-char ib)
(define (%output-buffer-sink ob)
(binary-output-port-sink (output-buffer-binary-port ob)))
-
-(define (flush-output-buffer ob)
- (let ((channel (output-buffer-channel ob))
- (do-flush
- (lambda ()
- (flush-binary-output-port (output-buffer-binary-port ob)))))
- (if channel
- (with-channel-blocking channel #t do-flush)
- (do-flush))))
\f
;; Returns >0 if the character was written in its entirety.
;; Returns 0 if the character wasn't written at all.