[usocket-devel] Support for UNIX sockets

kmkaplan+usocket-devel at ded.kim-minh.com kmkaplan+usocket-devel at ded.kim-minh.com
Fri Aug 15 12:00:42 UTC 2008


I need to connect to a UNIX domain socket using usocket.  Here is what
I came up with to make it work in SBCL.  Should this be done in another
function?

Index: backend/sbcl.lisp
===================================================================
--- backend/sbcl.lisp   (révision 423)
+++ backend/sbcl.lisp   (copie de travail)
@@ -213,8 +213,12 @@
              (not (fboundp 'sb-bsd-sockets::sockopt-tcp-nodelay)))
     (unsupported 'nodelay 'socket-connect))
 
-  (let* ((socket (make-instance 'sb-bsd-sockets:inet-socket
-                                :type :stream :protocol :tcp))
+  (let* ((socket (typecase host
+                  (pathname
+                   (make-instance 'sb-bsd-sockets:local-socket :type :stream))
+                  (t
+                   (make-instance 'sb-bsd-sockets:inet-socket
+                                  :type :stream :protocol :tcp))))
          (stream (sb-bsd-sockets:socket-make-stream socket
                                                     :input t
                                                     :output t
@@ -222,7 +226,9 @@
                                                     :element-type element-type))
          ;;###FIXME: The above line probably needs an :external-format
          (usocket (make-stream-socket :stream stream :socket socket))
-         (ip (host-to-vector-quad host)))
+         (raw-address (typecase host
+                       (pathname (list (namestring host)))
+                       (t (list (host-to-vector-quad host) port)))))
     (when (and nodelay-specified
                (fboundp 'sb-bsd-sockets::sockopt-tcp-nodelay))
       (setf (sb-bsd-sockets:sockopt-tcp-nodelay socket) nodelay))
@@ -232,7 +238,7 @@
                                    (or local-host *wildcard-host*))
                                   (or local-port *auto-port*)))
     (with-mapped-conditions (usocket)
-      (sb-bsd-sockets:socket-connect socket ip port))
+      (apply 'sb-bsd-sockets:socket-connect socket raw-address))
     usocket))

 (defun socket-listen (host port




More information about the usocket-devel mailing list