diff --git a/fd-gray.lisp b/fd-gray.lisp
index 686eca7..5fb833d 100644
--- a/fd-gray.lisp
+++ b/fd-gray.lisp
@@ -29,23 +29,23 @@
:reader stream-fd
:type file-descriptor)
(blocking :initarg :blocking
- :accessor stream-blocking%
- :type boolean)))
+ :accessor stream-blocking%
+ :type boolean)))
(defgeneric stream-blocking (stream))
(defmethod stream-blocking ((stream stream))
(or (and (slot-boundp stream 'blocking)
- (slot-value stream 'blocking))
+ (slot-value stream 'blocking))
(setf (slot-value stream 'blocking)
- (let ((flags (fcntl:getfl (stream-fd stream))))
- (not (= 0 (logand fcntl:+o-nonblock+ flags)))))))
+ (let ((flags (fcntl:getfl (stream-fd stream))))
+ (not (= 0 (logand fcntl:+o-nonblock+ flags)))))))
(defgeneric (setf stream-blocking) (value stream))
(defmethod (setf stream-blocking) (value (stream stream))
(let* ((fd (stream-fd stream))
- (flags (fcntl:getfl fd)))
+ (flags (fcntl:getfl fd)))
(cond
((and value (not (= 0 (logand fcntl:+o-nonblock+ flags))))
t)
@@ -53,8 +53,8 @@
nil)
(t
(fcntl:setfl fd (if value
- (logand (lognot fcntl:+o-nonblock+) flags)
- (logior fcntl:+o-nonblock+ flags)))
+ (logand (lognot fcntl:+o-nonblock+) flags)
+ (logior fcntl:+o-nonblock+ flags)))
(setf (slot-value stream 'blocking) value)))))
(define-condition stream-error (cl:stream-error)
@@ -85,17 +85,17 @@ to read from or write to a closed fd gray stream."))
(defclass input-stream (stream fundamental-binary-input-stream)
((input-buffer :initform (cffi:foreign-alloc :unsigned-char
- :count *buffer-size*)
- :accessor input-buffer)
+ :count *buffer-size*)
+ :accessor input-buffer)
(input-index :initform 0
- :accessor input-index
- :type fixnum+)
+ :accessor input-index
+ :type fixnum+)
(input-length :initform 0
- :accessor input-length
- :type fixnum+)
+ :accessor input-length
+ :type fixnum+)
(input-max :initform *buffer-size*
- :reader input-max
- :type fixnum+)))
+ :reader input-max
+ :type fixnum+)))
(define-condition stream-input-error (stream-error)
()
@@ -111,58 +111,58 @@ on a fd gray stream."))
"Fill buffer with file data.
Tries to read once from input-length to input-max (end of buffer)."
(let* ((buffer (input-buffer stream))
- (length (input-length stream))
- (fd (stream-fd stream))
- (buf (cffi:mem-aptr buffer :unsigned-char length))
- (buflen (- (input-max stream) length))
- (r (if (stream-blocking stream)
- (unistd:read fd buf buflen)
- (unistd:read-non-blocking fd buf buflen))))
+ (length (input-length stream))
+ (fd (stream-fd stream))
+ (buf (cffi:mem-aptr buffer :unsigned-char length))
+ (buflen (- (input-max stream) length))
+ (r (if (stream-blocking stream)
+ (unistd:read fd buf buflen)
+ (unistd:read-non-blocking fd buf buflen))))
(cond ((null r)
- nil)
- ((= r 0)
- :eof)
- ((< r 0)
- (error 'stream-input-error :stream stream))
- (t
- (incf (input-length stream) r)
- r))))
+ nil)
+ ((= r 0)
+ :eof)
+ ((< r 0)
+ (error 'stream-input-error :stream stream))
+ (t
+ (incf (input-length stream) r)
+ r))))
(defmethod stream-read-byte ((stream input-stream))
(check-if-open stream)
(let ((buffer (input-buffer stream)))
(with-accessors ((input-index input-index)) stream
(when (= input-index (input-length stream))
- (setf input-index 0
- (input-length stream) 0)
- (case (stream-input stream)
- ((:eof) (return-from stream-read-byte :eof))
- ((nil) (return-from stream-read-byte nil))))
+ (setf input-index 0
+ (input-length stream) 0)
+ (case (stream-input stream)
+ ((:eof) (return-from stream-read-byte :eof))
+ ((nil) (return-from stream-read-byte nil))))
(let ((b (cffi:mem-aref buffer :unsigned-char input-index)))
- (incf input-index)
- b))))
+ (incf input-index)
+ b))))
(defmethod stream-read-sequence ((stream input-stream)
- seq start end &key &allow-other-keys)
+ seq start end &key &allow-other-keys)
(check-if-open stream)
(let ((buffer (input-buffer stream)))
(with-accessors ((input-index input-index)) stream
(loop
- (unless (< start end)
- (return))
- (let ((e (min (- end start)
- (- (input-length stream) input-index))))
- (dotimes (i e)
- (setf (aref seq start)
- (cffi:mem-aref buffer :unsigned-char input-index))
- (incf start)
- (incf input-index))
- (when (= input-index (input-length stream))
- (setf input-index 0
- (input-length buffer) 0)
- (case (stream-input stream)
- ((:eof) (return-from stream-read-sequence :eof))
- ((nil) (return-from stream-read-sequence nil)))))))))
+ (unless (< start end)
+ (return))
+ (let ((e (min (- end start)
+ (- (input-length stream) input-index))))
+ (dotimes (i e)
+ (setf (aref seq start)
+ (cffi:mem-aref buffer :unsigned-char input-index))
+ (incf start)
+ (incf input-index))
+ (when (= input-index (input-length stream))
+ (setf input-index 0
+ (input-length buffer) 0)
+ (case (stream-input stream)
+ ((:eof) (return-from stream-read-sequence :eof))
+ ((nil) (return-from stream-read-sequence nil)))))))))
(defmethod close ((stream input-stream) &key abort)
(declare (ignore abort))
@@ -177,8 +177,8 @@ Tries to read once from input-length to input-max (end of buffer)."
(let ((stream (gensym "STREAM-")))
`(let ((,stream (input-stream ,fd)))
(unwind-protect (let ((,var ,stream))
- ,@body)
- (close ,stream)))))
+ ,@body)
+ (close ,stream)))))
(define-condition stream-output-error (stream-error)
()
@@ -190,17 +190,17 @@ on a fd gray stream."))
(defclass output-stream (stream fundamental-binary-output-stream)
((output-buffer :initform (cffi:foreign-alloc :unsigned-char
- :count *buffer-size*)
- :accessor output-buffer)
+ :count *buffer-size*)
+ :accessor output-buffer)
(output-index :initform 0
- :accessor output-index
- :type fixnum+)
+ :accessor output-index
+ :type fixnum+)
(output-length :initform 0
- :accessor output-length
- :type fixnum+)
+ :accessor output-length
+ :type fixnum+)
(output-max :initform *buffer-size*
- :reader output-max
- :type fixnum+)))
+ :reader output-max
+ :type fixnum+)))
(defgeneric stream-output (stream))
@@ -210,22 +210,22 @@ Calls write with data ranging from output-index to output-length."
(let ((buffer (output-buffer stream)))
(with-accessors ((output-index output-index)) stream
(let* ((fd (stream-fd stream))
- (buf (cffi:mem-aptr buffer :unsigned-char output-index))
- (buflen (- (output-length stream) output-index))
- (r (if (stream-blocking stream)
- (unistd:write fd buf buflen)
- (unistd:write-non-blocking fd buf buflen))))
- (cond ((null r)
- (return-from stream-output nil))
- ((= 0 r)
- (return-from stream-output :eof))
- ((< r 0)
- (error 'stream-output-error :stream stream))
- (t
- (incf output-index r)
- (when (= output-index (output-length stream))
- (setf output-index 0
- (output-length stream) 0))))))))
+ (buf (cffi:mem-aptr buffer :unsigned-char output-index))
+ (buflen (- (output-length stream) output-index))
+ (r (if (stream-blocking stream)
+ (unistd:write fd buf buflen)
+ (unistd:write-non-blocking fd buf buflen))))
+ (cond ((null r)
+ (return-from stream-output nil))
+ ((= 0 r)
+ (return-from stream-output :eof))
+ ((< r 0)
+ (error 'stream-output-error :stream stream))
+ (t
+ (incf output-index r)
+ (when (= output-index (output-length stream))
+ (setf output-index 0
+ (output-length stream) 0))))))))
(defmethod stream-force-output ((stream output-stream))
(stream-output stream))
@@ -241,28 +241,28 @@ Calls write with data ranging from output-index to output-length."
(let ((buffer (output-buffer stream)))
(when (= (output-length stream) (output-max stream))
(let ((r (stream-output stream)))
- (cond ((null r)
- ))))
+ (cond ((null r)
+ ))))
(setf (cffi:mem-aref buffer :unsigned-char (input-length stream)) byte)
(incf (input-length stream)))
byte)
(defmethod stream-write-sequence ((stream output-stream)
- seq start end &key &allow-other-keys)
+ seq start end &key &allow-other-keys)
(check-if-open stream)
(let ((buffer (output-buffer stream)))
(loop
(unless (< start end)
- (return))
+ (return))
(let ((e (min (- end start)
- (- (output-max stream) (output-length stream)))))
- (dotimes (i e)
- (setf (cffi:mem-aref buffer :unsigned-char (output-length stream))
- (aref seq start))
- (incf (output-length stream))
- (incf start))
- (when (= (output-length stream) (output-max stream))
- (stream-finish-output stream))))))
+ (- (output-max stream) (output-length stream)))))
+ (dotimes (i e)
+ (setf (cffi:mem-aref buffer :unsigned-char (output-length stream))
+ (aref seq start))
+ (incf (output-length stream))
+ (incf start))
+ (when (= (output-length stream) (output-max stream))
+ (stream-finish-output stream))))))
(defmethod close ((stream output-stream) &key abort)
(declare (ignore abort))
@@ -278,8 +278,8 @@ Calls write with data ranging from output-index to output-length."
(let ((stream (gensym "STREAM-")))
`(let ((,stream (output-stream ,fd)))
(unwind-protect (let ((,var ,stream))
- ,@body)
- (close ,stream)))))
+ ,@body)
+ (close ,stream)))))
(defclass io-stream (input-stream output-stream)
())
@@ -300,5 +300,5 @@ Calls write with data ranging from output-index to output-length."
(let ((stream (gensym "STREAM-")))
`(let ((,stream (io-stream ,fd)))
(unwind-protect (let ((,var ,stream))
- ,@body)
- (close ,stream)))))
+ ,@body)
+ (close ,stream)))))