From b4980254bc4596e7e1f80b44ce60dedd3c61f4d1 Mon Sep 17 00:00:00 2001 From: Hans Nilsson Date: Tue, 17 Sep 2019 09:46:04 +0200 Subject: ssh: For channel requests, add a fun() as a possibilty to what to do when the response arrives. The fun() could do updates of the #connection{} record for example. --- lib/ssh/src/ssh_connection.erl | 11 +++++++++++ lib/ssh/src/ssh_connection_handler.erl | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/lib/ssh/src/ssh_connection.erl b/lib/ssh/src/ssh_connection.erl index 067e5230c9..bf9e178cce 100644 --- a/lib/ssh/src/ssh_connection.erl +++ b/lib/ssh/src/ssh_connection.erl @@ -755,11 +755,22 @@ handle_msg(#ssh_msg_request_failure{}, {[{channel_request_reply, From, {failure, <<>>}}], Connection#connection{requests = Rest}}; +handle_msg(#ssh_msg_request_failure{}, + #connection{requests = [{_, From,_} | Rest]} = Connection, _) -> + {[{channel_request_reply, From, {failure, <<>>}}], + Connection#connection{requests = Rest}}; + handle_msg(#ssh_msg_request_success{data = Data}, #connection{requests = [{_, From} | Rest]} = Connection, _) -> {[{channel_request_reply, From, {success, Data}}], Connection#connection{requests = Rest}}; +handle_msg(#ssh_msg_request_success{data = Data}, + #connection{requests = [{_, From, Fun} | Rest]} = Connection0, _) -> + Connection = Fun({success,Data}, Connection0), + {[{channel_request_reply, From, {success, Data}}], + Connection#connection{requests = Rest}}; + handle_msg(#ssh_msg_disconnect{code = Code, description = Description}, Connection, _) -> diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl index 76479fffe3..3b99627f4d 100644 --- a/lib/ssh/src/ssh_connection_handler.erl +++ b/lib/ssh/src/ssh_connection_handler.erl @@ -1968,6 +1968,11 @@ add_request(true, ChannelId, From, #data{connection_state = #connection{requests = Requests0} = Connection} = State) -> Requests = [{ChannelId, From} | Requests0], + State#data{connection_state = Connection#connection{requests = Requests}}; +add_request(Fun, ChannelId, From, #data{connection_state = + #connection{requests = Requests0} = + Connection} = State) when is_function(Fun) -> + Requests = [{ChannelId, From, Fun} | Requests0], State#data{connection_state = Connection#connection{requests = Requests}}. new_channel_id(#data{connection_state = #connection{channel_id_seed = Id} = -- cgit v1.2.1