From 40e0af7c124479914a77ee634e745741e6fd6b0a Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Wed, 24 Aug 2016 14:17:27 +0700 Subject: [PATCH] Revert "[#259] TODO" (temp) This reverts commit 7ef597103b2c4005155428aef17c9553ef8cbb9f. --- src/taoensso/sente.cljc | 72 ++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 48 deletions(-) diff --git a/src/taoensso/sente.cljc b/src/taoensso/sente.cljc index bbffdf7..f51b567 100644 --- a/src/taoensso/sente.cljc +++ b/src/taoensso/sente.cljc @@ -593,11 +593,10 @@ (when (interfaces/sch-open? server-ch) ;; (assert (= _sch server-ch)) (when (= udt-t1 udt-t0) - ;; Ref. issue #230: ;; We've seen no send/recv activity on this ;; conn w/in our kalive window so send a ping ;; ->client (should auto-close conn if it's - ;; gone dead). + ;; gone dead) (interfaces/sch-send! server-ch websocket? (pack packer nil :chsk/ws-ping))) (recur udt-t1)))))) @@ -930,15 +929,14 @@ [client-id chs params packer url state_ ; {:type _ :open? _ :uid _ :csrf-token _ ...} - instance-handle_ retry-count_ ever-opened?_ + retry-handle_ retry-count_ ever-opened?_ backoff-ms-fn ; (fn [nattempt]) -> msecs cbs-waiting_ ; { ...} - socket_ - udt-last-comms_] + socket_] IChSocket (-chsk-disconnect! [chsk reason] - (reset! instance-handle_ nil) ; Disable auto retry + (reset! retry-handle_ "_disable-auto-retry") (swap-chsk-state! chsk #(chsk-state->closed % reason)) (when-let [s @socket_] (.close s 1000 "CLOSE_NORMAL"))) @@ -966,7 +964,6 @@ (try (.send @socket_ ppstr) - (reset! udt-last-comms_ (now-udt)) :apparent-success (catch :default e (errorf e "Chsk send error") @@ -983,8 +980,8 @@ (enc/oget goog/global "MozWebSocket") (enc/oget @?node-npm-websocket_ "w3cwebsocket"))] - (let [instance-handle (reset! instance-handle_ (enc/uuid-str)) - have-handle? (fn [] (= @instance-handle_ instance-handle)) + (let [retry-handle (enc/uuid-str) + have-handle? (fn [] (= @retry-handle_ retry-handle)) connect-fn (fn connect-fn [] (when (have-handle?) @@ -1035,15 +1032,14 @@ ;; whether they're wrapped or not [clj ?cb-uuid] (unpack packer ppstr)] - (reset! udt-last-comms_ (now-udt)) - (or (when (handshake? clj) (receive-handshake! :ws chsk clj) (reset! retry-count_ 0)) (when (= clj :chsk/ws-ping) - (receive-buffered-evs! chs [[:chsk/ws-ping]]) + (when @debug-mode?_ + (receive-buffered-evs! chs [[:debug/ws-ping]])) :noop) (if-let [cb-uuid ?cb-uuid] @@ -1081,27 +1077,7 @@ :last-ws-close last-ws-close)) (retry-fn))))))))))))] - ;; TODO ws-kalive-ms, document that it should be != server val - (when-let [ms (ms :secs 20)] - (go-loop [] - (let [udt-t0 @udt-last-comms_] - (server (should auto-close conn if it's - ;; gone dead). The server generally sends pings so - ;; this should be rare. Mostly here to help clients - ;; identify conns that were suddenly dropped. - - ;; TODO Confirm that a failed send will actually - ;; trigger on-error or on-close - (-chsk-send! chsk [:chsk/ws-ping] {}))) - (recur))))) - + (reset! retry-handle_ retry-handle) (reset! retry-count_ 0) (connect-fn) chsk))))) @@ -1110,13 +1086,12 @@ (defn- new-ChWebSocket [opts] (map->ChWebSocket (merge - {:state_ (atom {:type :ws :open? false :ever-opened? false}) - :instance-handle_ (atom nil) - :retry-count_ (atom 0) - :ever-opened?_ (atom false) - :cbs-waiting_ (atom {}) - :socket_ (atom nil) - :udt-last-comms_ (atom nil)} + {:state_ (atom {:type :ws :open? false :ever-opened? false}) + :retry-handle_ (atom "_pending") + :retry-count_ (atom 0) + :ever-opened?_ (atom false) + :cbs-waiting_ (atom {}) + :socket_ (atom nil)} opts)))) (def ^:private default-client-side-ajax-timeout-ms @@ -1131,13 +1106,13 @@ ;; Handles (re)polling, etc. [client-id chs params packer url state_ - instance-handle_ ever-opened?_ + retry-handle_ ever-opened?_ backoff-ms-fn ajax-opts curr-xhr_] IChSocket (-chsk-disconnect! [chsk reason] - (reset! instance-handle_ nil) ; Disable auto retry + (reset! retry-handle_ "_disable-auto-retry") (swap-chsk-state! chsk #(chsk-state->closed % reason)) (when-let [x @curr-xhr_] (.abort x))) @@ -1201,8 +1176,8 @@ :apparent-success)))) (-chsk-connect! [chsk] - (let [instance-handle (reset! instance-handle_ (enc/uuid-str)) - have-handle? (fn [] (= @instance-handle_ instance-handle)) + (let [retry-handle (enc/uuid-str) + have-handle? (fn [] (= @retry-handle_ retry-handle)) poll-fn ; async-poll-for-update-fn (fn poll-fn [retry-count] (tracef "async-poll-for-update!") @@ -1274,6 +1249,7 @@ (let [buffered-evs clj] ; An application reply (receive-buffered-evs! chs buffered-evs))))))))))))] + (reset! retry-handle_ retry-handle) (poll-fn 0) chsk)))) @@ -1281,10 +1257,10 @@ (defn- new-ChAjaxSocket [opts] (map->ChAjaxSocket (merge - {:state_ (atom {:type :ajax :open? false :ever-opened? false}) - :instance-handle_ (atom nil) - :ever-opened?_ (atom false) - :curr-xhr_ (atom nil)} + {:state_ (atom {:type :ajax :open? false :ever-opened? false}) + :retry-handle_ (atom "_pending") + :ever-opened?_ (atom false) + :curr-xhr_ (atom nil)} opts)))) #?(:cljs