Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions lib/ssh/src/ssh_connection.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1291,36 +1291,50 @@ handle_msg(#ssh_msg_global_request{name = _Type,
end;

handle_msg(#ssh_msg_request_failure{},
#connection{requests = [{_, From} | Rest]} = Connection, _, _SSH) ->
{[{channel_request_reply, From, {failure, <<>>}}],
Connection#connection{requests = Rest}};

handle_msg(#ssh_msg_request_failure{},
#connection{requests = [{_, From,_} | Rest]} = Connection, _, _SSH) ->
{[{channel_request_reply, From, {failure, <<>>}}],
Connection#connection{requests = Rest}};

handle_msg(#ssh_msg_request_success{data = Data},
#connection{requests = [{_, From} | Rest]} = Connection, _, _SSH) ->
{[{channel_request_reply, From, {success, Data}}],
Connection#connection{requests = Rest}};
#connection{requests = Requests} = Connection, _, _SSH) ->
case take_global_request(Requests) of
{{_, From}, Rest} ->
{[{channel_request_reply, From, {failure, <<>>}}],
Connection#connection{requests = Rest}};
{{_, From, _}, Rest} ->
{[{channel_request_reply, From, {failure, <<>>}}],
Connection#connection{requests = Rest}};
false ->
{[], Connection}
end;

handle_msg(#ssh_msg_request_success{data = Data},
#connection{requests = [{_, From, Fun} | Rest]} = Connection0, _, _SSH) ->
Connection = Fun({success,Data}, Connection0),
{[{channel_request_reply, From, {success, Data}}],
Connection#connection{requests = Rest}};

%% alive responses
handle_msg(#ssh_msg_request_success{},
#connection{requests = []} = Connection, _, _SSH) ->
{[], Connection};
#connection{requests = Requests} = Connection0, _, _SSH) ->
case take_global_request(Requests) of
{{_, From}, Rest} ->
{[{channel_request_reply, From, {success, Data}}],
Connection0#connection{requests = Rest}};
{{_, From, Fun}, Rest} ->
Connection = Fun({success, Data}, Connection0),
{[{channel_request_reply, From, {success, Data}}],
Connection#connection{requests = Rest}};
false ->
{[], Connection0}
end.

handle_msg(#ssh_msg_request_failure{},
#connection{requests = []} = Connection, _, _SSH) ->
{[], Connection}.


%%%----------------------------------------------------------------
%%% Find and remove the first global request entry (keyed by reference)
%%% from the requests list, skipping channel entries (keyed by integer).
%%% Returns {Entry, RemainingList} or false.
%%%
take_global_request([]) ->
false;
take_global_request([{Ref, _} = E | Rest]) when is_reference(Ref) ->
{E, Rest};
take_global_request([{Ref, _, _} = E | Rest]) when is_reference(Ref) ->
{E, Rest};
take_global_request([H | T]) ->
case take_global_request(T) of
{E, Rest} -> {E, [H | Rest]};
false -> false
end.

%%%----------------------------------------------------------------
%%% Returns pending responses to be delivered to the peer when a
Expand Down
4 changes: 3 additions & 1 deletion lib/ssh/src/ssh_connection_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,8 @@ get_repl({channel_data,undefined,_Data}, Acc) ->
get_repl({channel_data,Pid,Data}, Acc) ->
Pid ! {ssh_cm, self(), Data},
Acc;
get_repl({channel_request_reply,undefined,_Data}, Acc) ->
Acc;
get_repl({channel_request_reply,From,Data}, {CallRepls,S}) ->
{[{reply,From,Data}|CallRepls], S};
get_repl({flow_control,Cache,Channel,From,Msg}, {CallRepls,S}) ->
Expand Down Expand Up @@ -2226,7 +2228,7 @@ triggered_alive(StateName, D0 = #data{},
{stop, Shutdown, D};
_ ->
D = send_msg({ssh_msg_global_request,"keepalive@erlang.org", true, <<>>},
D0),
add_request(fun(_,Conn) -> Conn end, make_ref(), undefined, D0)),
Ssh = D#data.ssh_params,
Now = erlang:monotonic_time(milli_seconds),
Ssh1 = Ssh#ssh{alive_probes_sent = SentProbes + 1,
Expand Down
Loading