diff options
author | Hans Nilsson <hans@erlang.org> | 2019-08-16 13:12:10 +0200 |
---|---|---|
committer | Hans Nilsson <hans@erlang.org> | 2019-09-20 10:31:47 +0200 |
commit | a5f6b3441e26919a2be67929487c07a388ae96f6 (patch) | |
tree | f70e87259f79df5aafb997120343a2df7b939879 | |
parent | b4980254bc4596e7e1f80b44ce60dedd3c61f4d1 (diff) | |
download | erlang-a5f6b3441e26919a2be67929487c07a388ae96f6.tar.gz |
ssh: Add a simple per-connection term storage
-rw-r--r-- | lib/ssh/src/ssh_connection_handler.erl | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl index 3b99627f4d..991348b156 100644 --- a/lib/ssh/src/ssh_connection_handler.erl +++ b/lib/ssh/src/ssh_connection_handler.erl @@ -54,6 +54,8 @@ global_request/5, send/5, send_eof/2, + store/3, + retrieve/2, info/1, info/2, connection_info/2, channel_info/3, @@ -336,6 +338,15 @@ close(ConnectionHandler, ChannelId) -> ok end. + +%%-------------------------------------------------------------------- +store(ConnectionHandler, Key, Value) -> + cast(ConnectionHandler, {store,Key,Value}). + +retrieve(ConnectionHandler, Key) -> + call(ConnectionHandler, {retrieve,Key}). + + %%==================================================================== %% Test support %%==================================================================== @@ -1353,6 +1364,18 @@ handle_event({call,From}, {close, ChannelId}, StateName, D0) {keep_state_and_data, [{reply,From,ok}]} end; +handle_event(cast, {store,Key,Value}, _StateName, #data{connection_state=C0} = D) -> + C = #connection{options = ?PUT_INTERNAL_OPT({Key,Value}, C0#connection.options)}, + {keep_state, D#data{connection_state = C}}; + +handle_event({call,From}, {retrieve,Key}, _StateName, #data{connection_state=C0}) -> + try ?GET_INTERNAL_OPT(Key, C0#connection.options) of + Value -> + {keep_state_and_data, [{reply,From,{ok,Value}}]} + catch + error:{badkey,Key} -> + {keep_state_and_data, [{reply,From,undefined}]} + end; %%===== Reception of encrypted bytes, decryption and framing handle_event(info, {Proto, Sock, Info}, {hello,_}, #data{socket = Sock, |