1 (defpackage "SB-BSD-SOCKETS-INTERNAL"
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"))
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
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.
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"))
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
41 get-host-by-name get-host-by-address
43 host-ent-addresses host-ent-address
44 host-ent-aliases host-ent-name
46 ;; not sure if these are really good names or not
55 ;; all socket options are also exported, by code in
60 ;; other errno-based socket errors are exported by code in
67 (:use "COMMON-LISP" "SB-BSD-SOCKETS-INTERNAL")
68 (:import-from "SB-INT" "UNSUPPORTED-OPERATOR" "FEATUREP")
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.
75 We represent sockets as CLOS objects, and rename a lot of methods and
76 arguments to fit Lisp style more closely.
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
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
94 <li> <a href="#name-service">Name resolution</a> (DNS, /etc/hosts, &c)
97 <h2>General concepts</h2>
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
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
109 <li> We use multiple return values in many places where the C API would use
110 pass-by-reference values
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.
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.
123 (in-package :sb-bsd-sockets)
125 (defmethod asdf:hyperdocumentation
126 ((package (eql #.*package*)) symbol kind)
127 (declare (ignore kind))
128 (format nil "file://~A#~A"
130 (merge-pathnames "index.html"
131 (or *load-pathname* *compile-file-pathname*)))