0.8.0.68:
authorChristophe Rhodes <csr21@cam.ac.uk>
Fri, 13 Jun 2003 16:17:20 +0000 (16:17 +0000)
committerChristophe Rhodes <csr21@cam.ac.uk>
Fri, 13 Jun 2003 16:17:20 +0000 (16:17 +0000)
Merge patch I (+defgenerics.diff) from Andreas Fuchs
sbcl-devel 2003-06-10 for sb-bsd-sockets:
... add DEFGENERICS (enough to make LOAD-OP quiet, yay!)

contrib/sb-bsd-sockets/inet.lisp
contrib/sb-bsd-sockets/local.lisp
contrib/sb-bsd-sockets/misc.lisp
contrib/sb-bsd-sockets/name-service.lisp
contrib/sb-bsd-sockets/sockets.lisp
version.lisp-expr

index 2398952..df52637 100644 (file)
@@ -85,10 +85,6 @@ using getprotobyname(2) which typically looks in NIS or /etc/protocols"
    (+ (* 256 (sockint::sockaddr-in-port sockaddr 0))
       (sockint::sockaddr-in-port sockaddr 1))))  
    
-
 (defun make-inet-socket (type protocol)
   "Make an INET socket.  Deprecated in favour of make-instance"
   (make-instance 'inet-socket :type type :protocol protocol))
-
-
-
index 363f051..2350e06 100644 (file)
@@ -32,7 +32,7 @@ a network.
   sockint::size-of-sockaddr-un)
 
 (defmethod bits-of-sockaddr ((socket local-socket) sockaddr)
-  "Returns filename of SOCKADDR"
+  "Return the file name of the local socket address SOCKADDR."
   (let ((name (sb-c-call::%naturalize-c-string
               (sb-sys:sap+ (sockint::array-data-address sockaddr)
                            sockint::offset-of-sockaddr-un-path))))
index 6dd2bfb..c511cc7 100644 (file)
@@ -9,8 +9,10 @@
 
 ;;; XXX bad (sizeof (int) ==4 ) assumptions
 
+(defgeneric non-blocking-mode (socket)
+  (:documentation "Is SOCKET in non-blocking mode?"))
+
 (defmethod non-blocking-mode ((socket socket))
-  "Is SOCKET in non-blocking mode?"
   (let ((fd (socket-file-descriptor socket)))
     (sb-alien:with-alien ((arg integer))
                          (> (logand
                              sockint::o-nonblock)
                             0))))
 
+(defgeneric (setf non-blocking-mode) (non-blocking-p socket)
+  (:documentation "Put SOCKET in non-blocking mode - or not, according to NON-BLOCKING-P"))
+
 (defmethod (setf non-blocking-mode) (non-blocking-p (socket socket))
-  "Put SOCKET in non-blocking mode - or not, according to NON-BLOCKING-P"
   (declare (optimize (speed 3)))
   (let* ((fd (socket-file-descriptor socket))
          (arg1 (the (signed-byte 32) (sockint::fcntl fd sockint::f-getfl 0)))
index 5f03859..23f65a1 100644 (file)
@@ -17,6 +17,8 @@ eventually, so that we can do DNS lookups in parallel with other things
                                        ; presently always AF_INET
    (addresses :initarg :addresses :accessor host-ent-addresses)))
 
+(defgeneric host-ent-address (host-ent))
+
 (defmethod host-ent-address ((host-ent host-ent))
   (car (host-ent-addresses host-ent)))
 
index 69834dc..ed03482 100644 (file)
 
 \f
 
+(defgeneric make-sockaddr-for (socket &optional sockaddr &rest address)
+  (:documentation "Return a Socket Address object suitable for use with SOCKET.
+When SOCKADDR is passed, it is used instead of a new object."))
+
 ;; we deliberately redesign the "bind" interface: instead of passing a
 ;; sockaddr_something as second arg, we pass the elements of one as
 ;; multiple arguments.
 
-(defgeneric socket-bind (socket &rest address))
+(defgeneric socket-bind (socket &rest address)
+  (:documentation "Bind SOCKET to ADDRESS, which may vary according to
+socket family.  For the INET family, pass ADDRESS and PORT as two
+arguments; for FILE address family sockets, pass the filename string.
+See also bind(2)"))
+
 (defmethod socket-bind ((socket socket)
                         &rest address)
-  "Bind SOCKET to ADDRESS, which may vary according to socket family.  For
-the INET family, pass ADDRESS and PORT as two arguments; for FILE address
-family sockets, pass the filename string.  See also bind(2)"
   (let ((sockaddr (apply #'make-sockaddr-for socket nil address)))
     (if (= (sb-sys:without-gcing
            (sockint::bind (socket-file-descriptor socket)
@@ -64,9 +70,12 @@ family sockets, pass the filename string.  See also bind(2)"
         (socket-error "bind"))))
 
 \f
+(defgeneric socket-accept (socket)
+  (:documentation "Perform the accept(2) call, returning a
+newly-created connected socket and the peer address as multiple
+values"))
+  
 (defmethod socket-accept ((socket socket))
-  "Perform the accept(2) call, returning a newly-created connected socket
-and the peer address as multiple values"
   (let* ((sockaddr (make-sockaddr-for socket))
          (fd (sb-sys:without-gcing
              (sockint::accept (socket-file-descriptor socket)
@@ -82,9 +91,11 @@ and the peer address as multiple values"
                 (sb-ext:finalize s (lambda () (sockint::close fd)))))
           (multiple-value-list (bits-of-sockaddr socket sockaddr)))))
 
-(defgeneric socket-connect (socket &rest address))
+(defgeneric socket-connect (socket &rest address)
+  (:documentation "Perform the connect(2) call to connect SOCKET to a
+  remote PEER.  No useful return value."))
+
 (defmethod socket-connect ((socket socket) &rest peer)
-  "Perform the connect(2) call to connect SOCKET to a remote PEER.  No useful return value"
   (let* ((sockaddr (apply #'make-sockaddr-for socket nil peer)))
     (if (= (sb-sys:without-gcing
            (sockint::connect (socket-file-descriptor socket)
@@ -93,8 +104,11 @@ and the peer address as multiple values"
           -1)
        (socket-error "connect") )))
 
+(defgeneric socket-peername (socket)
+  (:documentation "Return the socket's peer; depending on the address
+  family this may return multiple values"))
+  
 (defmethod socket-peername ((socket socket))
-  "Return the socket's peer; depending on the address family this may return multiple values"  
   (let* ((sockaddr (make-sockaddr-for socket)))
     (when (= (sb-sys:without-gcing
              (sockint::getpeername (socket-file-descriptor socket)
@@ -104,8 +118,11 @@ and the peer address as multiple values"
       (socket-error "getpeername"))
     (bits-of-sockaddr socket sockaddr)))
 
+(defgeneric socket-name (socket)
+  (:documentation "Return the address (as vector of bytes) and port
+  that the socket is bound to, as multiple values."))
+
 (defmethod socket-name ((socket socket))
-  "Return the address (as vector of bytes) and port that the socket is bound to, as multiple values"
   (let* ((sockaddr (make-sockaddr-for socket)))
     (when (= (sb-sys:without-gcing
              (sockint::getsockname (socket-file-descriptor socket)
@@ -122,18 +139,22 @@ and the peer address as multiple values"
 ;;; allows us to read from an unconnected socket into a buffer, and
 ;;; to learn who the sender of the packet was
 
-(defmethod socket-receive ((socket socket) buffer length
-                        &key
-                        oob peek waitall
-                        (element-type 'character))
-  "Read LENGTH octets from SOCKET into BUFFER (or a freshly-consed buffer if
+(defgeneric socket-receive (socket buffer length
+                           &key
+                           oob peek waitall element-type)
+  (:documentation "Read LENGTH octets from SOCKET into BUFFER (or a freshly-consed buffer if
 NIL), using recvfrom(2).  If LENGTH is NIL, the length of BUFFER is
 used, so at least one of these two arguments must be non-NIL.  If
 BUFFER is supplied, it had better be of an element type one octet wide.
 Returns the buffer, its length, and the address of the peer
 that sent it, as multiple values.  On datagram sockets, sets MSG_TRUNC
 so that the actual packet length is returned even if the buffer was too
-small"
+small"))
+  
+(defmethod socket-receive ((socket socket) buffer length
+                        &key
+                        oob peek waitall
+                        (element-type 'character))
   (let ((flags
         (logior (if oob sockint::MSG-OOB 0)
                 (if peek sockint::MSG-PEEK 0)
@@ -162,18 +183,22 @@ small"
 
 
 
-(defmethod socket-listen ((socket socket) backlog)
-  "Mark SOCKET as willing to accept incoming connections.  BACKLOG
+(defgeneric socket-listen (socket backlog)
+  (:documentation "Mark SOCKET as willing to accept incoming connections.  BACKLOG
 defines the maximum length that the queue of pending connections may
-grow to before new connection attempts are refused.  See also listen(2)"
+grow to before new connection attempts are refused.  See also listen(2)"))
+
+(defmethod socket-listen ((socket socket) backlog)
   (let ((r (sockint::listen (socket-file-descriptor socket) backlog)))
     (if (= r -1)
         (socket-error "listen"))))
 
-(defmethod socket-close ((socket socket))
-  "Close SOCKET.  May throw any kind of error that write(2) would have
+(defgeneric socket-close (socket)
+  (:documentation "Close SOCKET.  May throw any kind of error that write(2) would have
 thrown.  If SOCKET-MAKE-STREAM has been called, calls CLOSE on that
-stream instead"
+stream instead"))
+
+(defmethod socket-close ((socket socket))
   ;; the close(2) manual page has all kinds of warning about not
   ;; checking the return value of close, on the grounds that an
   ;; earlier write(2) might have returned successfully w/o actually
@@ -195,9 +220,12 @@ stream instead"
      (bad-file-descriptor-error (c) (declare (ignore c)) nil)
      (:no-error (c)  (declare (ignore c)) nil))))
 
+(defgeneric socket-make-stream (socket  &rest args)
+    (:documentation "Find or create a STREAM that can be used for IO
+on SOCKET (which must be connected).  ARGS are passed onto
+SB-SYS:MAKE-FD-STREAM."))
+
 (defmethod socket-make-stream ((socket socket)  &rest args)
-  "Find or create a STREAM that can be used for IO on SOCKET (which
-must be connected).  ARGS are passed onto SB-SYS:MAKE-FD-STREAM."
   (let ((stream
         (and (slot-boundp socket 'stream) (slot-value socket 'stream))))
     (unless stream
@@ -276,4 +304,9 @@ must be connected).  ARGS are passed onto SB-SYS:MAKE-FD-STREAM."
     (error condition :errno errno  :syscall where)))
 
 
+(defgeneric bits-of-sockaddr (socket sockaddr)
+  (:documentation "Return protocol-dependent bits of parameter
+SOCKADDR, e.g. the Host/Port if SOCKET is an inet socket."))
 
+(defgeneric size-of-sockaddr (socket)
+  (:documentation "Return the size of a sockaddr object for SOCKET."))
index 5a609dc..8e2186f 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"0.8.0.67"
+"0.8.0.68"