Debian Codegraph @

doc/src/manual/ranch.child_spec.asciidoc

raw
1 = ranch:child_spec(3)
2
3 == Name
4
5 ranch:child_spec - Build child specifications for a new listener
6
7 == Description
8
9 [source,erlang]
10 ----
11 child_spec(Ref :: ranch_ref(),
12 Transport :: module(),
13 TransOpts :: ranch:opts(),
14 Protocol :: module(),
15 ProtoOpts :: any())
16 -> supervisor:child_spec()
17 ----
18
19 Build child specifications for a new listener which can
20 be embedded directly in an application's supervision
21 tree.
22
23 The actual listener is placed under a supervisor which
24 monitors `ranch_server` via a proxy process and will
25 restart the listener if `ranch_server` crashes.
26
27 == Arguments
28
29 Ref::
30
31 The listener name is used to refer to this listener in
32 future calls, for example when updating the configuration.
33 +
34 It can be any Erlang term. An atom is generally good enough,
35 for example `api`, `my_app_clear` or `my_app_tls`.
36
37 Transport::
38
39 The transport module that will be used by Ranch to accept
40 connections and that will be passed to the protocol module
41 along with the socket.
42 +
43 The interface of the transport module is documented in the
44 link:man:ranch_transport(3)[ranch_transport(3)] manual.
45
46 TransportOpts::
47
48 Transport options include the Ranch-specific options
49 and the socket options. The listener's port number must
50 be defined in the socket options.
51 +
52 The available options for the built-in Ranch transports
53 are documented in the link:man:ranch_tcp(3)[ranch_tcp(3)]
54 and link:man:ranch_ssl(3)[ranch_ssl(3)] manuals.
55
56 Protocol::
57
58 The protocol module that will be used by Ranch after
59 the connection has been accepted.
60 +
61 The interface of the protocol module is documented in the
62 link:man:ranch_protocol(3)[ranch_protocol(3)] manual.
63
64 ProtocolOpts::
65
66 The protocol options given when calling the protocol
67 module. Please consult the documentation of the protocol
68 module you are using for more details.
69
70 == Return value
71
72 Child specifications are returned.
73
74 == Changelog
75
76 * *2.0*: The actual listener is placed under a supervisor in order to
77 restart the listener if `ranch_server` crashes.
78 * *2.0*: The `TransOpts` argument must no longer contain
79 Ranch-specific options if given as a list. Use a map.
80 * *1.4*: The `NumAcceptors` argument was moved to the transport options.
81
82 == Examples
83
84 .Embed a listener
85 [source,erlang]
86 ----
87 -behavior(supervisor).
88
89 init(_) ->
90 {ok, {#{strategy => one_for_one}, [
91 ranch:child_spec(echo,
92 ranch_tcp, [{port, 5555}],
93 echo_protocol, []
94 )
95 ]}}.
96 ----
97
98 == See also
99
100 link:man:ranch:start_listener(3)[ranch:start_listener(3)],
101 link:man:ranch:stop_listener(3)[ranch:stop_listener(3)],
102 link:man:ranch(3)[ranch(3)],
103 link:man:ranch_tcp(3)[ranch_tcp(3)],
104 link:man:ranch_ssl(3)[ranch_ssl(3)],
105 link:man:ranch_transport(3)[ranch_transport(3)],
106 link:man:ranch_protocol(3)[ranch_protocol(3)]