anchor.diff:          (describe sock)
            (setf usock
                  (make-stream-socket
  -                :socket sock
  +                :socket jchan
                   :stream (ext:get-socket-stream (jdi:jop-deref sock)
                                                  :element-type element-type)))))))
   
  
positive.code:                          (jdi:jcoerce sock-addr
                                        "java.net.SocketAddress")
                           (jdi:jcoerce backlog :int))
      (make-stream-server-socket sock :element-type element-type)))
  
  (defmethod socket-accept ((socket stream-server-usocket) &key element-type)
    (let* ((jsock (socket socket))
           (jacc-sock (jdi:do-jmethod-call jsock "accept"))
           (jacc-stream
            (ext:get-socket-stream (jdi:jop-deref jacc-sock)
                                   :element-type (or element-type
                                                     (element-type socket)))))
      (make-stream-socket :socket jacc-sock
                          :stream jacc-stream)))
  
  ;;(defun print-java-exception (e)
  
negative.code:           (t
             "java.nio.channels.DatagramChannel"))))
  
  (defun socket-channel-class (socket)
    (cond
     ((stream-usocket-p socket)
      "java.nio.channels.SocketChannel")
     ((stream-server-usocket-p socket)
      "java.nio.channels.ServerSocketChannel")
     ((datagram-usocket-p socket)
      "java.nio.channels.DatagramChannel")))
  
  (defun wait-for-input-internal (sockets &key timeout)
    (let* ((ops (logior (op-read) (op-accept)))
           (selector (jdi:do-jstatic "java.nio.channels.Selector" "open"))
           (channels (mapcar #'socket sockets)))
      (unwind-protect
  ;;       (with-mapped-conditions ()
          (progn
            (let ((jfalse (java:make-immediate-object nil :boolean))
                  (sel (jdi:jop-deref selector)))
              (dolist (channel channels)
                (let ((chan (jdi:jop-deref channel)))
                  (java:jcall (java:jmethod "java.nio.channels.SelectableChannel"
                                            "configureBlocking"
                                            "boolean")
                              chan jfalse)
                  (java:jcall (java:jmethod "java.nio.channels.SelectableChannel"
                                            "register"
                                            "java.nio.channels.Selector" "int")
                              chan sel (logand ops (valid-ops channel)))))
              (let ((ready-count
                     (java:jcall (java:jmethod "java.nio.channels.Selector"
                                               "select"
                                               "long")
                                 sel (truncate (* timeout 1000)))))
                (when (< 0 ready-count)
                  ;; we actually have work to do
                  (let* ((selkeys (jdi:do-jmethod selector "selectedKeys"))
                         (selkey-iterator (jdi:do-jmethod selkeys "iterator"))
                         ready-sockets)
                    (loop while (java:jcall
                                 (java:jmethod "java.util.Iterator" "hasNext")
                                 (jdi:jop-deref selkey-iterator))
                          do (let* ((key (jdi:jcoerce
                                          (jdi:do-jmethod selkey-iterator "next")
                                          "java.nio.channels.SelectionKey"))
                                    (chan (jdi:jop-deref
                                           (jdi:do-jmethod key "channel"))))
                               (push chan ready-sockets)))
                    (remove-if #'(lambda (s)
                                   (not (member (jdi:jop-deref (socket s))
                                                ready-sockets
                                                :test #'(lambda (x y)
                                                          (java:jcall (java:jmethod "java.lang.Object"
                                                                               "equals"
                                                                               "java.lang.Object")
                                                                      x y)))))
                               sockets))))))
        ;; cancel all Selector registrations
        (let* ((keys (jdi:do-jmethod selector "keys"))
               (iter (jdi:do-jmethod keys "iterator")))
          (loop while (java:jcall (java:jmethod "java.util.Iterator" "hasNext")
                                  (jdi:jop-deref iter))
                do (java:jcall
                    (java:jmethod "java.nio.channels.SelectionKey" "cancel")
                    (java:jcall (java:jmethod "java.util.Iterator" "next")
                                (jdi:jop-deref iter)))))
        ;; close the selector
        (java:jcall (java:jmethod "java.nio.channels.Selector" "close")
                    (jdi:jop-deref selector))
        ;; make all sockets blocking again.
        (let ((jtrue (java:make-immediate-object t :boolean)))
          (dolist (chan channels)
            (java:jcall (java:jmethod "java.nio.channels.SelectableChannel"
                                            "configureBlocking"
                                            "boolean")
                        (jdi:jop-deref chan) jtrue))))))
  
  