From f61c933a7a534f22dac0ffd55c5443d033a35385 Mon Sep 17 00:00:00 2001 From: Evgeniy Khramtsov Date: Tue, 14 Feb 2017 15:39:57 +0300 Subject: [PATCH] Only use GEN_SERVER macro where appropriate --- src/ejabberd_receiver.erl | 17 ++++++++++------- src/ejabberd_router.erl | 7 +++++-- src/ejabberd_sm.erl | 11 +++++++---- src/gen_iq_handler.erl | 11 +++++++---- src/mod_http_upload.erl | 5 +---- src/mod_http_upload_quota.erl | 7 ++----- src/mod_offline.erl | 6 +----- 7 files changed, 33 insertions(+), 31 deletions(-) diff --git a/src/ejabberd_receiver.erl b/src/ejabberd_receiver.erl index 355fcbbd2..13c6d3b7f 100644 --- a/src/ejabberd_receiver.erl +++ b/src/ejabberd_receiver.erl @@ -27,7 +27,10 @@ -author('alexey@process-one.net'). --behaviour(gen_server). +-ifndef(GEN_SERVER). +-define(GEN_SERVER, gen_server). +-endif. +-behaviour(?GEN_SERVER). %% API -export([start_link/4, @@ -65,7 +68,7 @@ {ok, pid()}. start_link(Socket, SockMod, Shaper, MaxStanzaSize) -> - gen_server:start_link(?MODULE, + ?GEN_SERVER:start_link(?MODULE, [Socket, SockMod, Shaper, MaxStanzaSize], []). -spec start(inet:socket(), atom(), shaper:shaper()) -> undefined | pid(). @@ -77,14 +80,14 @@ start(Socket, SockMod, Shaper) -> non_neg_integer() | infinity) -> undefined | pid(). start(Socket, SockMod, Shaper, MaxStanzaSize) -> - {ok, Pid} = gen_server:start(ejabberd_receiver, + {ok, Pid} = ?GEN_SERVER:start(ejabberd_receiver, [Socket, SockMod, Shaper, MaxStanzaSize], []), Pid. -spec change_shaper(pid(), shaper:shaper()) -> ok. 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()}. @@ -109,7 +112,7 @@ become_controller(Pid, C2SPid) -> -spec close(pid()) -> ok. 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), {noreply, State, ?HIBERNATE_TIMEOUT}; handle_info(timeout, State) -> - proc_lib:hibernate(gen_server, enter_loop, + proc_lib:hibernate(?GEN_SERVER, enter_loop, [?MODULE, [], State]), {noreply, State, ?HIBERNATE_TIMEOUT}; handle_info(_Info, State) -> @@ -335,7 +338,7 @@ do_send(State, Data) -> (State#state.sock_mod):send(State#state.socket, Data). do_call(Pid, Msg) -> - case catch gen_server:call(Pid, Msg) of + case catch ?GEN_SERVER:call(Pid, Msg) of {'EXIT', Why} -> {error, Why}; Res -> Res end. diff --git a/src/ejabberd_router.erl b/src/ejabberd_router.erl index dca4a49f6..5ac0a58cc 100644 --- a/src/ejabberd_router.erl +++ b/src/ejabberd_router.erl @@ -29,7 +29,10 @@ -author('alexey@process-one.net'). --behaviour(gen_server). +-ifndef(GEN_SERVER). +-define(GEN_SERVER, gen_server). +-endif. +-behaviour(?GEN_SERVER). %% API -export([route/3, @@ -77,7 +80,7 @@ start() -> supervisor:start_child(ejabberd_sup, ChildSpec). start_link() -> - gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). + ?GEN_SERVER:start_link({local, ?MODULE}, ?MODULE, [], []). -spec route(jid(), jid(), xmlel() | stanza()) -> ok. route(#jid{} = From, #jid{} = To, #xmlel{} = El) -> diff --git a/src/ejabberd_sm.erl b/src/ejabberd_sm.erl index 12bfb4e10..0c01496ef 100644 --- a/src/ejabberd_sm.erl +++ b/src/ejabberd_sm.erl @@ -29,7 +29,10 @@ -author('alexey@process-one.net'). --behaviour(gen_server). +-ifndef(GEN_SERVER). +-define(GEN_SERVER, gen_server). +-endif. +-behaviour(?GEN_SERVER). %% API -export([start/0, @@ -110,7 +113,7 @@ start() -> supervisor:start_child(ejabberd_sup, ChildSpec). start_link() -> - gen_server:start_link({local, ?MODULE}, ?MODULE, [], []). + ?GEN_SERVER:start_link({local, ?MODULE}, ?MODULE, [], []). -spec route(jid(), term()) -> ok. %% @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. register_iq_handler(Host, XMLNS, Module, Fun, Opts) -> - gen_server:cast(?MODULE, + ?GEN_SERVER:cast(?MODULE, {register_iq_handler, Host, XMLNS, Module, Fun, Opts}). -spec unregister_iq_handler(binary(), binary()) -> ok. 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? c2s_handle_info(#{lang := Lang} = State, replaced) -> diff --git a/src/gen_iq_handler.erl b/src/gen_iq_handler.erl index fedd72c49..e9ba01470 100644 --- a/src/gen_iq_handler.erl +++ b/src/gen_iq_handler.erl @@ -27,7 +27,10 @@ -author('alexey@process-one.net'). --behaviour(gen_server). +-ifndef(GEN_SERVER). +-define(GEN_SERVER, gen_server). +-endif. +-behaviour(?GEN_SERVER). %% API -export([start_link/3, add_iq_handler/6, @@ -57,7 +60,7 @@ %% Description: Starts the server %%-------------------------------------------------------------------- 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. @@ -98,10 +101,10 @@ remove_iq_handler(Component, Host, NS) -> stop_iq_handler(_Module, _Function, Opts) -> case Opts of - {one_queue, Pid} -> gen_server:call(Pid, stop); + {one_queue, Pid} -> ?GEN_SERVER:call(Pid, stop); {queues, Pids} -> lists:foreach(fun (Pid) -> - catch gen_server:call(Pid, stop) + catch ?GEN_SERVER:call(Pid, stop) end, Pids); _ -> ok diff --git a/src/mod_http_upload.erl b/src/mod_http_upload.erl index c32c189e1..a00d1bccf 100644 --- a/src/mod_http_upload.erl +++ b/src/mod_http_upload.erl @@ -28,9 +28,6 @@ -protocol({xep, 363, '0.1'}). --ifndef(GEN_SERVER). --define(GEN_SERVER, gen_server). --endif. -define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds. -define(SLOT_TIMEOUT, 18000000). % 5 hours. -define(FORMAT(Error), file:format_error(Error)). @@ -62,7 +59,7 @@ {<<".xz">>, <<"application/x-xz">>}, {<<".zip">>, <<"application/zip">>}]). --behaviour(?GEN_SERVER). +-behaviour(gen_server). -behaviour(gen_mod). %% gen_mod/supervisor callbacks. diff --git a/src/mod_http_upload_quota.erl b/src/mod_http_upload_quota.erl index ee0ea9d1d..69b791478 100644 --- a/src/mod_http_upload_quota.erl +++ b/src/mod_http_upload_quota.erl @@ -26,14 +26,11 @@ -module(mod_http_upload_quota). -author('holger@zedat.fu-berlin.de'). --ifndef(GEN_SERVER). --define(GEN_SERVER, gen_server). --endif. -define(TIMEOUT, timer:hours(24)). -define(INITIAL_TIMEOUT, timer:minutes(10)). -define(FORMAT(Error), file:format_error(Error)). --behaviour(?GEN_SERVER). +-behaviour(gen_server). -behaviour(gen_mod). %% 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, _Lang) -> 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; handle_slot_request(Acc, _JID, _Path, _Size, _Lang) -> Acc. diff --git a/src/mod_offline.erl b/src/mod_offline.erl index 9ed9ab91f..59efa7214 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -33,11 +33,7 @@ -protocol({xep, 160, '1.0'}). -protocol({xep, 334, '0.2'}). --ifndef(GEN_SERVER). --define(GEN_SERVER, gen_server). --endif. --behaviour(?GEN_SERVER). - +-behaviour(gen_server). -behaviour(gen_mod). -export([start/2,