25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-20 16:15:59 +01:00

Use ejabberd_cluster:send() in SM/C2S

This commit is contained in:
Evgeniy Khramtsov 2017-12-06 14:15:20 +03:00
parent ab2a90181c
commit e4a4839880
2 changed files with 22 additions and 16 deletions

View File

@ -146,10 +146,9 @@ send_error(#{lserver := LServer} = State, Pkt, Err) ->
{Pkt1, State1} -> xmpp_stream_in:send_error(State1, Pkt1, Err)
end.
-spec route(pid(), term()) -> ok.
-spec route(pid(), term()) -> boolean().
route(Pid, Term) ->
Pid ! Term,
ok.
ejabberd_cluster:send(Pid, Term).
-spec set_timeout(state(), timeout()) -> state().
set_timeout(State, Timeout) ->

View File

@ -113,21 +113,28 @@ get_node_by_id(ID) ->
Mod = get_mod(),
Mod:get_node_by_id(ID).
%% Note that false positive returns are possible, while false negatives are not.
%% In other words: positive return value (i.e. 'true') doesn't guarantee
%% successful delivery, while negative return value ('false') means
%% the delivery has definitely failed.
-spec send(dst(), term()) -> boolean().
send(Dst, Msg) ->
IsLocal = case Dst of
{_, Node} -> Node == node();
Pid when is_pid(Pid) -> node(Pid) == node();
Name when is_atom(Name) -> true;
_ -> false
end,
if IsLocal ->
erlang:send(Dst, Msg),
send({Name, Node}, Msg) when Node == node() ->
send(Name, Msg);
send(undefined, _Msg) ->
false;
send(Name, Msg) when is_atom(Name) ->
send(whereis(Name), Msg);
send(Pid, Msg) when is_pid(Pid) andalso node(Pid) == node() ->
case erlang:is_process_alive(Pid) of
true ->
erlang:send(Pid, Msg),
true;
true ->
Mod = get_mod(),
Mod:send(Dst, Msg)
end.
false ->
false
end;
send(Dst, Msg) ->
Mod = get_mod(),
Mod:send(Dst, Msg).
-spec wait_for_sync(timeout()) -> ok | {error, any()}.
wait_for_sync(Timeout) ->