Skip to content

Commit

Permalink
add backoff flag : default true
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Gravell committed Oct 14, 2011
1 parent 4f7f6d3 commit f7a7953
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/smk_client.erl
Expand Up @@ -25,6 +25,7 @@
-type opt() :: -type opt() ::
{username, binary()} {username, binary()}
| {password, binary()} | {password, binary()}
| {cookie, binary()}
| {callback, fun()}. | {callback, fun()}.
-type opts() :: list(opt()). -type opts() :: list(opt()).
-type send_response() :: -type send_response() ::
Expand Down Expand Up @@ -208,8 +209,11 @@ init([Cache, Opts]) ->
lager:error("callback not defined"), lager:error("callback not defined"),
{stop, normal}; {stop, normal};
Callback -> Callback ->
Backoff = backoff(T), Backoff =
lager:info("connection backoff ~p, cache ~p", [Backoff, Cache]), case proplists:get_value(backoff, Opts, true) of
true -> backoff(T);
false -> 0
end,
timer:send_after(Backoff, {connect, Opts}), timer:send_after(Backoff, {connect, Opts}),
{ok, awaiting_session, #s{ {ok, awaiting_session, #s{
session=Session, session=Session,
Expand Down Expand Up @@ -274,7 +278,7 @@ handle_info({connect, Opts}, StateName, #s{session=Session, cache=Cache, name=Na
{next_state, StateName, NewState}; {next_state, StateName, NewState};
Error -> Error ->
lager:log(error, self(), "Connection error ~p", [Error]), lager:log(error, self(), "Connection error ~p", [Error]),
{stop, normal, State} {stop, Error, State}
end; end;


handle_info({heartbeat_timeout, _}, awaiting_session = StateName, State) -> handle_info({heartbeat_timeout, _}, awaiting_session = StateName, State) ->
Expand Down

0 comments on commit f7a7953

Please sign in to comment.