mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
mod_http_upload: Avoid timers from timer module
Use erlang:start_timer/3 instead of timer:send_after/2, as the former is more efficient.
This commit is contained in:
parent
4e9930597d
commit
2539be1a04
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
-define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
||||||
-define(CALL_TIMEOUT, 60000). % 1 minute.
|
-define(CALL_TIMEOUT, 60000). % 1 minute.
|
||||||
-define(SLOT_TIMEOUT, 18000000). % 5 hours.
|
-define(SLOT_TIMEOUT, timer:hours(5)).
|
||||||
-define(URL_ENC(URL), binary_to_list(misc:url_encode(URL))).
|
-define(URL_ENC(URL), binary_to_list(misc:url_encode(URL))).
|
||||||
-define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(misc:ip_to_list(IP))).
|
-define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(misc:ip_to_list(IP))).
|
||||||
-define(STR_TO_INT(Str, B), binary_to_integer(iolist_to_binary(Str), B)).
|
-define(STR_TO_INT(Str, B), binary_to_integer(iolist_to_binary(Str), B)).
|
||||||
@ -298,14 +298,14 @@ handle_call({use_slot, Slot, Size}, _From,
|
|||||||
custom_headers = CustomHeaders,
|
custom_headers = CustomHeaders,
|
||||||
docroot = DocRoot} = State) ->
|
docroot = DocRoot} = State) ->
|
||||||
case get_slot(Slot, State) of
|
case get_slot(Slot, State) of
|
||||||
{ok, {Size, Timer}} ->
|
{ok, {Size, TRef}} ->
|
||||||
timer:cancel(Timer),
|
cancel_timer(TRef),
|
||||||
NewState = del_slot(Slot, State),
|
NewState = del_slot(Slot, State),
|
||||||
Path = str:join([DocRoot | Slot], <<$/>>),
|
Path = str:join([DocRoot | Slot], <<$/>>),
|
||||||
{reply,
|
{reply,
|
||||||
{ok, Path, FileMode, DirMode, GetPrefix, Thumbnail, CustomHeaders},
|
{ok, Path, FileMode, DirMode, GetPrefix, Thumbnail, CustomHeaders},
|
||||||
NewState};
|
NewState};
|
||||||
{ok, {_WrongSize, _Timer}} ->
|
{ok, {_WrongSize, _TRef}} ->
|
||||||
{reply, {error, size_mismatch}, State};
|
{reply, {error, size_mismatch}, State};
|
||||||
error ->
|
error ->
|
||||||
{reply, {error, invalid_slot}, State}
|
{reply, {error, invalid_slot}, State}
|
||||||
@ -347,7 +347,7 @@ handle_info({route, #iq{lang = Lang} = Packet}, State) ->
|
|||||||
ejabberd_router:route_error(Packet, Err),
|
ejabberd_router:route_error(Packet, Err),
|
||||||
{noreply, State}
|
{noreply, State}
|
||||||
end;
|
end;
|
||||||
handle_info({slot_timed_out, Slot}, State) ->
|
handle_info({timeout, _TRef, Slot}, State) ->
|
||||||
NewState = del_slot(Slot, State),
|
NewState = del_slot(Slot, State),
|
||||||
{noreply, NewState};
|
{noreply, NewState};
|
||||||
handle_info(Info, State) ->
|
handle_info(Info, State) ->
|
||||||
@ -642,13 +642,13 @@ create_slot(#state{service_url = ServiceURL},
|
|||||||
|
|
||||||
-spec add_slot(slot(), pos_integer(), state()) -> state().
|
-spec add_slot(slot(), pos_integer(), state()) -> state().
|
||||||
add_slot(Slot, Size, #state{external_secret = <<>>, slots = Slots} = State) ->
|
add_slot(Slot, Size, #state{external_secret = <<>>, slots = Slots} = State) ->
|
||||||
{ok, Timer} = timer:send_after(?SLOT_TIMEOUT, {slot_timed_out, Slot}),
|
TRef = erlang:start_timer(?SLOT_TIMEOUT, self(), Slot),
|
||||||
NewSlots = maps:put(Slot, {Size, Timer}, Slots),
|
NewSlots = maps:put(Slot, {Size, TRef}, Slots),
|
||||||
State#state{slots = NewSlots};
|
State#state{slots = NewSlots};
|
||||||
add_slot(_Slot, _Size, State) ->
|
add_slot(_Slot, _Size, State) ->
|
||||||
State.
|
State.
|
||||||
|
|
||||||
-spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error.
|
-spec get_slot(slot(), state()) -> {ok, {pos_integer(), reference()}} | error.
|
||||||
get_slot(Slot, #state{slots = Slots}) ->
|
get_slot(Slot, #state{slots = Slots}) ->
|
||||||
maps:find(Slot, Slots).
|
maps:find(Slot, Slots).
|
||||||
|
|
||||||
@ -702,6 +702,17 @@ replace_special_chars(S) ->
|
|||||||
yield_content_type(<<"">>) -> ?DEFAULT_CONTENT_TYPE;
|
yield_content_type(<<"">>) -> ?DEFAULT_CONTENT_TYPE;
|
||||||
yield_content_type(Type) -> Type.
|
yield_content_type(Type) -> Type.
|
||||||
|
|
||||||
|
-spec cancel_timer(reference()) -> ok.
|
||||||
|
cancel_timer(TRef) ->
|
||||||
|
case erlang:cancel_timer(TRef) of
|
||||||
|
false ->
|
||||||
|
receive {timeout, TRef, _} -> ok
|
||||||
|
after 0 -> ok
|
||||||
|
end;
|
||||||
|
_ ->
|
||||||
|
ok
|
||||||
|
end.
|
||||||
|
|
||||||
-spec iq_disco_info(binary(), binary(), binary(), [xdata()]) -> disco_info().
|
-spec iq_disco_info(binary(), binary(), binary(), [xdata()]) -> disco_info().
|
||||||
iq_disco_info(Host, Lang, Name, AddInfo) ->
|
iq_disco_info(Host, Lang, Name, AddInfo) ->
|
||||||
Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size) of
|
Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size) of
|
||||||
|
Loading…
Reference in New Issue
Block a user