Changeset 12089 for trunk/source/level-1


Ignore:
Timestamp:
May 19, 2009, 8:30:54 AM (10 years ago)
Author:
gb
Message:

From Maciej Pasternacki: accept an :FD argument in MAKE-SOCKET and pass
it down to concrete socket constructors.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-1/l1-sockets.lisp

    r12033 r12089  
    666666                    local-filename remote-filename sharing basic
    667667                    external-format (auto-close t)
    668                     connect-timeout input-timeout output-timeout deadline)
     668                    connect-timeout input-timeout output-timeout deadline
     669                    fd)
    669670  "Create and return a new socket."
    670671  (declare (dynamic-extent keys))
     
    680681
    681682
    682 (defun make-udp-socket (&rest keys &aux (fd -1))
     683(defun make-udp-socket (&rest keys &key (fd -1) &allow-other-keys)
    683684  (unwind-protect
    684685    (let (socket)
    685       (setq fd (socket-call nil "socket"
    686                             (c_socket #$AF_INET #$SOCK_DGRAM #$IPPROTO_UDP)))
     686      (when (< fd 0)
     687        (setq fd (socket-call nil "socket"
     688                              (c_socket #$AF_INET #$SOCK_DGRAM #$IPPROTO_UDP))))
    687689      (apply #'set-socket-options fd keys)
    688690      (setq socket (make-instance 'udp-socket
     
    694696      (fd-close fd))))
    695697
    696 (defun make-tcp-socket (&rest keys &key connect &allow-other-keys &aux (fd -1))
     698(defun make-tcp-socket (&rest keys &key connect (fd -1) &allow-other-keys)
    697699  (unwind-protect
    698     (let (socket)
    699       (setq fd (socket-call nil "socket"
    700                             (c_socket #$AF_INET #$SOCK_STREAM #$IPPROTO_TCP)))
    701       (apply #'set-socket-options fd keys)
    702       (setq socket
    703             (ecase connect
    704               ((nil :active) (apply #'make-tcp-stream-socket fd keys))
    705               ((:passive) (apply #'make-tcp-listener-socket fd keys))))
    706       (setq fd -1)
    707       socket)
     700       (let (socket)
     701         (when (< fd 0)
     702           (setq fd (socket-call nil "socket"
     703                                 (c_socket #$AF_INET #$SOCK_STREAM #$IPPROTO_TCP))))
     704         (apply #'set-socket-options fd keys)
     705         (setq socket
     706               (ecase connect
     707                 ((nil :active) (apply #'make-tcp-stream-socket fd keys))
     708                 ((:passive) (apply #'make-tcp-listener-socket fd keys))))
     709         (setq fd -1)
     710         socket)
    708711    (unless (< fd 0)
    709712      (fd-close fd))))
    710713
    711 (defun make-stream-file-socket (&rest keys &key connect &allow-other-keys &aux (fd -1))
     714(defun make-stream-file-socket (&rest keys &key connect (fd -1) &allow-other-keys)
    712715  (unwind-protect
    713     (let (socket)
    714       (setq fd (socket-call nil "socket" (c_socket #$PF_UNIX #$SOCK_STREAM 0)))
    715       (apply #'set-socket-options fd keys)
    716       (setq socket
    717             (ecase connect
    718               ((nil :active) (apply #'make-file-stream-socket fd keys))
    719               ((:passive) (apply #'make-file-listener-socket fd keys))))
    720       (setq fd -1)
    721       socket)
     716       (let (socket)
     717         (when (< fd 0)
     718           (setq fd (socket-call nil "socket" (c_socket #$PF_UNIX #$SOCK_STREAM 0))))
     719         (apply #'set-socket-options fd keys)
     720         (setq socket
     721               (ecase connect
     722                 ((nil :active) (apply #'make-file-stream-socket fd keys))
     723                 ((:passive) (apply #'make-file-listener-socket fd keys))))
     724         (setq fd -1)
     725         socket)
    722726    (unless (< fd 0)
    723727      (fd-close fd))))
Note: See TracChangeset for help on using the changeset viewer.