aboutsummaryrefslogtreecommitdiffstats
path: root/templates/ranch_protocol.erl
diff options
context:
space:
mode:
Diffstat (limited to 'templates/ranch_protocol.erl')
-rw-r--r--templates/ranch_protocol.erl25
1 files changed, 25 insertions, 0 deletions
diff --git a/templates/ranch_protocol.erl b/templates/ranch_protocol.erl
new file mode 100644
index 0000000..1458815
--- /dev/null
+++ b/templates/ranch_protocol.erl
@@ -0,0 +1,25 @@
+-module(template_name).
+-behaviour(ranch_protocol).
+
+-export([start_link/4]).
+-export([init/4]).
+
+-type opts() :: [].
+-export_type([opts/0]).
+
+-record(state, {
+ socket :: inet:socket(),
+ transport :: module()
+}).
+
+start_link(Ref, Socket, Transport, Opts) ->
+ Pid = spawn_link(?MODULE, init, [Ref, Socket, Transport, Opts]),
+ {ok, Pid}.
+
+-spec init(ranch:ref(), inet:socket(), module(), opts()) -> ok.
+init(Ref, Socket, Transport, _Opts) ->
+ ok = ranch:accept_ack(Ref),
+ loop(#state{socket=Socket, transport=Transport}).
+
+loop(State) ->
+ loop(State).