Changeset 3728

Show
Ignore:
Timestamp:
08/07/08 22:06:50 (4 months ago)
Author:
hans
Message:

revert out usocket update again as it breaks buildbot tests on sbcl

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/thirdparty/usocket/Makefile

    r3727 r3728  
    11# $Id: Makefile 80 2006-02-12 10:09:49Z ehuelsmann $ 
    2 # $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/Makefile $ 
     2# $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/Makefile $ 
    33 
    44clean: 
  • trunk/thirdparty/usocket/README

    r3727 r3728  
    11                                                                -*- text -*- 
    22 
    3 $Id: README 249 2007-05-20 14:16:12Z ehuelsmann
     3$Id: README 334 2008-04-23 21:24:15Z hhubner
    44 
    55Content 
     
    9696 
    9797 
    98  
    99  
    10098Errors: 
    10199 - address-in-use-error 
  • trunk/thirdparty/usocket/TODO

    r3727 r3728  
    22- Implement wait-for-input-internal for 
    33    * SBCL Win32 
     4    * LispWorks Win32 
    45 
    56- Implement errors for (the alien interface code of) 
  • trunk/thirdparty/usocket/backend/allegro.lisp

    r3727 r3728  
    1 ;;;; $Id: allegro.lisp 405 2008-07-30 19:26:46Z ehuelsmann
    2 ;;;; $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/backend/allegro.lisp $ 
     1;;;; $Id: allegro.lisp 335 2008-04-23 21:29:50Z hhubner
     2;;;; $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/backend/allegro.lisp $ 
    33 
    44;;;; See LICENSE for licensing information. 
     
    5050    :binary)) 
    5151 
    52 (defun socket-connect (host port &key (element-type 'character) 
    53                        timeout deadline 
    54                        (nodelay t) ;; nodelay == t is the ACL default 
    55                        local-host local-port) 
    56   (when timeout (unsupported 'timeout 'socket-connect)) 
    57   (when deadline (unsupported 'deadline 'socket-connect)) 
    58  
     52(defun socket-connect (host port &key (element-type 'character) timeout nodelay) 
     53  (declare (ignore nodelay)) 
     54  (when timeout 
     55    (warn "SOCKET-CONNECT timeout not supported in Allegro CL")) 
    5956  (let ((socket)) 
    6057    (setf socket 
    6158          (with-mapped-conditions (socket) 
    62             (if timeout 
    63                 (mp:with-timeout (timeout nil) 
    64                   (socket:make-socket :remote-host (host-to-hostname host) 
    65                                       :remote-port port 
    66                                       :local-host (when local-host (host-to-hostname local-host)) 
    67                                       :local-port local-port 
    68                                       :format (to-format element-type) 
    69                                       :nodelay nodelay)) 
    70                 (socket:make-socket :remote-host (host-to-hostname host) 
    71                                     :remote-port port 
    72                                     :local-host local-host 
    73                                     :local-port local-port 
    74                                     :format (to-format element-type) 
    75                                     :nodelay nodelay)))) 
     59             (socket:make-socket :remote-host (host-to-hostname host) 
     60                                 :remote-port port 
     61                                 :format (to-format element-type)))) 
    7662    (make-stream-socket :socket socket :stream socket))) 
    7763 
     
    8167(defmethod socket-close ((usocket usocket)) 
    8268  "Close socket." 
    83   (when (wait-list usocket) 
    84      (remove-waiter (wait-list usocket) usocket)) 
    8569  (with-mapped-conditions (usocket) 
    8670    (close (socket usocket)))) 
     
    147131                               (host-to-hostname name)))))) 
    148132 
    149 (defun %setup-wait-list (wait-list) 
    150   (declare (ignore wait-list))) 
    151  
    152 (defun %add-waiter (wait-list waiter) 
    153   (push (socket waiter) (wait-list-%wait wait-list))) 
    154  
    155 (defun %remove-waiter (wait-list waiter) 
    156   (setf (wait-list-%wait wait-list) 
    157         (remove (socket waiter) (wait-list-%wait wait-list)))) 
    158  
    159 (defun wait-for-input-internal (wait-list &key timeout) 
     133(defun wait-for-input-internal (sockets &key timeout) 
    160134  (with-mapped-conditions () 
    161135    (let ((active-internal-sockets 
    162136           (if timeout 
    163                (mp:wait-for-input-available (wait-list-%wait wait-list
     137               (mp:wait-for-input-available (mapcar #'socket sockets
    164138                                            :timeout timeout) 
    165              (mp:wait-for-input-available (wait-list-%wait wait-list))))) 
     139             (mp:wait-for-input-available (mapcar #'socket sockets))))) 
    166140      ;; this is quadratic, but hey, the active-internal-sockets 
    167141      ;; list is very short and it's only quadratic in the length of that one. 
    168142      ;; When I have more time I could recode it to something of linear 
    169143      ;; complexity. 
    170       ;; [Same code is also used in openmcl.lisp] 
    171       (dolist (x active-internal-sockets) 
    172         (setf (state (gethash x (wait-list-map wait-list))) 
    173               :READ)) 
    174       wait-list))) 
     144      ;; [Same code is also used in lispworks.lisp, openmcl.lisp] 
     145      (remove-if #'(lambda (x) 
     146                     (not (member (socket x) active-internal-sockets))) 
     147                 sockets)))) 
  • trunk/thirdparty/usocket/backend/armedbear.lisp

    r3727 r3728  
    1 ;;;; $Id: armedbear.lisp 409 2008-07-31 05:50:06Z ehuelsmann
    2 ;;;; $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/backend/armedbear.lisp $ 
     1;;;; $Id: armedbear.lisp 335 2008-04-23 21:29:50Z hhubner
     2;;;; $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/backend/armedbear.lisp $ 
    33 
    44;;;; See LICENSE for licensing information. 
     
    8989    (java:jclass-name (jop-class instance))))) 
    9090 
    91 (declaim (inline jop-deref)) 
    9291(defun jop-deref (instance) 
    9392  (if (java-object-proxy-p instance) 
     
    187186    (error (error 'unknown-error :socket socket :real-error condition)))) 
    188187 
    189 (defun socket-connect (host port &key (element-type 'character) 
    190                        timeout deadline (nodelay nil nodelay-specified) 
    191                        local-host local-port) 
    192   (when deadline (unsupported 'deadline 'socket-connect)) 
    193   (when (or local-host local-port) 
    194     (unimplemented 'local-host 'socket-connect) 
    195     (unimplemented 'local-port 'socket-connect)) 
    196  
     188(defun socket-connect (host port &key (element-type 'character) timeout nodelay) 
     189  (declare (ignore nodelay)) 
     190  (when timeout 
     191    (warn "SOCKET-CONNECT timeout not supported in ABCL")) 
    197192  (let ((usock)) 
    198193    (with-mapped-conditions (usock) 
    199194      (let* ((sock-addr (jdi:jcoerce 
    200195                         (jdi:do-jnew-call "java.net.InetSocketAddress" 
    201                            (host-to-hostname host) 
    202                            (jdi:jcoerce port :int)) 
     196                                           (host-to-hostname host) 
     197                                           (jdi:jcoerce port :int)) 
    203198                         "java.net.SocketAddress")) 
    204199             (jchan (jdi:do-jstatic-call "java.nio.channels.SocketChannel" 
    205                       "open" sock-addr)) 
     200                                         "open" sock-addr)) 
    206201             (sock (jdi:do-jmethod-call jchan "socket"))) 
    207         (when nodelay-specified 
    208           (jdi:do-jmethod-call sock "setTcpNoDelay" 
    209                                (if nodelay 
    210                                    (java:make-immediate-object t :boolean) 
    211                                    (java:make-immediate-object nil :boolean)))) 
    212         (when timeout 
    213           (jdi:do-jmethod-call sock "setSoTimeout" 
    214                                     (truncate (* 1000 timeout)))) 
    215         (setf usock 
    216               (make-stream-socket 
    217                :socket jchan 
    218                :stream (ext:get-socket-stream (jdi:jop-deref sock) 
    219                                               :element-type element-type))))))) 
     202        (describe sock) 
     203         (setf usock 
     204               (make-stream-socket 
     205                :socket jchan 
     206                :stream (ext:get-socket-stream (jdi:jop-deref sock) 
     207                                               :element-type element-type))))))) 
    220208 
    221209(defun socket-listen (host port 
     
    261249 
    262250(defmethod socket-close ((usocket usocket)) 
    263   (when (wait-list usocket) 
    264      (remove-waiter (wait-list usocket) usocket)) 
    265251  (with-mapped-conditions (usocket) 
    266252    (jdi:do-jmethod (socket usocket) "close"))) 
     
    270256;; its buffers *and* closes the socket. 
    271257(defmethod socket-close ((usocket stream-usocket)) 
    272   (when (wait-list usocket) 
    273      (remove-waiter (wait-list usocket) usocket)) 
    274258  (with-mapped-conditions (usocket) 
    275259    (close (socket-stream usocket)))) 
    276260 
    277261(defmethod get-local-address ((usocket usocket)) 
    278   (dotted-quad-to-vector-quad (ext:socket-local-address 
    279                                (jdi:jop-deref 
    280                                 (jdi:do-jmethod-call (socket usocket) 
    281                                   "socket"))))) 
     262  (dotted-quad-to-vector-quad (ext:socket-local-address (socket usocket)))) 
    282263 
    283264(defmethod get-peer-address ((usocket stream-usocket)) 
    284   (dotted-quad-to-vector-quad (ext:socket-peer-address 
    285                                (jdi:jop-deref 
    286                                 (jdi:do-jmethod-call (socket usocket) 
    287                                   "socket"))))) 
     265  (dotted-quad-to-vector-quad (ext:socket-peer-address (socket usocket)))) 
    288266 
    289267(defmethod get-local-port ((usocket usocket)) 
    290   (ext:socket-local-port (jdi:jop-deref 
    291                           (jdi:do-jmethod-call (socket usocket) "socket")))) 
     268  (ext:socket-local-port (socket usocket))) 
    292269 
    293270(defmethod get-peer-port ((usocket stream-usocket)) 
    294   (ext:socket-peer-port (jdi:jop-deref 
    295                          (jdi:do-jmethod-call (socket usocket) "socket")))) 
     271  (ext:socket-peer-port (socket usocket))) 
    296272 
    297273(defmethod get-local-name ((usocket usocket)) 
     
    377353    "java.nio.channels.DatagramChannel"))) 
    378354 
    379 (defun wait-for-input-internal (wait-list &key timeout) 
    380   (let* ((sockets (wait-list-waiters wait-list)) 
    381          (ops (logior (op-read) (op-accept))) 
     355(defun wait-for-input-internal (sockets &key timeout) 
     356  (let* ((ops (logior (op-read) (op-accept))) 
    382357         (selector (jdi:do-jstatic "java.nio.channels.Selector" "open")) 
    383358         (channels (mapcar #'socket sockets))) 
    384359    (unwind-protect 
    385360        (with-mapped-conditions () 
    386           (let ((sel (jdi:jop-deref selector))) 
     361          (let ((jfalse (java:make-immediate-object nil :boolean)) 
     362                (sel (jdi:jop-deref selector))) 
    387363            (dolist (channel channels) 
    388364              (let ((chan (jdi:jop-deref channel))) 
     
    390366                                          "configureBlocking" 
    391367                                          "boolean") 
    392                             chan (java:make-immediate-object nil :boolean)
     368                            chan jfalse
    393369                (java:jcall (java:jmethod "java.nio.channels.SelectableChannel" 
    394370                                          "register" 
     
    404380                (let* ((selkeys (jdi:do-jmethod selector "selectedKeys")) 
    405381                       (selkey-iterator (jdi:do-jmethod selkeys "iterator")) 
    406                        (%wait (wait-list-%wait wait-list))
     382                       ready-sockets
    407383                  (loop while (java:jcall 
    408384                               (java:jmethod "java.util.Iterator" "hasNext") 
     
    413389                                  (chan (jdi:jop-deref 
    414390                                         (jdi:do-jmethod key "channel")))) 
    415                              (setf (state (gethash chan %wait)) 
    416                                    :READ)))))))) 
    417       ;; close the selector: all keys will be deregistered 
     391                             (push chan ready-sockets))) 
     392                  (remove-if #'(lambda (s) 
     393                                 (not (member (jdi:jop-deref (socket s)) 
     394                                              ready-sockets 
     395                                              :test #'(lambda (x y) 
     396                                                        (java:jcall (java:jmethod "java.lang.Object" 
     397                                                                             "equals" 
     398                                                                             "java.lang.Object") 
     399                                                                    x y))))) 
     400                             sockets)))))) 
     401      ;; cancel all Selector registrations 
     402      (let* ((keys (jdi:do-jmethod selector "keys")) 
     403             (iter (jdi:do-jmethod keys "iterator"))) 
     404        (loop while (java:jcall (java:jmethod "java.util.Iterator" "hasNext") 
     405                                (jdi:jop-deref iter)) 
     406              do (java:jcall 
     407                  (java:jmethod "java.nio.channels.SelectionKey" "cancel") 
     408                  (java:jcall (java:jmethod "java.util.Iterator" "next") 
     409                              (jdi:jop-deref iter))))) 
     410      ;; close the selector 
    418411      (java:jcall (java:jmethod "java.nio.channels.Selector" "close") 
    419412                  (jdi:jop-deref selector)) 
    420413      ;; make all sockets blocking again. 
    421      (dolist (channel channels) 
    422        (java:jcall (java:jmethod "java.nio.channels.SelectableChannel" 
    423                                  "configureBlocking" 
    424                                  "boolean") 
    425                       (jdi:jop-deref channel) 
    426                       (java:make-immediate-object t :boolean)))))) 
    427  
    428  
    429 ;; 
    430 ;; 
    431 ;; 
    432 ;; The WAIT-LIST part 
    433 ;; 
    434  
    435 ;; 
    436 ;; Note that even though Java has the concept of the Selector class, which 
    437 ;; remotely looks like a wait-list, it requires the sockets to be non-blocking. 
    438 ;; usocket however doesn't make any such guarantees and is therefore unable to 
    439 ;; use the concept outside of the waiting routine itself (blergh!). 
    440 ;; 
    441  
    442 (defun %setup-wait-list (wl) 
    443   (setf (wait-list-%wait wl) 
    444         (make-hash-table :test #'equal :rehash-size 1.3d0))) 
    445  
    446 (defun %add-waiter (wl w) 
    447   (setf (gethash (jdi:jop-deref (socket w)) (wait-list-%wait wl)) 
    448         w)) 
    449  
    450 (defun %remove-waiter (wl w) 
    451   (remhash (socket w) (wait-list-%wait wl))) 
     414      (let ((jtrue (java:make-immediate-object t :boolean))) 
     415        (dolist (chan channels) 
     416          (java:jcall (java:jmethod "java.nio.channels.SelectableChannel" 
     417                                          "configureBlocking" 
     418                                          "boolean") 
     419                      (jdi:jop-deref chan) jtrue)))))) 
     420 
  • trunk/thirdparty/usocket/backend/clisp.lisp

    r3727 r3728  
    1 ;;;; $Id: clisp.lisp 405 2008-07-30 19:26:46Z ehuelsmann
    2 ;;;; $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/backend/clisp.lisp $ 
     1;;;; $Id: clisp.lisp 335 2008-04-23 21:29:50Z hhubner
     2;;;; $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/backend/clisp.lisp $ 
    33 
    44;;;; See LICENSE for licensing information. 
     
    5656               (signal usock-err :socket socket))))))) 
    5757 
    58 (defun socket-connect (host port &key (element-type 'character) 
    59                        timeout deadline (nodelay t nodelay-specified) 
    60                        local-host local-port) 
     58(defun socket-connect (host port &key (element-type 'character) timeout nodelay) 
    6159  (declare (ignore nodelay)) 
    62   (when timeout (unsupported 'timeout 'socket-connect)) 
    63   (when deadline (unsupported 'deadline 'socket-connect)) 
    64   (when nodelay-specified (unsupported 'nodelay 'socket-connect)) 
    65   (when (or local-host local-port) 
    66      (unsupported 'local-host 'socket-connect) 
    67      (unsupported 'local-port 'socket-connect)) 
    68  
     60  (when timeout 
     61    (warn "SOCKET-CONNECT timeout not supported in CLISP")) 
    6962  (let ((socket) 
    7063        (hostname (host-to-hostname host))) 
    7164    (with-mapped-conditions (socket) 
    72       (setf socket 
    73             (if timeout 
    74                 (socket:socket-connect port hostname 
    75                                        :element-type element-type 
    76                                        :buffered t 
    77                                        :timeout timeout) 
    78                 (socket:socket-connect port hostname 
    79                                        :element-type element-type 
    80                                        :buffered t)))) 
     65       (setf socket 
     66             (socket:socket-connect port hostname 
     67                                    :element-type element-type 
     68                                    :buffered t))) 
    8169    (make-stream-socket :socket socket 
    8270                        :stream socket))) ;; the socket is a stream too 
     
    112100(defmethod socket-close ((usocket usocket)) 
    113101  "Close socket." 
    114   (when (wait-list usocket) 
    115      (remove-waiter (wait-list usocket) usocket)) 
    116102  (with-mapped-conditions (usocket) 
    117103    (close (socket usocket)))) 
    118104 
    119105(defmethod socket-close ((usocket stream-server-usocket)) 
    120   (when (wait-list usocket) 
    121      (remove-waiter (wait-list usocket) usocket)) 
    122106  (socket:socket-server-close (socket usocket))) 
    123107 
     
    147131 
    148132 
    149 (defun %setup-wait-list (wait-list) 
    150   (declare (ignore wait-list))) 
    151  
    152 (defun %add-waiter (wait-list waiter) 
    153   (push (cons (socket waiter) NIL) (wait-list-%wait wait-list))) 
    154  
    155 (defun %remove-waiter (wait-list waiter) 
    156   (setf (wait-list-%wait wait-list) 
    157         (remove (socket waiter) (wait-list-%wait wait-list) :key #'car))) 
    158  
    159 (defmethod wait-for-input-internal (wait-list &key timeout) 
     133(defmethod wait-for-input-internal (sockets &key timeout) 
    160134  (with-mapped-conditions () 
    161135    (multiple-value-bind 
    162136        (secs musecs) 
    163137        (split-timeout (or timeout 1)) 
    164       (dolist (x (wait-list-%wait wait-list)) 
    165         (setf (cdr x) :INPUT)) 
    166       (let* ((request-list (wait-list-%wait wait-list)) 
     138      (let* ((request-list (mapcar #'(lambda (x) 
     139                                       (if (stream-server-usocket-p x) 
     140                                           (socket x) 
     141                                         (list (socket x) :input))) 
     142                                   sockets)) 
    167143             (status-list (if timeout 
    168144                              (socket:socket-status request-list secs musecs) 
    169                             (socket:socket-status request-list))) 
    170              (sockets (wait-list-waiters wait-list))) 
    171         (do* ((x (pop sockets) (pop sockets)) 
    172               (y (pop status-list) (pop status-list))) 
    173              ((null x)) 
    174           (when (eq y :INPUT) 
    175             (setf (state x) :READ))) 
    176         wait-list)))) 
     145                            (socket:socket-status request-list)))) 
     146        (remove nil 
     147                (mapcar #'(lambda (x y) 
     148                            (when y x)) 
     149                        sockets status-list)))))) 
    177150 
    178151 
     
    247220 
    248221  (defmethod socket-close ((usocket datagram-usocket)) 
    249     (when (wait-list usocket) 
    250        (remove-waiter (wait-list usocket) usocket)) 
    251222    (rawsock:sock-close (socket usocket))) 
    252223   
  • trunk/thirdparty/usocket/backend/cmucl.lisp

    r3727 r3728  
    1 ;;;; $Id: cmucl.lisp 405 2008-07-30 19:26:46Z ehuelsmann
    2 ;;;; $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/backend/cmucl.lisp $ 
     1;;;; $Id: cmucl.lisp 335 2008-04-23 21:29:50Z hhubner
     2;;;; $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/backend/cmucl.lisp $ 
    33 
    44;;;; See LICENSE for licensing information. 
     
    5151                                               :condition condition)))) 
    5252 
    53 (defun socket-connect (host port &key (element-type 'character) 
    54                        timeout deadline (nodelay t nodelay-specified) 
    55                        local-host local-port) 
     53(defun socket-connect (host port &key (element-type 'character) timeout nodelay) 
    5654  (declare (ignore nodelay)) 
    57   (when timeout (unsupported 'timeout 'socket-connect)) 
    58   (when deadline (unsupported 'deadline 'socket-connect)) 
    59   (when nodelay-specified (unsupported 'nodelay 'socket-connect)) 
    60   (when (or local-host local-port) 
    61      (unsupported 'local-host 'socket-connect) 
    62      (unsupported 'local-port 'socket-connect)) 
    63  
     55  (when timeout 
     56    (warn "SOCKET-CONNECT timeout not supported in CMUCL")) 
    6457  (let* ((socket)) 
    6558    (setf socket 
     
    108101(defmethod socket-close ((usocket stream-usocket)) 
    109102  "Close socket." 
    110   (when (wait-list usocket) 
    111      (remove-waiter (wait-list usocket) usocket)) 
    112103  (with-mapped-conditions (usocket) 
    113104    (close (socket-stream usocket)))) 
     
    115106(defmethod socket-close ((usocket usocket)) 
    116107  "Close socket." 
    117   (when (wait-list usocket) 
    118      (remove-waiter (wait-list usocket) usocket)) 
    119108  (with-mapped-conditions (usocket) 
    120109    (ext:close-socket (socket usocket)))) 
     
    177166  (unix:unix-gethostname)) 
    178167 
    179 (defun %setup-wait-list (wait-list) 
    180   (declare (ignore wait-list))) 
    181  
    182 (defun %add-waiter (wait-list waiter) 
    183   (push (socket waiter) (wait-list-%wait wait-list))) 
    184  
    185 (defun %remove-waiter (wait-list waiter) 
    186   (setf (wait-list-%wait wait-list) 
    187         (remove (socket waiter) (wait-list-%wait wait-list)))) 
    188  
    189 (defun wait-for-input-internal (wait-list &key timeout) 
     168(defun wait-for-input-internal (sockets &key timeout) 
     169  #+MP 
     170  (progn 
     171    (unless (= 1 (length sockets)) 
     172      (error "can't wait for multiple file descriptors with multiprocessing enabled")) 
     173    (mp:process-wait-until-fd-usable (socket (car sockets)) :input timeout) 
     174    sockets) 
     175  #-MP 
    190176  (with-mapped-conditions () 
    191177    (alien:with-alien ((rfds (alien:struct unix:fd-set))) 
    192178       (unix:fd-zero rfds) 
    193        (dolist (socket (wait-list-%wait wait-list)
    194          (unix:fd-set socket rfds)) 
     179       (dolist (socket sockets
     180         (unix:fd-set (socket socket) rfds)) 
    195181       (multiple-value-bind 
    196182           (secs musecs) 
     
    198184         (multiple-value-bind 
    199185             (count err) 
    200              (unix:unix-fast-select (1+ (reduce #'max 
    201                                                 (wait-list-%wait wait-list))) 
     186             (unix:unix-fast-select (1+ (reduce #'max sockets 
     187                                                :key #'socket)) 
    202188                                    (alien:addr rfds) nil nil 
    203189                                    (when timeout secs) musecs) 
    204190           (if (<= 0 count) 
    205191               ;; process the result... 
    206                (dolist (x (wait-list-waiters wait-list)
    207                  (when (unix:fd-isset (socket x) rfds
    208                    (setf (state x) :READ))
     192               (remove-if #'(lambda (x
     193                              (not (unix:fd-isset (socket x) rfds))
     194                          sockets
    209195             (progn 
    210196               ;;###FIXME generate an error, except for EINTR 
  • trunk/thirdparty/usocket/backend/lispworks.lisp

    r3727 r3728  
    1 ;;;; $Id: lispworks.lisp 406 2008-07-30 20:56:49Z ehuelsmann
    2 ;;;; $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/backend/lispworks.lisp $ 
     1;;;; $Id: lispworks.lisp 335 2008-04-23 21:29:50Z hhubner
     2;;;; $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/backend/lispworks.lisp $ 
    33 
    44;;;; See LICENSE for licensing information. 
     
    7474                    (raise-usock-err errno socket condition))))) 
    7575 
    76 (defun socket-connect (host port &key (element-type 'base-char) 
    77                        timeout deadline (nodelay t nodelay-specified) 
    78                        local-host local-port) 
    79   (declare (ignorable nodelay)) 
    80   (when timeout (unimplemented 'timeout 'socket-connect)) 
    81   (when deadline (unsupported 'deadline 'socket-connect :minimum "LispWorks 5.1")) 
    82    
    83   #+(and (not lispworks4) (not lispworks5.0)) 
    84   (when nodelay-specified (unimplemented 'nodelay 'socket-connect)) 
    85   #+lispworks4 
    86   (when (or local-host local-port) 
    87      (unsupported 'local-host 'socket-connect :minimum "LispWorks 5.0+ (verified)") 
    88      (unsupported 'local-port 'socket-connect :minimum "LispWorks 5.0+ (verified)")) 
    89  
     76(defun socket-connect (host port &key (element-type 'base-char) timeout nodelay) 
     77  (declare (ignore nodelay)) 
     78  (when timeout 
     79    (warn "SOCKET-CONNECT timeout not supported in Lispworks")) 
    9080  (let ((hostname (host-to-hostname host)) 
    9181        (stream)) 
     
    9383          (with-mapped-conditions () 
    9484             (comm:open-tcp-stream hostname port 
    95                                    :element-type element-type 
    96                                    #-lispworks4 #-lispworks4 
    97                                    #-lispworks4 #-lispworks4 
    98                                    :local-address (when local-host (host-to-hostname local-host)) 
    99                                    :local-port local-port 
    100                                    #+(and (not lispworks4) (not lispworks5.0)) 
    101                                    #+(and (not lispworks4) (not lispworks5.0)) 
    102                                    :nodelay nodelay))) 
     85                                   :element-type element-type))) 
    10386    (if stream 
    10487        (make-stream-socket :socket (comm:socket-stream-socket stream) 
     
    11194                           (backlog 5) 
    11295                           (element-type 'base-char)) 
    113   #+lispworks4.1 
    114   (unsupported 'host 'socket-listen :minimum "LispWorks 4.0 or newer than 4.1") 
    115   #+lispworks4.1 
    116   (unsupported 'backlog 'socket-listen :minimum "LispWorks 4.0 or newer than 4.1") 
    117  
    11896  (let* ((reuseaddress (if reuse-address-supplied-p reuse-address reuseaddress)) 
    11997         (comm::*use_so_reuseaddr* reuseaddress) 
     
    143121(defmethod socket-close ((usocket stream-usocket)) 
    144122  "Close socket." 
    145   (when (wait-list usocket) 
    146      (remove-waiter (wait-list usocket) usocket)) 
    147123  (close (socket-stream usocket))) 
    148124 
    149125(defmethod socket-close ((usocket usocket)) 
    150   (when (wait-list usocket) 
    151      (remove-waiter (wait-list usocket) usocket)) 
    152126  (with-mapped-conditions (usocket) 
    153127     (comm::close-socket (socket usocket)))) 
     
    187161(defun usocket-listen (usocket) 
    188162  (if (stream-usocket-p usocket) 
    189       (when (listen (socket-stream usocket)) 
     163      (when (listen (socket usocket)) 
    190164        usocket) 
    191165    (when (comm::socket-listen (socket usocket)) 
     
    199173 
    200174#-win32 
    201 (progn 
    202  
    203   (defun %setup-wait-list (wait-list) 
    204     (declare (ignore wait-list))) 
    205  
    206   (defun %add-waiter (wait-list waiter) 
    207     (declare (ignore wait-list waiter))) 
    208  
    209   (defun %remove-waiter (wait-list waiter) 
    210     (declare (ignore wait-list waiter))) 
    211  
    212   (defun wait-for-input-internal (wait-list &key timeout) 
    213     (with-mapped-conditions () 
    214       ;; unfortunately, it's impossible to share code between 
    215       ;; non-win32 and win32 platforms... 
    216       ;; Can we have a sane -pref. complete [UDP!?]- API next time, please? 
    217       (dolist (x (wait-list-waiters wait-list)) 
    218         (mp:notice-fd (os-socket-handle x))) 
    219       (mp:process-wait-with-timeout "Waiting for a socket to become active" 
    220                                     (truncate timeout) 
    221                                     #'(lambda (socks) 
    222                                         (let (rv) 
    223                                           (dolist (x socks rv) 
    224                                             (when (usocket-listen x) 
    225                                               (setf (state x) :READ 
    226                                                     rv t))))) 
    227                                     (wait-list-waiters wait-list)) 
    228       (dolist (x (wait-list-waiters wait-list)) 
    229         (mp:unnotice-fd (os-socket-handle x))) 
    230       wait-list))) 
     175(defun wait-for-input-internal (sockets &key timeout) 
     176  (with-mapped-conditions () 
     177    ;; unfortunately, it's impossible to share code between 
     178    ;; non-win32 and win32 platforms... 
     179    ;; Can we have a sane -pref. complete [UDP!?]- API next time, please? 
     180    (mapcar #'mp:notice-fd sockets 
     181            :key #'os-socket-handle) 
     182    (mp:process-wait-with-timeout "Waiting for a socket to become active" 
     183                                  (truncate timeout) 
     184                                  #'(lambda (socks) 
     185                                      (some #'usocket-listen socks)) 
     186                                  sockets) 
     187    (mapcar #'mp:unnotice-fd sockets 
     188            :key #'os-socket-handle) 
     189    (remove nil (mapcar #'usocket-listen sockets)))) 
    231190 
    232191 
     
    273232  (defconstant fionread 1074030207) 
    274233 
    275  
    276   ;; Note: 
    277   ;; 
    278   ;;  If special finalization has to occur for a given 
    279   ;;  system resource (handle), an associated object should 
    280   ;;  be created.  A special cleanup action should be added 
    281   ;;  to the system and a special cleanup action should 
    282   ;;  be flagged on all objects created for resources like it 
    283   ;; 
    284   ;;  We have 2 functions to do so: 
    285   ;;   * hcl:add-special-free-action (function-symbol) 
    286   ;;   * hcl:flag-special-free-action (object) 
    287   ;; 
    288   ;;  Note that the special free action will be called on all 
    289   ;;  objects which have been flagged for special free, so be 
    290   ;;  sure to check for the right argument type! 
    291    
    292234  (fli:define-foreign-type ws-socket () '(:unsigned :int)) 
    293235  (fli:define-foreign-type win32-handle () '(:unsigned :int)) 
     
    334276  ;; Now that we have access to the system calls, this is the plan: 
    335277 
    336   ;; 1. Receive a wait-list with associated sockets to wait for 
     278  ;; 1. Receive a list of sockets to listen to 
    337279  ;; 2. Add all those sockets to an event handle 
    338280  ;; 3. Listen for an event on that handle (we have a LispWorks system:: internal for that) 
     
    354296          0)))) 
    355297 
     298  (defun add-socket-to-event (socket event-object) 
     299    (let ((events (etypecase socket 
     300                    (stream-server-usocket (logior fd-connect fd-accept fd-close)) 
     301                    (stream-usocket (logior fd-connect fd-read fd-oob fd-close))))) 
     302      (maybe-wsa-error 
     303       (wsa-event-select (os-socket-handle socket) event-object events) 
     304       socket))) 
     305 
    356306  (defun socket-ready-p (socket) 
    357307     (if (typep socket 'stream-usocket) 
     
    362312    (notany #'socket-ready-p sockets)) 
    363313 
    364   (defun wait-for-input-internal (wait-list &key timeout) 
    365     (when (waiting-required (wait-list-waiters wait-list)) 
    366       (system:wait-for-single-object (wait-list-%wait wait-list) 
    367                                      "Waiting for socket activity" timeout)) 
    368     (update-ready-and-state-slots (wait-list-waiters wait-list))) 
    369  
    370    
     314  (defun wait-for-input-internal (sockets &key timeout) 
     315    (let ((event-object (wsa-event-create))) 
     316      (unwind-protect 
     317          (progn 
     318            (when (waiting-required sockets) 
     319              (dolist (socket sockets) 
     320                (add-socket-to-event socket event-object)) 
     321              (system:wait-for-single-object event-object 
     322                                             "Waiting for socket activity" timeout)) 
     323            (update-ready-slots sockets) 
     324            (sockets-ready sockets)) 
     325        (wsa-event-close event-object)))) 
     326 
    371327  (defun map-network-events (func network-events) 
    372328    (let ((event-map (fli:foreign-slot-value network-events 'network-events)) 
     
    374330      (unless (zerop event-map) 
    375331          (dotimes (i fd-max-events) 
    376             (unless (zerop (ldb (byte 1 i) event-map)) ;;### could be faster with ash and logand? 
     332            (unless (zerop (ldb (byte 1 i) event-map)) 
    377333              (funcall func (fli:foreign-aref error-array i))))))) 
    378334 
    379   (defun update-ready-and-state-slots (sockets) 
     335  (defun update-ready-slots (sockets) 
    380336     (dolist (socket sockets) 
    381         (if (or (and (stream-usocket-p socket) 
    382                      (listen (socket-stream socket))) 
    383                 (%ready-p socket)) 
    384             (setf (state socket) :READ) 
    385           (multiple-value-bind 
    386                 (rv network-events) 
    387                 (wsa-enum-network-events (os-socket-handle socket) 0 t) 
    388              (if (zerop rv) 
     337        (unless (or (stream-usocket-p socket) ;; no need to check status for streams 
     338                    (%ready-p socket))        ;; and sockets already marked ready 
     339           (multiple-value-bind 
     340                 (rv network-events) 
     341                 (wsa-enum-network-events (os-socket-handle socket) 0 t) 
     342              (if (zerop rv) 
    389343                 (map-network-events #'(lambda (err-code) 
    390344                                          (if (zerop err-code) 
    391                                              (setf (%ready-p socket) t 
    392                                                    (state socket) :READ) 
     345                                             (setf (%ready-p socket) t) 
    393346                                             (raise-usock-err err-code socket))) 
    394347                                     network-events) 
    395348                 (maybe-wsa-error rv socket)))))) 
    396349 
    397  
    398  
    399   ;; The wait-list part 
    400  
    401   (defun free-wait-list (wl) 
    402     (when (wait-list-p wl) 
    403       (unless (null (wait-list-%wait wl)) 
    404         (wsa-event-close (wait-list-%wait wl))))) 
    405    
    406   (hcl:add-special-free-action 'free-wait-list) 
    407    
    408   (defun %setup-wait-list (wait-list) 
    409     (hcl:flag-special-free-action wait-list) 
    410     (setf (wait-list-%wait wait-list) (wsa-event-create))) 
    411  
    412   (defun %add-waiter (wait-list waiter) 
    413     (let ((events (etypecase waiter 
    414                     (stream-server-usocket (logior fd-connect fd-accept fd-close)) 
    415                     (stream-usocket (logior fd-connect fd-read fd-oob fd-close))))) 
    416       (maybe-wsa-error 
    417        (wsa-event-select (os-socket-handle waiter) (wait-list-%wait wait-list) events) 
    418        waiter))) 
    419  
    420   (defun %remove-waiter (wait-list waiter) 
    421     (maybe-wsa-error 
    422      (wsa-event-select (os-socket-handle waiter) (wait-list-%wait wait-list) 0) 
    423      waiter)) 
     350  (defun sockets-ready (sockets) 
     351    (remove-if-not #'socket-ready-p sockets)) 
    424352   
    425353  );; end of WIN32-block 
  • trunk/thirdparty/usocket/backend/openmcl.lisp

    r3727 r3728  
    1 ;;;; $Id: openmcl.lisp 414 2008-08-07 18:50:26Z ehuelsmann
    2 ;;;; $URL: svn+ssh://common-lisp.net/project/usocket/svn/usocket/trunk/backend/openmcl.lisp $ 
     1;;;; $Id: openmcl.lisp 335 2008-04-23 21:29:50Z hhubner
     2;;;; $URL: svn://common-lisp.net/project/usocket/svn/usocket/branches/hans/backend/openmcl.lisp $ 
    33 
    44;;;; See LICENSE for licensing information. 
     
    3333  (ccl::rletZ ((tv :timeval)) 
    3434    (ccl::ticks-to-timeval ticks-to-wait tv) 
    35     ;;### The trickery below can be moved to the wait-list now... 
    3635    (ccl::%stack-block ((infds ccl::*fd-set-size*)) 
    3736      (ccl::fd-zero infds) 
    3837      (let ((max-fd -1)) 
    3938        (dolist (sock sockets) 
    40           (let ((fd (openmcl-socket:socket-os-fd (socket sock)))) 
     39          (let ((fd (openmcl-socket:socket-os-fd sock))) 
    4140            (setf max-fd (max max-fd fd)) 
    4241            (ccl::fd-set fd infds))) 
     
    4544                              (if ticks-to-wait tv (ccl::%null-ptr))))) 
    4645          (when (> res 0) 
    47             (dolist (x sockets) 
    48               (when (ccl::fd-is-set (openmcl-socket:socket-os-fd (socket x)) 
    49                                     infds) 
    50                 (setf (state x) :READ)))) 
    51           sockets))))) 
     46            (remove-if #'(lambda (x) 
     47                           (not (ccl::fd-is-set (openmcl-socket:socket-os-fd x) 
     48                                                infds))) 
     49                       sockets))))))) 
    5250 
    5351(defun raise-error-from-id (condition-id socket real-condition) 
     
    7573    :binary)) 
    7674 
    77 (defun socket-connect (host port &key (element-type 'character) timeout deadline nodelay 
    78                        local-host local-port) 
     75(defun socket-connect (host port &key (element-type 'character) timeout deadline nodelay) 
    7976  (with-mapped-conditions () 
    8077    (let ((mcl-sock 
    8178           (openmcl-socket:make-socket :remote-host (host-to-hostname host) 
    8279                                       :remote-port port 
    83                                        :local-host (when local-host (host-to-hostname local-host)) 
    84                                        :local-port local-port 
    8580                                       :format (to-format element-type) 
    8681                                       :deadline deadline 
     
    118113;; by the same object. 
    119114(defmethod socket-