0.9.10.20:
[sbcl.git] / contrib / sb-bsd-sockets / defpackage.lisp
1 (defpackage "SB-BSD-SOCKETS-INTERNAL"
2   (:nicknames "SOCKINT")
3   (:shadow close listen)
4   #+cmu (:shadowing-import-from "CL" with-array-data)
5   #+sbcl (:shadowing-import-from "SB-KERNEL" with-array-data)
6   #+cmu (:use "COMMON-LISP" "ALIEN" "SYSTEM" "EXT" "C-CALL")
7   #+sbcl (:use "COMMON-LISP" "SB-ALIEN" #+nil "SB-SYSTEM" "SB-EXT" "SB-C-CALL"))
8
9 ;;; SBCL changes a lot of package prefixes.  To avoid littering the
10 ;;; code with conditionals, we use the SBCL package prefixes
11 ;;; throughout.  This means that we need to create said packages
12 ;;; first, if we're using CMUCL
13
14 ;;; One thing that this exercise really has made clear is just how much
15 ;;; of the alien stuff is scattered around the cmucl package space
16 ;;; seemingly at random.  Hmm.
17
18 #+cmu
19 (eval-when (:compile-toplevel :load-toplevel)
20   (defun add-package-nickname (name nickname)
21     (let ((p (find-package name)))
22       (rename-package p (package-name p)
23                       (cons nickname (package-nicknames name)))))
24   (add-package-nickname "EXT" "SB-EXT")
25   (add-package-nickname "ALIEN" "SB-ALIEN")
26   (add-package-nickname "UNIX" "SB-UNIX")
27   (add-package-nickname "C-CALL" "SB-C-CALL")
28   (add-package-nickname "KERNEL" "SB-KERNEL")
29   (add-package-nickname "SYSTEM" "SB-SYS"))
30
31 (defpackage "SB-BSD-SOCKETS"
32   (:export socket local-socket inet-socket
33            make-local-socket make-inet-socket
34            socket-bind socket-accept socket-connect
35            socket-send socket-receive socket-recv
36            socket-name socket-peername socket-listen
37            socket-close socket-file-descriptor
38            socket-family socket-protocol socket-open-p
39            socket-type socket-make-stream get-protocol-by-name
40
41            get-host-by-name get-host-by-address
42            host-ent
43            host-ent-addresses host-ent-address
44            host-ent-aliases host-ent-name
45            name-service-error
46            ;; not sure if these are really good names or not
47            netdb-internal-error
48            netdb-success-error
49            host-not-found-error
50            try-again-error
51            no-recovery-error
52
53            unknown-protocol
54
55            ;; all socket options are also exported, by code in
56            ;; sockopt.lisp
57
58            socket-error
59
60            ;; other errno-based socket errors are exported by code in
61            ;; sockets.lisp
62
63            make-inet-address
64
65            non-blocking-mode
66            )
67   (:use "COMMON-LISP" "SB-BSD-SOCKETS-INTERNAL")
68   (:import-from "SB-INT" "UNSUPPORTED-OPERATOR" "FEATUREP")
69   (:documentation
70    "
71
72 A thinly-disguised BSD socket API for SBCL.  Ideas stolen from the BSD
73 socket API for C and Graham Barr's IO::Socket classes for Perl.
74
75 We represent sockets as CLOS objects, and rename a lot of methods and
76 arguments to fit Lisp style more closely.
77
78 "
79    ))
80
81 #||
82
83 <h2>Contents</h2>
84
85 <ol>
86 <li> General concepts
87 <li> Methods applicable to all <a href="#socket">sockets</a>
88 <li> <a href="#sockopt">Socket Options</a>
89 <li> Methods applicable to a particular subclass
90 <ol>
91 <li> <a href="#internet">INET-SOCKET</a> - Internet Protocol (TCP, UDP, raw) sockets
92 <li> Methods on <a href="#LOCAL-SOCKET">LOCAL-SOCKET</a> - Local-domain sockets
93 </ol>
94 <li> <a href="#name-service">Name resolution</a> (DNS, /etc/hosts, &amp;c)
95 </ol>
96
97 <h2>General concepts</h2>
98
99 <p>Most of the functions are modelled on the BSD socket API.  BSD sockets
100 are widely supported, portably <i>("portable" by Unix standards, at least)</i>
101 available on a variety of systems, and documented.  There are some
102 differences in approach where we have taken advantage of some of the more useful features of Common Lisp - briefly
103
104 <ul>
105 <li> Where the C API would typically return -1 and set errno, we
106 signal an error.  All the errors are subclasses of SOCKET-CONDITION
107 and generally correspond one for one with possible <tt>errno</tt> values
108
109 <li> We use multiple return values in many places where the C API would use
110 pass-by-reference values
111
112 <li> We can often avoid supplying an explicit <i>length</i> argument to
113 functions because we already know how long the argument is.
114
115 <li> IP addresses and ports are represented in slightly friendlier fashion
116 than "network-endian integers".  See the section on <a href="#internet"
117 >Internet domain</a> sockets for details.
118 </ul>
119
120
121 |#
122
123 (in-package :sb-bsd-sockets)
124
125 (defmethod asdf:hyperdocumentation
126     ((package (eql #.*package*)) symbol kind)
127   (declare (ignore kind))
128   (format nil "file://~A#~A"
129           #.(namestring
130              (merge-pathnames "index.html"
131                               (or *load-pathname* *compile-file-pathname*)))
132           symbol))