mirror of
https://github.com/processone/ejabberd
synced 2025-10-03 09:49:18 +02:00
Only use GEN_SERVER macro where appropriate
This commit is contained in:
parent
28f66ddd7c
commit
f61c933a7a
7 changed files with 33 additions and 31 deletions
|
@ -27,7 +27,10 @@
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-ifndef(GEN_SERVER).
|
||||||
|
-define(GEN_SERVER, gen_server).
|
||||||
|
-endif.
|
||||||
|
-behaviour(?GEN_SERVER).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/4,
|
-export([start_link/4,
|
||||||
|
@ -65,7 +68,7 @@
|
||||||
{ok, pid()}.
|
{ok, pid()}.
|
||||||
|
|
||||||
start_link(Socket, SockMod, Shaper, MaxStanzaSize) ->
|
start_link(Socket, SockMod, Shaper, MaxStanzaSize) ->
|
||||||
gen_server:start_link(?MODULE,
|
?GEN_SERVER:start_link(?MODULE,
|
||||||
[Socket, SockMod, Shaper, MaxStanzaSize], []).
|
[Socket, SockMod, Shaper, MaxStanzaSize], []).
|
||||||
|
|
||||||
-spec start(inet:socket(), atom(), shaper:shaper()) -> undefined | pid().
|
-spec start(inet:socket(), atom(), shaper:shaper()) -> undefined | pid().
|
||||||
|
@ -77,14 +80,14 @@ start(Socket, SockMod, Shaper) ->
|
||||||
non_neg_integer() | infinity) -> undefined | pid().
|
non_neg_integer() | infinity) -> undefined | pid().
|
||||||
|
|
||||||
start(Socket, SockMod, Shaper, MaxStanzaSize) ->
|
start(Socket, SockMod, Shaper, MaxStanzaSize) ->
|
||||||
{ok, Pid} = gen_server:start(ejabberd_receiver,
|
{ok, Pid} = ?GEN_SERVER:start(ejabberd_receiver,
|
||||||
[Socket, SockMod, Shaper, MaxStanzaSize], []),
|
[Socket, SockMod, Shaper, MaxStanzaSize], []),
|
||||||
Pid.
|
Pid.
|
||||||
|
|
||||||
-spec change_shaper(pid(), shaper:shaper()) -> ok.
|
-spec change_shaper(pid(), shaper:shaper()) -> ok.
|
||||||
|
|
||||||
change_shaper(Pid, Shaper) ->
|
change_shaper(Pid, Shaper) ->
|
||||||
gen_server:cast(Pid, {change_shaper, Shaper}).
|
?GEN_SERVER:cast(Pid, {change_shaper, Shaper}).
|
||||||
|
|
||||||
-spec reset_stream(pid()) -> ok | {error, any()}.
|
-spec reset_stream(pid()) -> ok | {error, any()}.
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ become_controller(Pid, C2SPid) ->
|
||||||
-spec close(pid()) -> ok.
|
-spec close(pid()) -> ok.
|
||||||
|
|
||||||
close(Pid) ->
|
close(Pid) ->
|
||||||
gen_server:cast(Pid, close).
|
?GEN_SERVER:cast(Pid, close).
|
||||||
|
|
||||||
|
|
||||||
%%====================================================================
|
%%====================================================================
|
||||||
|
@ -220,7 +223,7 @@ handle_info({timeout, _Ref, activate}, State) ->
|
||||||
activate_socket(State),
|
activate_socket(State),
|
||||||
{noreply, State, ?HIBERNATE_TIMEOUT};
|
{noreply, State, ?HIBERNATE_TIMEOUT};
|
||||||
handle_info(timeout, State) ->
|
handle_info(timeout, State) ->
|
||||||
proc_lib:hibernate(gen_server, enter_loop,
|
proc_lib:hibernate(?GEN_SERVER, enter_loop,
|
||||||
[?MODULE, [], State]),
|
[?MODULE, [], State]),
|
||||||
{noreply, State, ?HIBERNATE_TIMEOUT};
|
{noreply, State, ?HIBERNATE_TIMEOUT};
|
||||||
handle_info(_Info, State) ->
|
handle_info(_Info, State) ->
|
||||||
|
@ -335,7 +338,7 @@ do_send(State, Data) ->
|
||||||
(State#state.sock_mod):send(State#state.socket, Data).
|
(State#state.sock_mod):send(State#state.socket, Data).
|
||||||
|
|
||||||
do_call(Pid, Msg) ->
|
do_call(Pid, Msg) ->
|
||||||
case catch gen_server:call(Pid, Msg) of
|
case catch ?GEN_SERVER:call(Pid, Msg) of
|
||||||
{'EXIT', Why} -> {error, Why};
|
{'EXIT', Why} -> {error, Why};
|
||||||
Res -> Res
|
Res -> Res
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -29,7 +29,10 @@
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-ifndef(GEN_SERVER).
|
||||||
|
-define(GEN_SERVER, gen_server).
|
||||||
|
-endif.
|
||||||
|
-behaviour(?GEN_SERVER).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([route/3,
|
-export([route/3,
|
||||||
|
@ -77,7 +80,7 @@ start() ->
|
||||||
supervisor:start_child(ejabberd_sup, ChildSpec).
|
supervisor:start_child(ejabberd_sup, ChildSpec).
|
||||||
|
|
||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
?GEN_SERVER:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
|
-spec route(jid(), jid(), xmlel() | stanza()) -> ok.
|
||||||
route(#jid{} = From, #jid{} = To, #xmlel{} = El) ->
|
route(#jid{} = From, #jid{} = To, #xmlel{} = El) ->
|
||||||
|
|
|
@ -29,7 +29,10 @@
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-ifndef(GEN_SERVER).
|
||||||
|
-define(GEN_SERVER, gen_server).
|
||||||
|
-endif.
|
||||||
|
-behaviour(?GEN_SERVER).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start/0,
|
-export([start/0,
|
||||||
|
@ -110,7 +113,7 @@ start() ->
|
||||||
supervisor:start_child(ejabberd_sup, ChildSpec).
|
supervisor:start_child(ejabberd_sup, ChildSpec).
|
||||||
|
|
||||||
start_link() ->
|
start_link() ->
|
||||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
|
?GEN_SERVER:start_link({local, ?MODULE}, ?MODULE, [], []).
|
||||||
|
|
||||||
-spec route(jid(), term()) -> ok.
|
-spec route(jid(), term()) -> ok.
|
||||||
%% @doc route arbitrary term to c2s process(es)
|
%% @doc route arbitrary term to c2s process(es)
|
||||||
|
@ -358,13 +361,13 @@ get_vh_session_number(Server) ->
|
||||||
-spec register_iq_handler(binary(), binary(), atom(), atom(), list()) -> ok.
|
-spec register_iq_handler(binary(), binary(), atom(), atom(), list()) -> ok.
|
||||||
|
|
||||||
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
|
register_iq_handler(Host, XMLNS, Module, Fun, Opts) ->
|
||||||
gen_server:cast(?MODULE,
|
?GEN_SERVER:cast(?MODULE,
|
||||||
{register_iq_handler, Host, XMLNS, Module, Fun, Opts}).
|
{register_iq_handler, Host, XMLNS, Module, Fun, Opts}).
|
||||||
|
|
||||||
-spec unregister_iq_handler(binary(), binary()) -> ok.
|
-spec unregister_iq_handler(binary(), binary()) -> ok.
|
||||||
|
|
||||||
unregister_iq_handler(Host, XMLNS) ->
|
unregister_iq_handler(Host, XMLNS) ->
|
||||||
gen_server:cast(?MODULE, {unregister_iq_handler, Host, XMLNS}).
|
?GEN_SERVER:cast(?MODULE, {unregister_iq_handler, Host, XMLNS}).
|
||||||
|
|
||||||
%% Why the hell do we have so many similar kicks?
|
%% Why the hell do we have so many similar kicks?
|
||||||
c2s_handle_info(#{lang := Lang} = State, replaced) ->
|
c2s_handle_info(#{lang := Lang} = State, replaced) ->
|
||||||
|
|
|
@ -27,7 +27,10 @@
|
||||||
|
|
||||||
-author('alexey@process-one.net').
|
-author('alexey@process-one.net').
|
||||||
|
|
||||||
-behaviour(gen_server).
|
-ifndef(GEN_SERVER).
|
||||||
|
-define(GEN_SERVER, gen_server).
|
||||||
|
-endif.
|
||||||
|
-behaviour(?GEN_SERVER).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/3, add_iq_handler/6,
|
-export([start_link/3, add_iq_handler/6,
|
||||||
|
@ -57,7 +60,7 @@
|
||||||
%% Description: Starts the server
|
%% Description: Starts the server
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
start_link(Host, Module, Function) ->
|
start_link(Host, Module, Function) ->
|
||||||
gen_server:start_link(?MODULE, [Host, Module, Function],
|
?GEN_SERVER:start_link(?MODULE, [Host, Module, Function],
|
||||||
[]).
|
[]).
|
||||||
|
|
||||||
-spec add_iq_handler(module(), binary(), binary(), module(), atom(), type()) -> ok.
|
-spec add_iq_handler(module(), binary(), binary(), module(), atom(), type()) -> ok.
|
||||||
|
@ -98,10 +101,10 @@ remove_iq_handler(Component, Host, NS) ->
|
||||||
|
|
||||||
stop_iq_handler(_Module, _Function, Opts) ->
|
stop_iq_handler(_Module, _Function, Opts) ->
|
||||||
case Opts of
|
case Opts of
|
||||||
{one_queue, Pid} -> gen_server:call(Pid, stop);
|
{one_queue, Pid} -> ?GEN_SERVER:call(Pid, stop);
|
||||||
{queues, Pids} ->
|
{queues, Pids} ->
|
||||||
lists:foreach(fun (Pid) ->
|
lists:foreach(fun (Pid) ->
|
||||||
catch gen_server:call(Pid, stop)
|
catch ?GEN_SERVER:call(Pid, stop)
|
||||||
end,
|
end,
|
||||||
Pids);
|
Pids);
|
||||||
_ -> ok
|
_ -> ok
|
||||||
|
|
|
@ -28,9 +28,6 @@
|
||||||
|
|
||||||
-protocol({xep, 363, '0.1'}).
|
-protocol({xep, 363, '0.1'}).
|
||||||
|
|
||||||
-ifndef(GEN_SERVER).
|
|
||||||
-define(GEN_SERVER, gen_server).
|
|
||||||
-endif.
|
|
||||||
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
||||||
-define(SLOT_TIMEOUT, 18000000). % 5 hours.
|
-define(SLOT_TIMEOUT, 18000000). % 5 hours.
|
||||||
-define(FORMAT(Error), file:format_error(Error)).
|
-define(FORMAT(Error), file:format_error(Error)).
|
||||||
|
@ -62,7 +59,7 @@
|
||||||
{<<".xz">>, <<"application/x-xz">>},
|
{<<".xz">>, <<"application/x-xz">>},
|
||||||
{<<".zip">>, <<"application/zip">>}]).
|
{<<".zip">>, <<"application/zip">>}]).
|
||||||
|
|
||||||
-behaviour(?GEN_SERVER).
|
-behaviour(gen_server).
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
%% gen_mod/supervisor callbacks.
|
%% gen_mod/supervisor callbacks.
|
||||||
|
|
|
@ -26,14 +26,11 @@
|
||||||
-module(mod_http_upload_quota).
|
-module(mod_http_upload_quota).
|
||||||
-author('holger@zedat.fu-berlin.de').
|
-author('holger@zedat.fu-berlin.de').
|
||||||
|
|
||||||
-ifndef(GEN_SERVER).
|
|
||||||
-define(GEN_SERVER, gen_server).
|
|
||||||
-endif.
|
|
||||||
-define(TIMEOUT, timer:hours(24)).
|
-define(TIMEOUT, timer:hours(24)).
|
||||||
-define(INITIAL_TIMEOUT, timer:minutes(10)).
|
-define(INITIAL_TIMEOUT, timer:minutes(10)).
|
||||||
-define(FORMAT(Error), file:format_error(Error)).
|
-define(FORMAT(Error), file:format_error(Error)).
|
||||||
|
|
||||||
-behaviour(?GEN_SERVER).
|
-behaviour(gen_server).
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
%% gen_mod/supervisor callbacks.
|
%% gen_mod/supervisor callbacks.
|
||||||
|
@ -253,7 +250,7 @@ code_change(_OldVsn, #state{server_host = ServerHost} = State, _Extra) ->
|
||||||
handle_slot_request(allow, #jid{lserver = ServerHost} = JID, Path, Size,
|
handle_slot_request(allow, #jid{lserver = ServerHost} = JID, Path, Size,
|
||||||
_Lang) ->
|
_Lang) ->
|
||||||
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
|
Proc = mod_http_upload:get_proc_name(ServerHost, ?MODULE),
|
||||||
?GEN_SERVER:cast(Proc, {handle_slot_request, JID, Path, Size}),
|
gen_server:cast(Proc, {handle_slot_request, JID, Path, Size}),
|
||||||
allow;
|
allow;
|
||||||
handle_slot_request(Acc, _JID, _Path, _Size, _Lang) -> Acc.
|
handle_slot_request(Acc, _JID, _Path, _Size, _Lang) -> Acc.
|
||||||
|
|
||||||
|
|
|
@ -33,11 +33,7 @@
|
||||||
-protocol({xep, 160, '1.0'}).
|
-protocol({xep, 160, '1.0'}).
|
||||||
-protocol({xep, 334, '0.2'}).
|
-protocol({xep, 334, '0.2'}).
|
||||||
|
|
||||||
-ifndef(GEN_SERVER).
|
-behaviour(gen_server).
|
||||||
-define(GEN_SERVER, gen_server).
|
|
||||||
-endif.
|
|
||||||
-behaviour(?GEN_SERVER).
|
|
||||||
|
|
||||||
-behaviour(gen_mod).
|
-behaviour(gen_mod).
|
||||||
|
|
||||||
-export([start/2,
|
-export([start/2,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue