aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/ranch_protocol.asciidoc
blob: 5a94399623a697e43db3a739a7871d9d9c1d8e50 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
= ranch_protocol(3)

== Name

ranch_protocol - Protocol modules

== Description

The module `ranch_protocol` defines the interface used
by Ranch protocols.

== Callbacks

Ranch protocols implement the following interface:

[source,erlang]
----
start_link(Ref       :: ranch:ref(),
           Transport :: module(),
           ProtoOpts :: any())
    -> {ok, ConnPid :: pid()}
     | {ok, SupPid :: pid(), ConnPid :: pid()}
----

Start a new connection process.

The only purpose of this callback is to start a process that
will handle the socket. It must spawn the process, link and
then return the new pid. This function will always be called
from inside a supervisor.

This callback can also return two pids. The first pid is the
pid of the process that will be supervised. The second pid is
the pid of the process that will receive ownership of the
socket. This second process must be a child of the first. This
form is only available when `connection_type` is set to
`supervisor`.

If any other value is returned, the supervisor will close the
socket and assume no process has been started.

Do not perform any operations in this callback, as this would
block the supervisor responsible for starting connection
processes and degrade performance severely.

== Changelog

* *2.0*: The second argument `Socket` was removed.
* *1.6*: The second argument `Socket` was deprecated. Call
         link:man:ranch:handshake(3)[ranch:handshake(3)]
         to obtain the socket.

== See also

link:man:ranch:handshake(3)[ranch:handshake(3)],
link:man:ranch(7)[ranch(7)]