diff --git a/lib/ssh/src/ssh_acceptor.erl b/lib/ssh/src/ssh_acceptor.erl index d2b1a9f7204..e49d922c418 100644 --- a/lib/ssh/src/ssh_acceptor.erl +++ b/lib/ssh/src/ssh_acceptor.erl @@ -77,9 +77,8 @@ acceptor_loop(Port, Address, Opts, ListenSocket, AcceptTimeout, SystemSup) -> PeerName = inet:peername(Socket), MaxSessions = ?GET_OPT(max_sessions, Opts), NumSessions = number_of_connections(SystemSup), - ParallelLogin = ?GET_OPT(parallel_login, Opts), case handle_connection(Address, Port, PeerName, Opts, Socket, - MaxSessions, NumSessions, ParallelLogin) of + MaxSessions, NumSessions) of {error,Error} -> catch close(Socket, Opts), handle_error(Error, Address, Port, PeerName); @@ -97,33 +96,15 @@ acceptor_loop(Port, Address, Opts, ListenSocket, AcceptTimeout, SystemSup) -> %%%---------------------------------------------------------------- handle_connection(_Address, _Port, _Peer, _Options, _Socket, - MaxSessions, NumSessions, _ParallelLogin) + MaxSessions, NumSessions) when NumSessions >= MaxSessions-> {error,{max_sessions,MaxSessions}}; handle_connection(_Address, _Port, {error,Error}, _Options, _Socket, - _MaxSessions, _NumSessions, _ParallelLogin) -> + _MaxSessions, _NumSessions) -> {error,Error}; handle_connection(Address, Port, _Peer, Options, Socket, - _MaxSessions, _NumSessions, ParallelLogin) - when ParallelLogin == false -> - handle_connection(Address, Port, Options, Socket); -handle_connection(Address, Port, _Peer, Options, Socket, - _MaxSessions, _NumSessions, ParallelLogin) - when ParallelLogin == true -> - Ref = make_ref(), - Pid = spawn_link( - fun() -> - process_flag(trap_exit, true), - receive - {start,Ref} -> - handle_connection(Address, Port, Options, Socket) - after 10000 -> - {error, timeout2} - end - end), - catch gen_tcp:controlling_process(Socket, Pid), - Pid ! {start,Ref}, - ok. + _MaxSessions, _NumSessions) -> + handle_connection(Address, Port, Options, Socket). handle_connection(Address, Port, Options, Socket) -> AddressR = #address{address = Address, port = Port, diff --git a/lib/ssh/src/ssh_connection_handler.erl b/lib/ssh/src/ssh_connection_handler.erl index 8746c2bbd4e..43a11ea7320 100644 --- a/lib/ssh/src/ssh_connection_handler.erl +++ b/lib/ssh/src/ssh_connection_handler.erl @@ -136,7 +136,8 @@ takeover(ConnPid, Role, Socket, Options) -> Options, ?GET_OPT(negotiation_timeout, Options) ), - handshake(ConnPid, Role, Ref, NegTimeout); + ParallelLogin = ?GET_OPT(parallel_login, Options, disabled), + handshake(ConnPid, Role, Ref, NegTimeout, ParallelLogin); {error, Reason} -> {error, Reason} end. @@ -491,7 +492,11 @@ init_ssh_record(Role, Socket, PeerAddr, Opts) -> } end. -handshake(ConnPid, server, Ref, Timeout) -> +handshake(ConnPid, server, Ref, _Timeout, true) -> + %% FIXME how ssh_connected messages should be cleaned, flushed? + erlang:demonitor(Ref, [flush]), + {ok, ConnPid}; +handshake(ConnPid, server, Ref, Timeout, _) -> receive {ConnPid, ssh_connected} -> erlang:demonitor(Ref, [flush]), @@ -511,7 +516,7 @@ handshake(ConnPid, server, Ref, Timeout) -> ssh_connection_handler:stop(ConnPid), {error, timeout} end; -handshake(ConnPid, client, Ref, Timeout) -> +handshake(ConnPid, client, Ref, Timeout, _) -> receive {ConnPid, ssh_connected} -> erlang:demonitor(Ref, [flush]),