               :c2
               :write)))))
 
+(defn poll-selector [bo timeout]
+  (if-not (zero? (.select bo timeout))
+    (let [ready (.selectedKeys bo)
+          v (doall (map (fn [k]
+                          {:channel (.channel k)
+                           :ops (.readyOps k)})
+                        ready))]
+      (.clear ready)
+      v)))
 
 (defn poll-channels [poll-set timeout]
   (with-open [bo (reduce (fn [s [channel & ops]]

            ;; Note this may block in connect(), I haven't decided if that's
            ;; bad or not
            (get ready-channels serversocket)
            (let [sock (accept-connection serversocket)]
              (recur nil
                     (if sock
                       (assoc downstreams-for-upstreams
                              sock
                              (doto (SocketChannel/open)
                                (.connect (InetSocketAddress. host port))
                                (.configureBlocking false)))
                       downstreams-for-upstreams)))
            :default
            (do
              (println "timeout")
              (recur pending-write downstreams-for-upstreams))


            ))))))



                           s)
                         (Selector/open)
                         poll-set)]
    (doall ; have to force evaluation of this before closing selector
     (poll-selector bo timeout))))

(deftest poll-test
  (testing "timeout"
