Skip to content

Commit 9a3ab23

Browse files
committed
Finished up backoff support.
1 parent 31eda61 commit 9a3ab23

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/tcp-client-mgr.lfe

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@
6767
(maps:put 'requests #m())))
6868
(actions `(#(#(timeout reconnect) ,(backoff:get b) undefined))))
6969
`#(keep_state ,data ,actions)))
70-
(('internal 'connect (= `#m(host ,host port ,port tcp-opts ,opts) data))
70+
(('internal 'connect (= `#m(host ,host port ,port tcp-opts ,opts backoff ,b) data))
7171
(case (gen_tcp:connect host port opts)
7272
(`#(ok ,sock) `#(next_state connected ,(maps:put 'socket sock data)))
73-
(`#(error ,err) (progn
73+
(`#(error ,err) (let ((actions `(#(#(timeout reconnect) ,(backoff:get b) undefined))))
7474
(io:format "Connection failed: ~ts~n" `(,(inet:format_error err)))
75-
'keep_state_and_data))))
75+
`#(keep_state ,data ,actions)))))
7676
(('#(timeout reconnect) _ (= `#m(backoff ,b) data))
7777
(io:format "Attempting to reconnect ...~n")
7878
(let ((`#(,_ ,b) (backoff:fail b)))
@@ -89,6 +89,7 @@
8989
(defun connected
9090
(('enter _old-state (= `#m(backoff ,b) data))
9191
(let ((`#(,_ ,b) (backoff:succeed b)))
92+
(io:format "Connected.")
9293
`#(keep_state ,(mset data 'backoff b))))
9394
(('info `#(tcp_closed ,sock) (= `#m(socket ,sock) data))
9495
`#(next_state disconnected ,data))

0 commit comments

Comments
 (0)