small changes to the reverser test
[iolib.git] / net.sockets.cc / classes.lisp
blob92d3c48b26b0da9728d957be61af26e8294c9c34
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; indent-tabs-mode: NIL -*-
2 ;;;
3 ;;; Copyright (C) 2006-2008, Attila Lendvai <attila.lendvai@gmail.com>
4 ;;;
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
11 ;;;
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.
16 ;;;
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 :net.sockets.cc)
24 (defclass connection-multiplexer ()
25 ((name
26 :initform "unnamed connection-multiplexer"
27 :initarg :name
28 :accessor name-of)
29 (lock
30 :initform (bordeaux-threads:make-recursive-lock "connection-multiplexer lock")
31 :accessor lock-of)
32 (fd->connection
33 :initform (make-array 128 :adjustable t :initial-element nil)
34 :accessor fd->connection-of)
35 (fd-multiplexer
36 :initform nil
37 :accessor fd-multiplexer-of)
38 (shutdown-requested
39 :initform nil
40 :accessor shutdown-requested-p)
41 (workers
42 :initform (make-array 4 :adjustable t :fill-pointer 0)
43 :accessor workers-of)
44 ;; configuration slots
45 (worker-count
46 :initform 4
47 :initarg :worker-count
48 :accessor worker-count-of)
49 (external-format
50 :initform :default
51 :initarg :external-format
52 :accessor external-format-of)
53 (fd-multiplexer-type
54 :initarg :fd-multiplexer-type
55 :accessor fd-multiplexer-type-of)))
57 ;; TODO use progn combination
58 (defgeneric startup-connection-multiplexer (multiplexer &key &allow-other-keys))
59 (defgeneric shutdown-connection-multiplexer (multiplexer &key force))
61 (defgeneric register-connection (multiplexer connection))
62 (defgeneric unregister-connection (multiplexer connection))
63 (defgeneric connection-registered-p (multiplexer connection))
65 (defclass connection-acceptor (connection-multiplexer)
66 (;; slots for the runtime state
67 (accepting-connection
68 :initform nil
69 :initarg :accepting-connection
70 :accessor accepting-connection-of)
71 ;; configuration slots
72 (connection-handler
73 :initarg :connection-handler
74 :accessor connection-handler-of
75 :type (or symbol function))))
77 (defclass connection-with-continuation-mixin ()
78 ((continuation
79 :initform nil
80 :initarg :continuation
81 :accessor continuation-of)
82 (wait-reason
83 :accessor wait-reason-of
84 :initarg :wait-reason
85 :type (member :read :write))))
87 (defclass bandwidth-information-mixin ()
88 ((created-at
89 :initform (get-internal-real-time)
90 :accessor created-at-of)
91 (total-bytes-written
92 :initform 0
93 :accessor total-bytes-written-of)
94 (total-bytes-read
95 :initform 0
96 :accessor total-bytes-read-of)))
98 (defgeneric notify-bytes-written (connection count))
99 (defgeneric average-writing-speed-of (connection))
100 (defgeneric notify-bytes-read (connection count))
101 (defgeneric average-reading-speed-of (connection))
103 (defclass connection (connection-with-continuation-mixin
104 bandwidth-information-mixin
105 socket-stream-internet-active)
108 ;; TODO why does connection inherit from socket-stream-internet-active and
109 ;; accepting-connection only contain a socket slot?
110 (defclass accepting-connection (connection-with-continuation-mixin)
111 ((socket
112 :initarg :socket
113 :reader socket-of)))
115 (defgeneric startup-acceptor (acceptor &key address port))
116 (defgeneric shutdown-acceptor (acceptor &key force))