]> granicus.if.org Git - ejabberd/commitdiff
Forward old messages to newly spawned extauth process (thanks to Mika Seppänen)(EJAB...
authorBadlop <badlop@process-one.net>
Mon, 21 Feb 2011 15:13:41 +0000 (16:13 +0100)
committerBadlop <badlop@process-one.net>
Mon, 21 Feb 2011 15:19:45 +0000 (16:19 +0100)
src/extauth.erl

index 5b01fd9314d358e9c8aee897e4b462be6c0d6067..e0de7d82d7715e813ed15ac0b3074ea9a79226f5 100644 (file)
@@ -126,7 +126,8 @@ loop(Port, Timeout, ProcessName, ExtPrg) ->
                     ?ERROR_MSG("extauth call '~p' didn't receive response", [Msg]),
                    Caller ! {eauth, false},
                    unregister(ProcessName),
-                   spawn(?MODULE, init, [ProcessName, ExtPrg]),
+                   Pid = spawn(?MODULE, init, [ProcessName, ExtPrg]),
+                   flush_buffer_and_forward_messages(Pid),
                    exit(port_terminated)
            end;
        stop ->
@@ -140,6 +141,15 @@ loop(Port, Timeout, ProcessName, ExtPrg) ->
            exit(port_terminated)
     end.
 
+flush_buffer_and_forward_messages(Pid) ->
+    receive
+       Message ->
+           Pid ! Message,
+           flush_buffer_and_forward_messages(Pid)
+    after 0 ->
+           true
+    end.
+
 join(List, Sep) ->
     lists:foldl(fun(A, "") -> A;
                   (A, Acc) -> Acc ++ Sep ++ A