1 (cl:in-package
#:sb-bsd-sockets
)
5 (defgeneric make-sockaddr-for
(socket &optional sockaddr
&rest address
)
7 "Return a Socket Address object suitable for use with SOCKET.
8 When SOCKADDR is passed, it is used instead of a new object."))
10 (defgeneric free-sockaddr-for
(socket sockaddr
)
12 "Deallocate the socket address object SOCKADDR that was created for
15 (defgeneric bits-of-sockaddr
(socket sockaddr
)
17 "Return as multiple values protocol-dependent bits of parameter
18 SOCKADDR, e.g. the host/port if SOCKET is an inet socket."))
20 (defgeneric size-of-sockaddr
(socket)
22 "Return the size in bytes of a sockaddr object for SOCKET."))
26 (defgeneric socket-name
(socket)
28 "Return the address (as vector of bytes) and port that SOCKET is
29 bound to, as multiple values."))
31 (defgeneric socket-peername
(socket)
33 "Return SOCKET's peer; depending on the address family this may
34 return multiple values"))
36 (defgeneric socket-namestring
(socket)
40 "Return a string representation of the address and port that SOCKET
43 (defgeneric socket-peerstring
(socket)
47 "Return a string representation of the address and port of SOCKET's
50 (defgeneric socket-open-p
(socket)
52 "Return true if SOCKET is open; otherwise, return false.")
54 (error 'type-error
:datum socket
:expected-type
'socket
)))
56 (defgeneric socket-close
(socket &key abort
)
58 "Close SOCKET, unless it was already closed.
60 If SOCKET-MAKE-STREAM has been called, calls CLOSE using ABORT on that
61 stream. Otherwise closes the socket file descriptor using
64 (defgeneric socket-bind
(socket &rest address
)
66 "Bind SOCKET to ADDRESS, which may vary according to socket family.
67 For the INET family, pass ADDRESS and PORT as two arguments; for FILE
68 address family sockets, pass the filename string. See also bind(2)"))
70 (defgeneric socket-accept
(socket)
72 "Perform the accept(2) call, returning a newly-created connected
73 socket and the peer address as multiple values"))
75 (defgeneric socket-connect
(socket &rest address
)
77 "Perform the connect(2) call to connect SOCKET to a remote PEER.
78 No useful return value."))
80 (defgeneric socket-receive
(socket buffer length
82 oob peek waitall dontwait element-type
)
84 "Read LENGTH octets from SOCKET into BUFFER (or a freshly-consed
85 buffer if NIL), using recvfrom(2). If LENGTH is NIL, the length of
86 BUFFER is used, so at least one of these two arguments must be
87 non-NIL. If BUFFER is supplied, it had better be of an element type
88 one octet wide. Returns the buffer, its length, and the address of the
89 peer that sent it, as multiple values. On datagram sockets, sets
90 MSG_TRUNC so that the actual packet length is returned even if the
91 buffer was too small."))
93 (defgeneric socket-send
(socket buffer length
97 oob eor dontroute dontwait nosignal
98 #+linux confirm
#+linux more
)
100 "Send LENGTH octets from BUFFER into SOCKET, using sendto(2). If
101 BUFFER is a string, it will converted to octets according to
102 EXTERNAL-FORMAT. If LENGTH is NIL, the length of the octet buffer is
103 used. The format of ADDRESS depends on the socket type (for example
104 for INET domain sockets it would be a list of an IP address and a
105 port). If no socket address is provided, send(2) will be called
106 instead. Returns the number of octets written."))
108 (defgeneric socket-listen
(socket backlog
)
110 "Mark SOCKET as willing to accept incoming connections. The
111 integer BACKLOG defines the maximum length that the queue of pending
112 connections may grow to before new connection attempts are refused.
113 See also listen(2)"))
115 (defgeneric socket-shutdown
(socket &key direction
)
117 "Indicate that no communication in DIRECTION will be performed on
120 DIRECTION has to be one of :INPUT, :OUTPUT or :IO.
122 After a shutdown, no input and/or output of the indicated DIRECTION
123 can be performed on SOCKET."))
125 (defgeneric socket-make-stream
(socket &key input output
126 element-type external-format
130 "Find or create a STREAM that can be used for IO on SOCKET \(which
131 must be connected\). Specify whether the stream is for INPUT, OUTPUT,
132 or both \(it is an error to specify neither\).
134 ELEMENT-TYPE and EXTERNAL-FORMAT are as per OPEN.
136 TIMEOUT specifies a read timeout for the stream."))
138 (defgeneric non-blocking-mode
(socket)
140 "Is SOCKET in non-blocking mode?"))
142 (defgeneric (setf non-blocking-mode
) (non-blocking-p socket
)
144 "Put SOCKET in non-blocking mode - or not, according to
149 (defgeneric host-ent-address
(host-ent)
151 "Return some valid address for HOST-ENT."))