aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ssh/test/ssh_echo_server.erl
diff options
context:
space:
mode:
authorHans Nilsson <[email protected]>2016-05-25 14:51:55 +0200
committerHans Nilsson <[email protected]>2016-06-07 15:41:28 +0200
commitab95786ce0dc29f330de6e0c3565a30948ba799b (patch)
tree3609ce8b6f3840372d69865e84640fb08450fc9c /lib/ssh/test/ssh_echo_server.erl
parenta39395d4f99aff99ac57ab40a3191fa13a7371fd (diff)
downloadotp-ab95786ce0dc29f330de6e0c3565a30948ba799b.tar.gz
otp-ab95786ce0dc29f330de6e0c3565a30948ba799b.tar.bz2
otp-ab95786ce0dc29f330de6e0c3565a30948ba799b.zip
ssh: logging in test helper ssh_echo_server
Diffstat (limited to 'lib/ssh/test/ssh_echo_server.erl')
-rw-r--r--lib/ssh/test/ssh_echo_server.erl35
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/ssh/test/ssh_echo_server.erl b/lib/ssh/test/ssh_echo_server.erl
index ed9bbe1b67..3702630cb4 100644
--- a/lib/ssh/test/ssh_echo_server.erl
+++ b/lib/ssh/test/ssh_echo_server.erl
@@ -26,15 +26,29 @@
-record(state, {
n,
id,
- cm
+ cm,
+ dbg = false
}).
-export([init/1, handle_msg/2, handle_ssh_msg/2, terminate/2]).
+-define(DBG(State,Fmt,Args),
+ case State#state.dbg of
+ true -> ct:log("~p:~p ~p "++Fmt, [?MODULE,?LINE,self()|Args]);
+ false -> ok
+ end).
+
+
init([N]) ->
- ct:pal("Echo server: ~p",[self()]),
- {ok, #state{n = N}}.
+ {ok, #state{n = N}};
+init([N,Opts]) ->
+ State = #state{n = N,
+ dbg = proplists:get_value(dbg,Opts,false)
+ },
+ ?DBG(State, "init([~p])",[N]),
+ {ok, State}.
handle_msg({ssh_channel_up, ChannelId, ConnectionManager}, State) ->
+ ?DBG(State, "ssh_channel_up Cid=~p ConnMngr=~p",[ChannelId,ConnectionManager]),
{ok, State#state{id = ChannelId,
cm = ConnectionManager}}.
@@ -42,32 +56,39 @@ handle_ssh_msg({ssh_cm, CM, {data, ChannelId, 0, Data}}, #state{n = N} = State)
M = N - size(Data),
case M > 0 of
true ->
+ ?DBG(State, "ssh_cm data Cid=~p size(Data)=~p M=~p",[ChannelId,size(Data),M]),
ssh_connection:send(CM, ChannelId, Data),
{ok, State#state{n = M}};
false ->
<<SendData:N/binary, _/binary>> = Data,
+ ?DBG(State, "ssh_cm data Cid=~p size(Data)=~p M=~p size(SendData)=~p",[ChannelId,size(Data),M,size(SendData)]),
ssh_connection:send(CM, ChannelId, SendData),
ssh_connection:send_eof(CM, ChannelId),
{stop, ChannelId, State}
end;
handle_ssh_msg({ssh_cm, _ConnectionManager,
{data, _ChannelId, 1, Data}}, State) ->
+ ?DBG(State, "stderr: ~p",[Data]),
error_logger:format(standard_error, " ~p~n", [binary_to_list(Data)]),
{ok, State};
handle_ssh_msg({ssh_cm, _ConnectionManager, {eof, _ChannelId}}, State) ->
+ ?DBG(State, "{eof ~p}",[_ChannelId]),
{ok, State};
-handle_ssh_msg({ssh_cm, _, {signal, _, _}}, State) ->
+handle_ssh_msg({ssh_cm, _, _Sig={signal, _, _}}, State) ->
%% Ignore signals according to RFC 4254 section 6.9.
+ ?DBG(State, "~p",[_Sig]),
{ok, State};
-handle_ssh_msg({ssh_cm, _, {exit_signal, ChannelId, _, _Error, _}},
- State) ->
+handle_ssh_msg({ssh_cm, _, _Sig={exit_signal, ChannelId, _, _Error, _}}, State) ->
+ ?DBG(State, "~p",[_Sig]),
{stop, ChannelId, State};
-handle_ssh_msg({ssh_cm, _, {exit_status, ChannelId, _Status}}, State) ->
+handle_ssh_msg({ssh_cm, _, _Sig={exit_status, ChannelId, _Status}}, State) ->
+ ?DBG(State, "~p",[_Sig]),
{stop, ChannelId, State}.
terminate(_Reason, _State) ->
+ ?DBG(_State, "terminate ~p",[_Reason]),
ok.