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