diff options
author | Hans Nilsson <hans@erlang.org> | 2019-09-17 09:46:04 +0200 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2019-09-20 10:31:47 +0200 |
commit | b4980254bc4596e7e1f80b44ce60dedd3c61f4d1 (patch) | |
tree | 249224610411e09e8cc46a4e6d63c292d66bb19e | |
parent | a9050738f80a588e75742842fb64fa4bdc4ab448 (diff) | |
download | erlang-b4980254bc4596e7e1f80b44ce60dedd3c61f4d1.tar.gz |
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.
-rw-r--r-- | lib/ssh/src/ssh_connection.erl | 11 | ||||
-rw-r--r-- | lib/ssh/src/ssh_connection_handler.erl | 5 |
2 files changed, 16 insertions, 0 deletions
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} = |