25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Fix delayed response of a timeout call was reused for next login (EJAB-1385)

This commit is contained in:
Badlop 2011-01-19 19:06:46 +01:00
parent f4c74c147b
commit 6e3a9ac4fd

View File

@ -54,7 +54,7 @@ init(ProcessName, ExtPrg) ->
register(ProcessName, self()), register(ProcessName, self()),
process_flag(trap_exit,true), process_flag(trap_exit,true),
Port = open_port({spawn, ExtPrg}, [{packet,2}]), Port = open_port({spawn, ExtPrg}, [{packet,2}]),
loop(Port, ?INIT_TIMEOUT). loop(Port, ?INIT_TIMEOUT, ProcessName, ExtPrg).
stop(Host) -> stop(Host) ->
lists:foreach( lists:foreach(
@ -108,23 +108,27 @@ get_instances(Server) ->
_ -> 1 _ -> 1
end. end.
loop(Port, Timeout) -> loop(Port, Timeout, ProcessName, ExtPrg) ->
receive receive
{call, Caller, Msg} -> {call, Caller, Msg} ->
Port ! {self(), {command, encode(Msg)}}, port_command(Port, encode(Msg)),
receive receive
{Port, {data, Data}} -> {Port, {data, Data}} ->
?DEBUG("extauth call '~p' received data response:~n~p", [Msg, Data]), ?DEBUG("extauth call '~p' received data response:~n~p", [Msg, Data]),
Caller ! {eauth, decode(Data)}; Caller ! {eauth, decode(Data)},
loop(Port, ?CALL_TIMEOUT, ProcessName, ExtPrg);
{Port, Other} -> {Port, Other} ->
?ERROR_MSG("extauth call '~p' received strange response:~n~p", [Msg, Other]), ?ERROR_MSG("extauth call '~p' received strange response:~n~p", [Msg, Other]),
Caller ! {eauth, false} Caller ! {eauth, false},
loop(Port, ?CALL_TIMEOUT, ProcessName, ExtPrg)
after after
Timeout -> Timeout ->
?ERROR_MSG("extauth call '~p' didn't receive response", [Msg]), ?ERROR_MSG("extauth call '~p' didn't receive response", [Msg]),
Caller ! {eauth, false} Caller ! {eauth, false},
end, unregister(ProcessName),
loop(Port, ?CALL_TIMEOUT); spawn(?MODULE, init, [ProcessName, ExtPrg]),
exit(port_terminated)
end;
stop -> stop ->
Port ! {self(), close}, Port ! {self(), close},
receive receive