From 8e8b61c63431096cc8fdd4eaea7d7ed33c143847 Mon Sep 17 00:00:00 2001 From: Fredrik Gustafsson Date: Wed, 31 Oct 2012 10:45:16 +0100 Subject: Check cache on channel exec --- lib/ssh/src/ssh_connection_manager.erl | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'lib/ssh/src/ssh_connection_manager.erl') diff --git a/lib/ssh/src/ssh_connection_manager.erl b/lib/ssh/src/ssh_connection_manager.erl index 6e2fe9da74..9a96542505 100644 --- a/lib/ssh/src/ssh_connection_manager.erl +++ b/lib/ssh/src/ssh_connection_manager.erl @@ -234,6 +234,13 @@ handle_call({request, ChannelPid, ChannelId, Type, Data}, From, State0) -> %% channel is sent later when reply arrives from the connection %% handler. lists:foreach(fun send_msg/1, Replies), + SshOpts = proplists:get_value(ssh_opts, State0#state.opts), + case proplists:get_value(idle_time, SshOpts) of + infinity -> + ok; + _IdleTime -> + erlang:send_after(5000, self(), {check_cache, [], []}) + end, {noreply, State}; handle_call({request, ChannelId, Type, Data}, From, State0) -> @@ -613,18 +620,24 @@ check_cache(State, Cache) -> undefined -> State; Time -> - TimerRef = erlang:send_after(Time, self(), {'EXIT', [], "Timeout"}), - State#state{idle_timer_ref=TimerRef} + case State#state.idle_timer_ref of + undefined -> + TimerRef = erlang:send_after(Time, self(), {'EXIT', [], "Timeout"}), + State#state{idle_timer_ref=TimerRef}; + _ -> + State + end end; _ -> State end. remove_timer_ref(State) -> case State#state.idle_timer_ref of - infinity -> + infinity -> %% If the timer is not activated State; - _ -> - TimerRef = State#state.idle_timer_ref, + undefined -> %% If we already has cancelled the timer + State; + TimerRef -> %% Timer is active erlang:cancel_timer(TimerRef), State#state{idle_timer_ref = undefined} end. -- cgit v1.2.3