mirror of
https://github.com/processone/ejabberd.git
synced 2024-06-10 21:47:01 +02:00
Correctly handle mod_client_state (re)load
This commit is contained in:
parent
bd06bc00e2
commit
f3af117108
|
@ -187,7 +187,7 @@ unregister_hooks(Host) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
-spec c2s_stream_started(c2s_state(), stream_start()) -> c2s_state().
|
-spec c2s_stream_started(c2s_state(), stream_start()) -> c2s_state().
|
||||||
c2s_stream_started(State, _) ->
|
c2s_stream_started(State, _) ->
|
||||||
State#{csi_state => active, csi_queue => queue_new()}.
|
init_csi_state(State).
|
||||||
|
|
||||||
-spec c2s_authenticated_packet(c2s_state(), xmpp_element()) -> c2s_state().
|
-spec c2s_authenticated_packet(c2s_state(), xmpp_element()) -> c2s_state().
|
||||||
c2s_authenticated_packet(C2SState, #csi{type = active}) ->
|
c2s_authenticated_packet(C2SState, #csi{type = active}) ->
|
||||||
|
@ -284,6 +284,10 @@ add_stream_feature(Features, Host) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Internal functions.
|
%% Internal functions.
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
-spec init_csi_state(c2s_state()) -> c2s_state().
|
||||||
|
init_csi_state(C2SState) ->
|
||||||
|
C2SState#{csi_state => active, csi_queue => queue_new()}.
|
||||||
|
|
||||||
-spec enqueue_stanza(csi_type(), stanza(), c2s_state()) -> filter_acc().
|
-spec enqueue_stanza(csi_type(), stanza(), c2s_state()) -> filter_acc().
|
||||||
enqueue_stanza(Type, Stanza, #{csi_state := inactive,
|
enqueue_stanza(Type, Stanza, #{csi_state := inactive,
|
||||||
csi_queue := Q} = C2SState) ->
|
csi_queue := Q} = C2SState) ->
|
||||||
|
@ -302,12 +306,18 @@ enqueue_stanza(_Type, Stanza, State) ->
|
||||||
|
|
||||||
-spec dequeue_sender(jid(), c2s_state()) -> c2s_state().
|
-spec dequeue_sender(jid(), c2s_state()) -> c2s_state().
|
||||||
dequeue_sender(#jid{luser = U, lserver = S} = Sender,
|
dequeue_sender(#jid{luser = U, lserver = S} = Sender,
|
||||||
#{csi_queue := Q, jid := JID} = C2SState) ->
|
#{jid := JID} = C2SState) ->
|
||||||
?DEBUG("Flushing packets of ~s@~s from CSI queue of ~s",
|
case maps:get(csi_queue, C2SState, undefined) of
|
||||||
[U, S, jid:encode(JID)]),
|
undefined ->
|
||||||
{Elems, Q1} = queue_take(Sender, Q),
|
%% This may happen when the module is (re)loaded in runtime
|
||||||
C2SState1 = flush_stanzas(C2SState, Elems),
|
init_csi_state(C2SState);
|
||||||
C2SState1#{csi_queue => Q1}.
|
Q ->
|
||||||
|
?DEBUG("Flushing packets of ~s@~s from CSI queue of ~s",
|
||||||
|
[U, S, jid:encode(JID)]),
|
||||||
|
{Elems, Q1} = queue_take(Sender, Q),
|
||||||
|
C2SState1 = flush_stanzas(C2SState, Elems),
|
||||||
|
C2SState1#{csi_queue => Q1}
|
||||||
|
end.
|
||||||
|
|
||||||
-spec flush_queue(c2s_state()) -> c2s_state().
|
-spec flush_queue(c2s_state()) -> c2s_state().
|
||||||
flush_queue(#{csi_queue := Q, jid := JID} = C2SState) ->
|
flush_queue(#{csi_queue := Q, jid := JID} = C2SState) ->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user