|
30 | 30 |
|
31 | 31 | -define(SERVICE_REQUEST_TIMEOUT, 5000). % 5 seconds.
|
32 | 32 | -define(CALL_TIMEOUT, 60000). % 1 minute.
|
33 |
| --define(SLOT_TIMEOUT, 18000000). % 5 hours. |
| 33 | +-define(SLOT_TIMEOUT, timer:hours(5)). |
34 | 34 | -define(URL_ENC(URL), binary_to_list(misc:url_encode(URL))).
|
35 | 35 | -define(ADDR_TO_STR(IP), ejabberd_config:may_hide_data(misc:ip_to_list(IP))).
|
36 | 36 | -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,
|
298 | 298 | custom_headers = CustomHeaders,
|
299 | 299 | docroot = DocRoot} = State) ->
|
300 | 300 | case get_slot(Slot, State) of
|
301 |
| - {ok, {Size, Timer}} -> |
302 |
| - timer:cancel(Timer), |
| 301 | + {ok, {Size, TRef}} -> |
| 302 | + cancel_timer(TRef), |
303 | 303 | NewState = del_slot(Slot, State),
|
304 | 304 | Path = str:join([DocRoot | Slot], <<$/>>),
|
305 | 305 | {reply,
|
306 | 306 | {ok, Path, FileMode, DirMode, GetPrefix, Thumbnail, CustomHeaders},
|
307 | 307 | NewState};
|
308 |
| - {ok, {_WrongSize, _Timer}} -> |
| 308 | + {ok, {_WrongSize, _TRef}} -> |
309 | 309 | {reply, {error, size_mismatch}, State};
|
310 | 310 | error ->
|
311 | 311 | {reply, {error, invalid_slot}, State}
|
@@ -347,7 +347,7 @@ handle_info({route, #iq{lang = Lang} = Packet}, State) ->
|
347 | 347 | ejabberd_router:route_error(Packet, Err),
|
348 | 348 | {noreply, State}
|
349 | 349 | end;
|
350 |
| -handle_info({slot_timed_out, Slot}, State) -> |
| 350 | +handle_info({timeout, _TRef, Slot}, State) -> |
351 | 351 | NewState = del_slot(Slot, State),
|
352 | 352 | {noreply, NewState};
|
353 | 353 | handle_info(Info, State) ->
|
@@ -642,13 +642,13 @@ create_slot(#state{service_url = ServiceURL},
|
642 | 642 |
|
643 | 643 | -spec add_slot(slot(), pos_integer(), state()) -> state().
|
644 | 644 | add_slot(Slot, Size, #state{external_secret = <<>>, slots = Slots} = State) ->
|
645 |
| - {ok, Timer} = timer:send_after(?SLOT_TIMEOUT, {slot_timed_out, Slot}), |
646 |
| - NewSlots = maps:put(Slot, {Size, Timer}, Slots), |
| 645 | + TRef = erlang:start_timer(?SLOT_TIMEOUT, self(), Slot), |
| 646 | + NewSlots = maps:put(Slot, {Size, TRef}, Slots), |
647 | 647 | State#state{slots = NewSlots};
|
648 | 648 | add_slot(_Slot, _Size, State) ->
|
649 | 649 | State.
|
650 | 650 |
|
651 |
| --spec get_slot(slot(), state()) -> {ok, {pos_integer(), timer:tref()}} | error. |
| 651 | +-spec get_slot(slot(), state()) -> {ok, {pos_integer(), reference()}} | error. |
652 | 652 | get_slot(Slot, #state{slots = Slots}) ->
|
653 | 653 | maps:find(Slot, Slots).
|
654 | 654 |
|
@@ -702,6 +702,17 @@ replace_special_chars(S) ->
|
702 | 702 | yield_content_type(<<"">>) -> ?DEFAULT_CONTENT_TYPE;
|
703 | 703 | yield_content_type(Type) -> Type.
|
704 | 704 |
|
| 705 | +-spec cancel_timer(reference()) -> ok. |
| 706 | +cancel_timer(TRef) -> |
| 707 | + case erlang:cancel_timer(TRef) of |
| 708 | + false -> |
| 709 | + receive {timeout, TRef, _} -> ok |
| 710 | + after 0 -> ok |
| 711 | + end; |
| 712 | + _ -> |
| 713 | + ok |
| 714 | + end. |
| 715 | + |
705 | 716 | -spec iq_disco_info(binary(), binary(), binary(), [xdata()]) -> disco_info().
|
706 | 717 | iq_disco_info(Host, Lang, Name, AddInfo) ->
|
707 | 718 | Form = case gen_mod:get_module_opt(Host, ?MODULE, max_size) of
|
|
0 commit comments