remove_conn_and_wait_protocol.erl 429 B

12345678910111213141516171819
  1. -module(remove_conn_and_wait_protocol).
  2. -behaviour(ranch_protocol).
  3. -export([start_link/4]).
  4. -export([init/3]).
  5. start_link(Ref, _, _, [{remove, MaybeRemove, Timeout}]) ->
  6. Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove, Timeout]),
  7. {ok, Pid}.
  8. init(Ref, MaybeRemove, Timeout) ->
  9. ranch:accept_ack(Ref),
  10. case MaybeRemove of
  11. true ->
  12. ranch:remove_connection(Ref);
  13. false ->
  14. ok
  15. end,
  16. receive after Timeout -> ok end.