diff options
author | Siri Hansen <[email protected]> | 2016-06-09 14:52:35 +0200 |
---|---|---|
committer | Siri Hansen <[email protected]> | 2016-06-09 14:52:35 +0200 |
commit | 68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8 (patch) | |
tree | b34c9396a56b03968beaf3cdbab56e4a8a4847d2 /lib/common_test/test/telnet_server.erl | |
parent | 75e5cdabbcaaa12f043225ca8d361055a9d47b24 (diff) | |
parent | baf5751951f3463d599ccb958272ab6a6fec39b4 (diff) | |
download | otp-68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8.tar.gz otp-68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8.tar.bz2 otp-68ff9f3e4b5387cf38af7aeb1a8b7abbdaa867d8.zip |
Merge branch 'siri/cuddle-master'
* siri/cuddle-master:
[ct test] Wait for event receiver to be unregistered
[ct test] Flush messages from old client after close in telnet server
[ct test] Use monitor instead of ct:sleep
[ct test] Check that crypto is loaded, or skip netconf tests
[ct test] Reduce amount of data in netconfc1_SUITE:get_a_lot
Diffstat (limited to 'lib/common_test/test/telnet_server.erl')
-rw-r--r-- | lib/common_test/test/telnet_server.erl | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/lib/common_test/test/telnet_server.erl b/lib/common_test/test/telnet_server.erl index 2c33cb268a..65300b0bdf 100644 --- a/lib/common_test/test/telnet_server.erl +++ b/lib/common_test/test/telnet_server.erl @@ -117,38 +117,64 @@ init_client(#state{client=Sock}=State) -> dbg("Server sending: ~p~n",["login: "]), R = case gen_tcp:send(Sock,"login: ") of ok -> - loop(State, 1); + loop(State); Error -> Error end, _ = gen_tcp:close(Sock), R. -loop(State, N) -> +loop(State=#state{client=Sock}) -> receive - {tcp,_,Data} -> + {tcp,Sock,Data} -> try handle_data(Data,State) of {ok,State1} -> - loop(State1, N); + loop(State1); closed -> + _ = flush(State), closed catch throw:Error -> + _ = flush(State), Error end; - {tcp_closed, _} -> + {tcp_closed,Sock} -> closed; - {tcp_error,_,Error} -> + {tcp_error,Sock,Error} -> {error,tcp,Error}; disconnect -> - Sock = State#state.client, dbg("Server closing connection on socket ~p~n", [Sock]), + timer:sleep(1000), ok = gen_tcp:close(Sock), - closed; + _ = flush(State); stop -> + _ = flush(State), stopped end. +flush(State=#state{client=Sock}) -> + receive + {tcp,Sock,Data} = M-> + dbg("Message flushed after close or error: ~p~n", [M]), + try handle_data(Data,State) of + {ok,State1} -> + flush(State1); + closed -> + flush(State) + catch + throw:Error -> + Error + end; + {tcp_closed,Sock} = M -> + dbg("Message flushed after close or error: ~p~n", [M]), + ok; + {tcp_error,Sock,Error} = M -> + dbg("Message flushed after close or error: ~p~n", [M]), + {error,tcp,Error} + after 100 -> + ok + end. + handle_data(Cmd,#state{break=true}=State) -> dbg("Server got data when in break mode: ~p~n",[Cmd]), handle_break_cmd(Cmd,State); |