Fix literal hash tables test suite on CLISP.
[iolib.git] / io.streams / classes.lisp
blob3b82728babb17fc018d8d37d3b2a566a61575aa5
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
2 ;;;
3 ;;; classes.lisp --- fd-streams classes.
4 ;;;
5 ;;; Copyright (C) 2006-2007, Stelian Ionescu <sionescu@common-lisp.net>
6 ;;;
7 ;;; This code is free software; you can redistribute it and/or
8 ;;; modify it under the terms of the version 2.1 of
9 ;;; the GNU Lesser General Public License as published by
10 ;;; the Free Software Foundation, as clarified by the
11 ;;; preamble found here:
12 ;;; http://opensource.franz.com/preamble.html
13 ;;;
14 ;;; This program is distributed in the hope that it will be useful,
15 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;;; GNU General Public License for more details.
18 ;;;
19 ;;; You should have received a copy of the GNU Lesser General
20 ;;; Public License along with this library; if not, write to the
21 ;;; Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 ;;; Boston, MA 02110-1301, USA
24 (in-package :io.streams)
26 ;;;; Types
28 (deftype ub8 () '(unsigned-byte 8))
29 (deftype ub16 () '(unsigned-byte 16))
30 (deftype ub32 () '(unsigned-byte 32))
31 (deftype sb8 () '(signed-byte 8))
32 (deftype sb16 () '(signed-byte 16))
33 (deftype sb32 () '(signed-byte 32))
35 (deftype ub8-sarray (&optional (size '*))
36 `(simple-array ub8 (,size)))
38 (deftype ub8-vector () '(vector ub8))
40 (deftype ub16-sarray (&optional (size '*))
41 `(simple-array ub16 (,size)))
43 ;;;; Socket Buffers
45 (deftype stream-buffer () 'foreign-pointer)
46 (deftype buffer-index () '(unsigned-byte 24))
48 (defstruct (iobuf (:constructor %make-iobuf ()))
49 (data (null-pointer) :type stream-buffer)
50 (size 0 :type buffer-index)
51 (start 0 :type buffer-index)
52 (end 0 :type buffer-index))
54 ;;;; File-Descriptor Mixins
56 (deftype stream-position () '(unsigned-byte 64))
58 (defclass dual-channel-fd-mixin ()
59 ((input-fd :initform nil :initarg :input-fd :accessor input-fd-of
60 :documentation "placeholder")
61 (output-fd :initform nil :initarg :output-fd :accessor output-fd-of
62 :documentation "placeholder"))
63 (:documentation "placeholder"))
65 (defgeneric input-fd-non-blocking (socket)
66 (:documentation "placeholder"))
68 (defgeneric (setf input-fd-non-blocking) (mode fd-mixin))
70 (defgeneric output-fd-non-blocking (socket)
71 (:documentation "placeholder"))
73 (defgeneric (setf output-fd-non-blocking) (mode fd-mixin))
75 (defclass dual-channel-single-fd-mixin (dual-channel-fd-mixin)
77 (:documentation "placeholder"))
79 (defgeneric fd-of (stream)
80 (:documentation "placeholder")
81 (:method ((stream dual-channel-single-fd-mixin))
82 (with-accessors ((fd-in input-fd-of)
83 (fd-out output-fd-of)) stream
84 (assert (eql fd-in fd-out) (fd-in fd-out)
85 "Input and output FDs must be equal: ~A, ~A" fd-in fd-out)
86 (values fd-in))))
88 (defgeneric (setf fd-of) (fd stream)
89 (:documentation "placeholder")
90 (:method (fd (stream dual-channel-single-fd-mixin))
91 (with-accessors ((fd-in input-fd-of)
92 (fd-out output-fd-of)) stream
93 (setf fd-in fd fd-out fd)
94 (values fd-in))))
96 (defgeneric fd-non-blocking (fd-mixin)
97 (:documentation "placeholder"))
99 (defgeneric (setf fd-non-blocking) (mode fd-mixin))
101 ;;;; Bivalent Socket Gray Stream
103 (defclass dual-channel-gray-stream (trivial-gray-stream-mixin
104 dual-channel-fd-mixin
105 fundamental-binary-input-stream
106 fundamental-binary-output-stream
107 fundamental-character-input-stream
108 fundamental-character-output-stream)
109 ((external-format :initform :default :initarg :external-format
110 :reader external-format-of
111 :documentation "placehold")
112 ;; Input buffer.
113 (input-buffer :initform nil :type (or iobuf null)
114 :accessor input-buffer-of)
115 ;; Output buffer.
116 (output-buffer :initform nil :type (or iobuf null)
117 :accessor output-buffer-of)
118 ;; Flag used by stream-force-output.
119 (must-flush-output :initform nil :type boolean
120 :accessor must-flush-output-p)
121 ;; Last read char buffer index.
122 (ibuf-unread-index :initform 0 :type buffer-index
123 :accessor ibuf-unread-index-of))
124 (:documentation "placeholder"))
126 (defgeneric (setf external-format-of) (external-format stream)
127 (:documentation "placeholder"))
129 (defclass dual-channel-single-fd-gray-stream
130 (dual-channel-gray-stream dual-channel-single-fd-mixin)
132 (:documentation "placeholder"))