From 456161cfef8899161c46836fed31509e1abb3a1f Mon Sep 17 00:00:00 2001 From: Stelian Ionescu Date: Sun, 2 Mar 2008 17:46:20 +0100 Subject: [PATCH] Added READ-BUFFER-SIZE, READ-BUFFER-EMPTY-P, WRITE-BUFFER-SIZE, WRITE-BUFFER-EMPTY-P and DRAIN-INPUT-BUFFER. Signed-off-by: Stelian Ionescu --- io.streams/gray/classes.lisp | 15 +++++++++++++++ io.streams/gray/gray-stream-methods.lisp | 29 +++++++++++++++++++++++++++++ io.streams/gray/pkgdcl.lisp | 5 +++++ 3 files changed, 49 insertions(+) diff --git a/io.streams/gray/classes.lisp b/io.streams/gray/classes.lisp index 58684e7..38453d3 100644 --- a/io.streams/gray/classes.lisp +++ b/io.streams/gray/classes.lisp @@ -133,6 +133,21 @@ (defgeneric (setf external-format-of) (external-format stream) (:documentation "placeholder")) +(defgeneric drain-input-buffer (stream sequence &key start end) + (:documentation "")) + +(defgeneric read-buffer-size (stream) + (:documentation "")) + +(defgeneric read-buffer-empty-p (stream) + (:documentation "")) + +(defgeneric write-buffer-size (stream) + (:documentation "")) + +(defgeneric write-buffer-empty-p (stream) + (:documentation "")) + (defclass dual-channel-single-fd-gray-stream (dual-channel-gray-stream dual-channel-single-fd-mixin) () diff --git a/io.streams/gray/gray-stream-methods.lisp b/io.streams/gray/gray-stream-methods.lisp index f77d507..ded7d6a 100644 --- a/io.streams/gray/gray-stream-methods.lisp +++ b/io.streams/gray/gray-stream-methods.lisp @@ -160,6 +160,21 @@ ((stream dual-channel-gray-stream) sequence start end &key) (%read-sequence stream sequence start end)) +(defmethod drain-input-buffer + ((stream dual-channel-gray-stream) sequence &key (start 0) end) + (check-bounds sequence start end) + (with-accessors ((ib input-buffer-of)) + stream + (let ((nbytes (min (- end start) + (iobuf-length ib)))) + (iobuf-copy-into-lisp-array ib (iobuf-start ib) + sequence start + nbytes) + (incf (iobuf-start ib) nbytes) + (let ((len (iobuf-length ib))) + (values (+ start nbytes) + (and (plusp len) len)))))) + ;;;; Output Methods (defun %write-n-bytes (write-fn fd buf nbytes &optional timeout) @@ -548,3 +563,17 @@ stream (%flush-obuf-if-needed stream) (iobuf-push-octet ob integer))) + +;;;; Buffer-related stuff + +(defmethod input-buffer-size ((stream dual-channel-gray-stream)) + (iobuf-length (input-buffer-of stream))) + +(defmethod input-buffer-empty-p ((stream dual-channel-gray-stream)) + (iobuf-empty-p (input-buffer-of stream))) + +(defmethod output-buffer-size ((stream dual-channel-gray-stream)) + (iobuf-length (output-buffer-of stream))) + +(defmethod output-buffer-empty-p ((stream dual-channel-gray-stream)) + (iobuf-empty-p (output-buffer-of stream))) diff --git a/io.streams/gray/pkgdcl.lisp b/io.streams/gray/pkgdcl.lisp index 6533f03..3293e96 100644 --- a/io.streams/gray/pkgdcl.lisp +++ b/io.streams/gray/pkgdcl.lisp @@ -51,7 +51,12 @@ #:input-fd-of #:output-fd-non-blocking #:output-fd-of + #:read-buffer-size + #:read-buffer-empty-p + #:write-buffer-size + #:write-buffer-empty-p #:read-sequence* #:write-sequence* + #:drain-input-buffer )) -- 2.11.4.GIT