| 1 |
= ranch:handshake(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
ranch:handshake - Perform the transport handshake |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
handshake(Ref) -> {ok, Socket} | {continue, Info} |
| 12 |
handshake(Ref, Opts) -> {ok, Socket} | {continue, Info} |
| 13 |
|
| 14 |
Ref :: ranch:ref() |
| 15 |
Opts :: any() |
| 16 |
Socket :: any() |
| 17 |
Info :: any() |
| 18 |
---- |
| 19 |
|
| 20 |
Perform the transport handshake. |
| 21 |
|
| 22 |
This function must be called by the protocol process in order |
| 23 |
to retrieve the socket for the connection. Ranch performs the |
| 24 |
handshake necessary to give control of the socket to this |
| 25 |
process and also does the transport handshake, for example |
| 26 |
setting up the TLS connection. |
| 27 |
|
| 28 |
== Arguments |
| 29 |
|
| 30 |
Ref:: |
| 31 |
|
| 32 |
The listener name. |
| 33 |
|
| 34 |
Opts:: |
| 35 |
|
| 36 |
Transport handshake options. |
| 37 |
+ |
| 38 |
Allowed options depend on the transport module. |
| 39 |
|
| 40 |
== Return value |
| 41 |
|
| 42 |
An `ok` tuple is returned containing the socket for the connection |
| 43 |
by default. |
| 44 |
|
| 45 |
Depending on configuration, a `continue` tuple can otherwise |
| 46 |
be returned when the handshake operation is paused. It contains |
| 47 |
data provided by the transport that can be used to inform further |
| 48 |
decisions before resuming the handshake, for example to provide |
| 49 |
new transport options. The handshake can be resumed using |
| 50 |
link:man:ranch:handshake_continue(3)[ranch:handshake_continue(3)] |
| 51 |
or canceled using |
| 52 |
link:man:ranch:handshake_cancel(3)[ranch:handshake_cancel(3)]. |
| 53 |
|
| 54 |
This function will trigger an exception when an error occurs. |
| 55 |
|
| 56 |
== Changelog |
| 57 |
|
| 58 |
* *2.0*: The `continue` tuple can now be returned. |
| 59 |
* *1.6*: Function introduced. Replaces `ranch:accept_ack/1`. |
| 60 |
|
| 61 |
== Examples |
| 62 |
|
| 63 |
.Initialize the connection process |
| 64 |
[source,erlang] |
| 65 |
---- |
| 66 |
start_link(Ref, Transport, Opts) -> |
| 67 |
Pid = proc_lib:spawn_link(?MODULE, init, |
| 68 |
[Ref, Transport, Opts]), |
| 69 |
{ok, Pid}. |
| 70 |
|
| 71 |
init(Ref, Transport, Opts) -> |
| 72 |
{ok, Socket} = ranch:handshake(Ref), |
| 73 |
loop(#state{ref=Ref, socket=Socket, |
| 74 |
transport=Transport, opts=Opts}). |
| 75 |
---- |
| 76 |
|
| 77 |
== See also |
| 78 |
|
| 79 |
link:man:ranch:start_listener(3)[ranch:start_listener(3)], |
| 80 |
link:man:ranch:handshake_continue(3)[ranch:handshake_continue(3)], |
| 81 |
link:man:ranch:handshake_cancel(3)[ranch:handshake_cancel(3)], |
| 82 |
link:man:ranch:recv_proxy_header(3)[ranch:recv_proxy_header(3)], |
| 83 |
link:man:ranch:remove_connection(3)[ranch:remove_connection(3)], |
| 84 |
link:man:ranch(3)[ranch(3)] |