760c5f015252bc7eb35cb882bbc190aaa8bc6516
[sbcl.git] / contrib / sb-bsd-sockets / sb-bsd-sockets.texinfo
1 @node Networking
2 @comment  node-name,  next,  previous,  up
3 @chapter Networking
4 @cindex Sockets, Networking
5
6 The @code{sb-bsd-sockets} module provides a thinly disguised BSD
7 socket API for SBCL. Ideas have been stolen from the BSD socket API
8 for C and Graham Barr's IO::Socket classes for Perl.
9
10 Sockets are represented as CLOS objects, and the API naming
11 conventions attempt to balance between the BSD names and good lisp style.
12
13 @menu
14 * Sockets Overview::
15 * General Sockets::      Methods applicable to all sockets
16 * Socket Options::
17 * INET Domain Sockets::
18 * Local (Unix) Domain Sockets::
19 * Name Service::
20 @end menu
21
22 @node Sockets Overview
23 @section Sockets Overview
24
25 Most of the functions are modelled on the BSD socket API.  BSD sockets
26 are widely supported, portably @emph{(``portable'' by Unix standards, at least)}
27 available on a variety of systems, and documented.  There are some
28 differences in approach where we have taken advantage of some of the
29 more useful features of Common Lisp - briefly:
30
31 @itemize
32
33 @item
34 Where the C API would typically return -1 and set @code{errno},
35 @code{sb-bsd-sockets} signals an error. All the errors are subclasses
36 of @code{sb-bsd-sockets:socket-condition} and generally correspond one
37 for one with possible @code{errno} values.
38
39 @item 
40 We use multiple return values in many places where the C API would use
41 pass-by-reference values.
42
43 @item
44 We can often avoid supplying an explicit @emph{length} argument to
45 functions because we already know how long the argument is.
46
47 @item
48 IP addresses and ports are represented in slightly friendlier fashion
49 than "network-endian integers".
50
51 @end itemize
52
53 @node General Sockets
54 @section General Sockets
55
56 @include class-sb-bsd-sockets-socket.texinfo
57
58 @include fun-sb-bsd-sockets-socket-bind.texinfo
59
60 @include fun-sb-bsd-sockets-socket-accept.texinfo
61
62 @include fun-sb-bsd-sockets-socket-connect.texinfo
63
64 @include fun-sb-bsd-sockets-socket-peername.texinfo
65
66 @include fun-sb-bsd-sockets-socket-name.texinfo
67
68 @include fun-sb-bsd-sockets-socket-receive.texinfo
69
70 @include fun-sb-bsd-sockets-socket-send.texinfo
71
72 @include fun-sb-bsd-sockets-socket-listen.texinfo
73
74 @include fun-sb-bsd-sockets-socket-open-p.texinfo
75
76 @include fun-sb-bsd-sockets-socket-close.texinfo
77
78 @include fun-sb-bsd-sockets-socket-make-stream.texinfo
79
80 @include fun-sb-bsd-sockets-socket-error.texinfo
81
82 @include fun-sb-bsd-sockets-non-blocking-mode.texinfo
83
84 @node Socket Options
85 @section Socket Options
86
87 A subset of socket options are supported, using a fairly general
88 framework which should make it simple to add more as required - see
89 @file{SYS:CONTRIB;SB-BSD-SOCKETS:SOCKOPT.LISP} for details. The name
90 mapping from C is fairly straightforward: @code{SO_RCVLOWAT} becomes
91 @code{sockopt-receive-low-water} and @code{(setf
92 sockopt-receive-low-water)}.
93
94 @include fun-sb-bsd-sockets-sockopt-reuse-address.texinfo
95
96 @include fun-sb-bsd-sockets-sockopt-keep-alive.texinfo
97
98 @include fun-sb-bsd-sockets-sockopt-oob-inline.texinfo
99
100 @include fun-sb-bsd-sockets-sockopt-bsd-compatible.texinfo
101
102 @include fun-sb-bsd-sockets-sockopt-pass-credentials.texinfo
103
104 @include fun-sb-bsd-sockets-sockopt-debug.texinfo
105
106 @include fun-sb-bsd-sockets-sockopt-dont-route.texinfo
107
108 @include fun-sb-bsd-sockets-sockopt-broadcast.texinfo
109
110 @include fun-sb-bsd-sockets-sockopt-tcp-nodelay.texinfo
111
112 @node INET Domain Sockets
113 @section INET Domain Sockets
114
115 The TCP and UDP sockets that you know and love. Some representation
116 issues:
117
118 @itemize
119
120 @item
121 Internet addresses are represented by vectors of (unsigned-byte 8) -
122 viz. #(127 0 0 1). Ports are just integers: 6010. No conversion
123 between network- and host-order data is needed from the user of this
124 package.
125
126 @item
127 Socket addresses are represented by the two values for address and
128 port, so for example, (socket-connect s #(192 168 1 1) 80).
129
130 @end itemize
131
132 @include class-sb-bsd-sockets-inet-socket.texinfo
133
134 @include fun-sb-bsd-sockets-make-inet-address.texinfo
135
136 @include fun-sb-bsd-sockets-get-protocol-by-name.texinfo
137
138 @node Local (Unix) Domain Sockets
139 @section Local (Unix) Domain Sockets
140
141 Local domain (@code{AF_LOCAL}) sockets are also known as Unix-domain
142 sockets, but were renamed by POSIX presumably on the basis that they
143 may be available on other systems too.
144                                                                                 
145 A local socket address is a string, which is used to create a node in
146 the local filesystem. This means of course that they cannot be used
147 across a network.
148
149 @include class-sb-bsd-sockets-local-socket.texinfo
150
151 @node Name Service
152 @section Name Service
153
154 Presently name service is implemented by calling out to the
155 @code{getaddrinfo(3)} and @code{gethostinfo(3)}, or to
156 @code{gethostbyname(3)} @code{gethostbyaddr(3)} on platforms where
157 the preferred functions are not available. The exact details of
158 the name resolving process (for example the choice of whether
159 DNS or a hosts file is used for lookup) are platform dependent.
160                                                                                  
161 @c Direct links to the asynchronous @code{resolver(3)} routines would be
162 @c nice to have eventually, so that we can do DNS lookups in parallel
163 @c with other things.
164
165 @include class-sb-bsd-sockets-host-ent.texinfo
166
167 @include fun-sb-bsd-sockets-get-host-by-name.texinfo
168
169 @include fun-sb-bsd-sockets-get-host-by-address.texinfo
170
171 @include fun-sb-bsd-sockets-host-ent-address.texinfo