X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-bsd-sockets%2Fdefpackage.lisp;h=0c865527ba2b7e299cf460749536e241a3bf261f;hb=315285fcf8bf1f7e732da307cfaf31f18f412811;hp=e431cf36086c97b6e22eb741e7566100d3133c42;hpb=c03ebb54770cfa613d4b706a80e5be231786a5d0;p=sbcl.git diff --git a/contrib/sb-bsd-sockets/defpackage.lisp b/contrib/sb-bsd-sockets/defpackage.lisp index e431cf3..0c86552 100644 --- a/contrib/sb-bsd-sockets/defpackage.lisp +++ b/contrib/sb-bsd-sockets/defpackage.lisp @@ -1,44 +1,14 @@ -#+(and sbcl win32) -(defpackage "SB-WIN32-SOCKETS-INTERNAL" - (:nicknames "WIN32SOCKINT") - (:shadow close listen) - (:use "COMMON-LISP" "SB-ALIEN" "SB-EXT" "SB-C-CALL")) - (defpackage "SB-BSD-SOCKETS-INTERNAL" (:nicknames "SOCKINT") (:shadow close listen) - #+cmu (:shadowing-import-from "CL" with-array-data) - #+sbcl (:shadowing-import-from "SB-KERNEL" with-array-data) - #+cmu (:use "COMMON-LISP" "ALIEN" "SYSTEM" "EXT" "C-CALL") - #+sbcl (:use "COMMON-LISP" "SB-ALIEN" #+nil "SB-SYSTEM" "SB-EXT" "SB-C-CALL")) - -;;; SBCL changes a lot of package prefixes. To avoid littering the -;;; code with conditionals, we use the SBCL package prefixes -;;; throughout. This means that we need to create said packages -;;; first, if we're using CMUCL - -;;; One thing that this exercise really has made clear is just how much -;;; of the alien stuff is scattered around the cmucl package space -;;; seemingly at random. Hmm. - -#+cmu -(eval-when (:compile-toplevel :load-toplevel) - (defun add-package-nickname (name nickname) - (let ((p (find-package name))) - (rename-package p (package-name p) - (cons nickname (package-nicknames name))))) - (add-package-nickname "EXT" "SB-EXT") - (add-package-nickname "ALIEN" "SB-ALIEN") - (add-package-nickname "UNIX" "SB-UNIX") - (add-package-nickname "C-CALL" "SB-C-CALL") - (add-package-nickname "KERNEL" "SB-KERNEL") - (add-package-nickname "SYSTEM" "SB-SYS")) + (:shadowing-import-from "SB-KERNEL" with-array-data) + (:use "COMMON-LISP" "SB-ALIEN" "SB-EXT")) (defpackage "SB-BSD-SOCKETS" - (:export socket local-socket inet-socket + (:export socket local-socket local-abstract-socket inet-socket make-local-socket make-inet-socket socket-bind socket-accept socket-connect - socket-send socket-receive socket-recv + socket-send socket-receive socket-name socket-peername socket-listen socket-close socket-file-descriptor socket-family socket-protocol socket-open-p @@ -68,71 +38,26 @@ make-inet-address - non-blocking-mode - ) + non-blocking-mode) (:use "COMMON-LISP" "SB-BSD-SOCKETS-INTERNAL") (:import-from "SB-INT" "UNSUPPORTED-OPERATOR" "FEATUREP") (:documentation - " - -A thinly-disguised BSD socket API for SBCL. Ideas stolen from the BSD + "A thinly-disguised BSD socket API for SBCL. Ideas stolen from the BSD socket API for C and Graham Barr's IO::Socket classes for Perl. We represent sockets as CLOS objects, and rename a lot of methods and -arguments to fit Lisp style more closely. - -" - )) - -#|| - -

Contents

- -
    -
  1. General concepts -
  2. Methods applicable to all sockets -
  3. Socket Options -
  4. Methods applicable to a particular subclass -
      -
    1. INET-SOCKET - Internet Protocol (TCP, UDP, raw) sockets -
    2. Methods on LOCAL-SOCKET - Local-domain sockets -
    -
  5. Name resolution (DNS, /etc/hosts, &c) -
- -

General concepts

- -

Most of the functions are modelled on the BSD socket API. BSD sockets -are widely supported, portably ("portable" by Unix standards, at least) -available on a variety of systems, and documented. There are some -differences in approach where we have taken advantage of some of the more useful features of Common Lisp - briefly - -

- - -|# - -(in-package :sb-bsd-sockets) - -(defmethod asdf:hyperdocumentation - ((package (eql #.*package*)) symbol kind) - (declare (ignore kind)) - (format nil "file://~A#~A" - #.(namestring - (merge-pathnames "index.html" - (or *load-pathname* *compile-file-pathname*))) - symbol)) +arguments to fit Lisp style more closely.")) + +;;; gethostbyname/gethostbyaddr are generally not thread safe. POSIX +;;; 1003.1-2003 defines an alternative API, which is specified in the +;;; RFC to be thread-safe. If it seems to be available, use it. +;;; +;;; Unfortunately the manual page claims that these functions are not +;;; thread-safe on OS X, but they probably can't be any worse than +;;; gethostbyname and gethostbyaddr. +;;; +;;; CLH: getaddrinfo seems to be broken is broken on x86-64/darwin +#-(or win32 (and x86-64 darwin)) +(let ((addr (sb-alien::find-dynamic-foreign-symbol-address "getaddrinfo"))) + (when addr + (pushnew :sb-bsd-sockets-addrinfo *features*)))