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 :net.sockets
)
30 (defclass socket
(dual-channel-single-fd-stream-mixin)
31 ((family :initarg
:family
:accessor socket-family
)
32 (protocol :initarg
:protocol
:accessor socket-protocol
)))
34 (defgeneric socket-fd
(socket))
35 (defgeneric (setf socket-fd
) (fd socket
))
37 (defgeneric socket-type
(socket))
39 (defgeneric socket-open-p
(socket))
41 (defgeneric local-name
(socket))
43 (defgeneric socket-address
(socket))
45 (defgeneric socket-port
(socket))
47 (defgeneric remote-name
(socket))
49 (defgeneric get-socket-option
(socket option-name
))
51 (defgeneric set-socket-option
(socket option-name
&key
&allow-other-keys
))
53 (defclass stream-socket
(socket) ()
54 (:default-initargs
:type
:stream
))
56 (defclass datagram-socket
(socket) ()
57 (:default-initargs
:type
:datagram
))
59 (defgeneric unconnect
(socket))
61 (defclass internet-socket
(socket) ()
62 (:default-initargs
:family
(if *ipv6
* :ipv6
:ipv4
)))
64 (defclass local-socket
(socket) ()
65 (:default-initargs
:family
:local
))
67 (defclass active-socket
(socket dual-channel-gray-stream
) ())
69 (defgeneric connect
(socket address
&key
&allow-other-keys
))
71 (defgeneric socket-connected-p
(socket))
73 (defgeneric shutdown
(socket direction
))
75 (defgeneric socket-send
(buffer socket
&key
&allow-other-keys
))
77 (defgeneric socket-receive
(buffer socket
&key
&allow-other-keys
))
79 (defclass passive-socket
(socket)
80 ((bound :initform nil
:reader socket-bound-p
:type boolean
)
81 (listening :initform nil
:reader socket-listening-p
:type boolean
)
82 (active-class :initarg
:active-class
:reader active-class
83 :type symbol
:allocation
:class
)))
85 (defgeneric bind-address
(socket address
&key
&allow-other-keys
))
87 (defgeneric socket-listen
(socket &key backlog
&allow-other-keys
))
89 (defgeneric accept-connection
(passive-socket &key wait
&allow-other-keys
))
91 (defclass socket-stream-internet-active
(active-socket stream-socket internet-socket
) ())
93 (defclass socket-stream-internet-passive
(passive-socket stream-socket internet-socket
) ()
94 (:default-initargs
:active-class
'socket-stream-internet-active
))
96 (defclass socket-stream-local-active
(active-socket stream-socket local-socket
) ())
98 (defclass socket-stream-local-passive
(passive-socket stream-socket local-socket
) ()
99 (:default-initargs
:active-class
'socket-stream-local-active
))
101 (defclass socket-datagram-local-active
(active-socket datagram-socket local-socket
) ())
103 (defclass socket-datagram-internet-active
(active-socket datagram-socket internet-socket
) ())