1 ;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp -*-
3 ;; Copyright (C) 2006, 2007 Stelian Ionescu
5 ;; This code is free software; you can redistribute it and/or
6 ;; modify it under the terms of the version 2.1 of
7 ;; the GNU Lesser General Public License as published by
8 ;; the Free Software Foundation, as clarified by the
9 ;; preamble found here:
10 ;; http://opensource.franz.com/preamble.html
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU Lesser General
18 ;; Public License along with this library; if not, write to the
19 ;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA
22 (in-package :io.streams
)
30 (deftype ub8
() `(unsigned-byte 8))
31 (deftype ub16
() `(unsigned-byte 16))
32 (deftype ub32
() `(unsigned-byte 32))
33 (deftype sb8
() `(signed-byte 8))
34 (deftype sb16
() `(signed-byte 16))
35 (deftype sb32
() `(signed-byte 32))
37 (deftype ub8-sarray
(&optional
(size '*))
38 `(simple-array ub8
(,size
)))
39 (deftype ub8-vector
()
41 (deftype ub16-sarray
(&optional
(size '*))
42 `(simple-array ub16
(,size
)))
45 ;;;;;;;;;;;;;;;;;;;;;;
47 ;;; Socket buffers ;;;
49 ;;;;;;;;;;;;;;;;;;;;;;
51 (deftype stream-buffer
()
54 (deftype buffer-index
()
58 (:constructor %make-iobuf
()))
59 (data (null-pointer) :type stream-buffer
)
60 (size 0 :type buffer-index
)
61 (start 0 :type buffer-index
)
62 (end 0 :type buffer-index
))
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
66 ;;; File-Descriptor Mixins ;;;
68 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
70 (deftype stream-position
()
73 (defclass dual-channel-fd-mixin
()
74 ((input-fd :initform nil
:accessor input-fd-of
)
75 (output-fd :initform nil
:accessor output-fd-of
)))
77 (defgeneric input-fd-non-blocking
(socket))
78 (defgeneric (setf input-fd-non-blocking
) (mode fd-mixin
))
80 (defgeneric output-fd-non-blocking
(socket))
81 (defgeneric (setf output-fd-non-blocking
) (mode fd-mixin
))
84 (defclass dual-channel-single-fd-mixin
(dual-channel-fd-mixin) ())
86 (defgeneric fd-of
(stream)
87 (:method
((stream dual-channel-single-fd-mixin
))
88 (with-accessors ((fd-in input-fd-of
)
89 (fd-out output-fd-of
)) stream
90 (assert (eql fd-in fd-out
))
92 (defgeneric (setf fd-of
) (fd stream
)
93 (:method
(fd (stream dual-channel-single-fd-mixin
))
94 (with-accessors ((fd-in input-fd-of
)
95 (fd-out output-fd-of
)) stream
96 (assert (eql fd-in fd-out
))
97 (setf fd-in fd fd-out fd
)
100 (defgeneric fd-non-blocking
(fd-mixin))
101 (defgeneric (setf fd-non-blocking
) (mode fd-mixin
))
103 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
105 ;;; Bivalent socket Gray stream ;;;
107 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
109 (defclass dual-channel-gray-stream
(dual-channel-fd-mixin
110 fundamental-binary-input-stream
111 fundamental-binary-output-stream
112 fundamental-character-input-stream
113 fundamental-character-output-stream
)
114 ((external-format :initarg
:external-format
115 :reader external-format-of
)
117 (input-buffer :initform nil
:type
(or iobuf null
)
118 :accessor input-buffer-of
)
120 (output-buffer :initform nil
:type
(or iobuf null
)
121 :accessor output-buffer-of
)
122 ;; Flag used by stream-force-output
123 (must-flush-output :initform nil
:type boolean
124 :accessor must-flush-output-p
)
125 ;; Last read char buffer index
126 (ibuf-unread-index :initform
0 :type buffer-index
127 :accessor ibuf-unread-index-of
))
128 (:default-initargs
:external-format
:default
))
130 (defgeneric (setf external-format-of
) (external-format stream
))