aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/ranch.handshake.asciidoc
blob: 508abe5af6a2ed37b4814de97dfa2a02680c2c4e (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
= ranch:handshake(3)

== Name

ranch:handshake - Perform the transport handshake

== Description

[source,erlang]
----
handshake(Ref)       -> {ok, Socket} | {continue, Info}
handshake(Ref, Opts) -> {ok, Socket} | {continue, Info}

Ref    :: ranch:ref()
Opts   :: any()
Socket :: any()
Info   :: any()
----

Perform the transport handshake.

This function must be called by the protocol process in order
to retrieve the socket for the connection. Ranch performs the
handshake necessary to give control of the socket to this
process and also does the transport handshake, for example
setting up the TLS connection.

== Arguments

Ref::

The listener name.

Opts::

Transport handshake options.
+
Allowed options depend on the transport module.

== Return value

An `ok` tuple is returned containing the socket for the connection
by default.

Depending on configuration, a `continue` tuple can otherwise
be returned when the handshake operation is paused. It contains
data provided by the transport that can be used to inform further
decisions before resuming the handshake, for example to provide
new transport options. The handshake can be resumed using
link:man:ranch:handshake_continue(3)[ranch:handshake_continue(3)]
or canceled using
link:man:ranch:handshake_cancel(3)[ranch:handshake_cancel(3)].

This function will trigger an exception when an error occurs.

== Changelog

* *2.0*: The `continue` tuple can now be returned.
* *1.6*: Function introduced. Replaces `ranch:accept_ack/1`.

== Examples

.Initialize the connection process
[source,erlang]
----
start_link(Ref, Transport, Opts) ->
    Pid = proc_lib:spawn_link(?MODULE, init,
        [Ref, Transport, Opts]),
    {ok, Pid}.

init(Ref, Transport, Opts) ->
    {ok, Socket} = ranch:handshake(Ref),
    loop(#state{ref=Ref, socket=Socket,
        transport=Transport, opts=Opts}).
----

== See also

link:man:ranch:start_listener(3)[ranch:start_listener(3)],
link:man:ranch:handshake_continue(3)[ranch:handshake_continue(3)],
link:man:ranch:handshake_cancel(3)[ranch:handshake_cancel(3)],
link:man:ranch:recv_proxy_header(3)[ranch:recv_proxy_header(3)],
link:man:ranch:remove_connection(3)[ranch:remove_connection(3)],
link:man:ranch(3)[ranch(3)]