File: remove_conn_and_wait_protocol.erl

package info (click to toggle)
erlang-ranch 1.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 668 kB
  • sloc: erlang: 2,368; makefile: 45
file content (19 lines) | stat: -rw-r--r-- 429 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-module(remove_conn_and_wait_protocol).
-behaviour(ranch_protocol).

-export([start_link/4]).
-export([init/3]).

start_link(Ref, _, _, [{remove, MaybeRemove, Timeout}]) ->
	Pid = spawn_link(?MODULE, init, [Ref, MaybeRemove, Timeout]),
	{ok, Pid}.

init(Ref, MaybeRemove, Timeout) ->
	ranch:accept_ack(Ref),
	case MaybeRemove of
		true ->
			ranch:remove_connection(Ref);
		false ->
			ok
	end,
	receive after Timeout -> ok end.