1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: nil -*-
3 ;;; --- fd-streams classes.
6 (in-package :io.streams
)
10 (deftype ub8
() '(unsigned-byte 8))
11 (deftype ub16
() '(unsigned-byte 16))
12 (deftype ub32
() '(unsigned-byte 32))
13 (deftype sb8
() '(signed-byte 8))
14 (deftype sb16
() '(signed-byte 16))
15 (deftype sb32
() '(signed-byte 32))
17 (deftype ub8-sarray
(&optional
(size '*))
18 `(simple-array ub8
(,size
)))
20 (deftype ub8-vector
() '(vector ub8
))
22 (deftype ub16-sarray
(&optional
(size '*))
23 `(simple-array ub16
(,size
)))
27 (deftype stream-buffer
() 'foreign-pointer
)
28 (deftype buffer-index
() '(unsigned-byte 24))
30 (defstruct (iobuf (:constructor %make-iobuf
()))
31 (data (null-pointer) :type stream-buffer
)
32 (size 0 :type buffer-index
)
33 (start 0 :type buffer-index
)
34 (end 0 :type buffer-index
))
36 ;;;; File-Descriptor Mixins
38 (deftype stream-position
() '(unsigned-byte 64))
40 (defun default-read-fn (fd buf nbytes
)
41 (nix:read fd buf nbytes
))
43 (defun default-write-fn (fd buf nbytes
)
44 (nix:write fd buf nbytes
))
46 (defclass dual-channel-fd-mixin
()
47 ((input-fd :initform nil
:initarg
:input-fd
:accessor input-fd-of
48 :documentation
"placeholder")
49 (read-fn :initform
'default-read-fn
:initarg
:read-fn
:accessor read-fn-of
)
50 (output-fd :initform nil
:initarg
:output-fd
:accessor output-fd-of
51 :documentation
"placeholder")
52 (write-fn :initform
'default-write-fn
:initarg
:write-fn
:accessor write-fn-of
))
53 (:documentation
"placeholder"))
55 (defgeneric input-fd-non-blocking
(socket)
56 (:documentation
"placeholder"))
58 (defgeneric (setf input-fd-non-blocking
) (mode fd-mixin
))
60 (defgeneric output-fd-non-blocking
(socket)
61 (:documentation
"placeholder"))
63 (defgeneric (setf output-fd-non-blocking
) (mode fd-mixin
))
65 (defclass dual-channel-single-fd-mixin
(dual-channel-fd-mixin)
67 (:documentation
"placeholder"))
69 (defgeneric fd-of
(stream)
70 (:documentation
"placeholder")
71 (:method
((stream dual-channel-single-fd-mixin
))
72 (with-accessors ((fd-in input-fd-of
)
73 (fd-out output-fd-of
)) stream
74 (assert (eql fd-in fd-out
) (fd-in fd-out
)
75 "Input and output FDs must be equal: ~A, ~A" fd-in fd-out
)
78 (defgeneric (setf fd-of
) (fd stream
)
79 (:documentation
"placeholder")
80 (:method
(fd (stream dual-channel-single-fd-mixin
))
81 (with-accessors ((fd-in input-fd-of
)
82 (fd-out output-fd-of
)) stream
83 (setf fd-in fd fd-out fd
)
86 (defgeneric fd-non-blocking
(fd-mixin)
87 (:documentation
"placeholder"))
89 (defgeneric (setf fd-non-blocking
) (mode fd-mixin
))
91 ;;;; Bivalent Socket Gray Stream
93 (defclass dual-channel-gray-stream
(trivial-gray-stream-mixin
95 fundamental-binary-input-stream
96 fundamental-binary-output-stream
97 fundamental-character-input-stream
98 fundamental-character-output-stream
)
99 ((external-format :initform
:default
:initarg
:external-format
100 :reader external-format-of
101 :documentation
"placehold")
103 (input-buffer :initform nil
:type
(or iobuf null
)
104 :accessor input-buffer-of
)
106 (output-buffer :initform nil
:type
(or iobuf null
)
107 :accessor output-buffer-of
)
108 ;; Flag used by stream-force-output.
109 (dirty :initform nil
:type boolean
:accessor dirtyp
)
110 ;; Last read char buffer index.
111 (ibuf-unread-index :initform
0 :type buffer-index
112 :accessor ibuf-unread-index-of
))
113 (:documentation
"placeholder"))
115 (defgeneric (setf external-format-of
) (external-format stream
)
116 (:documentation
"placeholder"))
118 (defgeneric drain-input-buffer
(stream sequence
&key start end
)
121 (defgeneric input-buffer-size
(stream)
124 (defgeneric input-buffer-empty-p
(stream)
127 (defgeneric output-buffer-size
(stream)
130 (defgeneric output-buffer-empty-p
(stream)
133 (defclass dual-channel-single-fd-gray-stream
134 (dual-channel-gray-stream dual-channel-single-fd-mixin
)
136 (:documentation
"placeholder"))