ranch.handshake.asciidoc 2.2 KB

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