1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Indent-tabs-mode: NIL -*-
3 ;;; base-sockets.lisp --- Base socket classes.
5 ;;; Copyright (C) 2006-2007, Stelian Ionescu <sionescu@common-lisp.net>
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
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.
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 :net.sockets
)
28 (defclass socket
(dual-channel-single-fd-mixin)
29 ((family :initarg
:family
:accessor socket-family
)
30 (protocol :initarg
:protocol
:accessor socket-protocol
)
31 (bound :initform nil
:reader socket-bound-p
:type boolean
)))
33 (defgeneric socket-fd
(socket))
34 (defgeneric (setf socket-fd
) (fd socket
))
35 (defgeneric socket-type
(socket))
36 (defgeneric socket-open-p
(socket))
37 (defgeneric local-name
(socket))
38 (defgeneric local-address
(socket))
39 (defgeneric local-port
(socket))
40 (defgeneric remote-name
(socket))
41 (defgeneric remote-address
(socket))
42 (defgeneric remote-port
(socket))
43 (defgeneric get-socket-option
(socket option-name
))
44 (defgeneric set-socket-option
(socket option-name
&key
&allow-other-keys
))
46 (defclass stream-socket
(socket) ()
47 (:default-initargs
:type
:stream
))
49 (defclass datagram-socket
(socket) ()
50 (:default-initargs
:type
:datagram
))
52 (defgeneric disconnect
(socket))
54 (defclass internet-socket
(socket) ()
55 (:default-initargs
:family
(if *ipv6
* :ipv6
:ipv4
)))
57 (defclass local-socket
(socket) ()
58 (:default-initargs
:family
:local
))
60 (defclass active-socket
(socket dual-channel-gray-stream
) ())
62 (defgeneric connect
(socket address
&key
&allow-other-keys
))
64 (defgeneric socket-connected-p
(socket))
66 (defgeneric shutdown
(socket direction
))
68 (defgeneric socket-send
(buffer socket
&rest args
&key
&allow-other-keys
))
70 (defgeneric socket-receive
(buffer socket
&rest args
&key
&allow-other-keys
))
72 (defclass passive-socket
(socket)
73 ((listening :initform nil
:reader socket-listening-p
:type boolean
)
74 (external-format :initarg
:external-format
:reader external-format-of
)
75 (active-class :initarg
:active-class
:reader active-class
76 :type symbol
:allocation
:class
))
77 (:default-initargs
:external-format
:default
))
79 (defgeneric bind-address
(socket address
&key
&allow-other-keys
))
81 (defgeneric socket-listen
(socket &key backlog
&allow-other-keys
))
83 (defgeneric accept-connection
(passive-socket))
85 (defclass socket-stream-internet-active
86 (active-socket stream-socket internet-socket
)
89 (defclass socket-stream-internet-passive
90 (passive-socket stream-socket internet-socket
)
92 (:default-initargs
:active-class
'socket-stream-internet-active
))
94 (defclass socket-stream-local-active
(active-socket stream-socket local-socket
)
97 (defclass socket-stream-local-passive
98 (passive-socket stream-socket local-socket
)
100 (:default-initargs
:active-class
'socket-stream-local-active
))
102 (defclass socket-datagram-local-active
103 (active-socket datagram-socket local-socket
)
106 (defclass socket-datagram-internet-active
107 (active-socket datagram-socket internet-socket
)