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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
= ranch(3)
== Name
ranch - socket acceptor pool
== Description
The `ranch` module provides functions for starting and
manipulating Ranch listeners.
== Types
=== max_conns() = non_neg_integer() | infinity
Maximum number of connections allowed on this listener.
This is a soft limit. The actual number of connections
might be slightly above the limit due to concurrency
when accepting new connections. Some connections may
also be removed from this count explicitly by the user
code.
=== opt()
[source,erlang]
----
opt() = {ack_timeout, timeout()}
| {connection_type, worker | supervisor}
| {max_connections, max_conns()}
| {shutdown, timeout() | brutal_kill}
| {socket, any()}
----
Ranch-specific transport options.
These options are not passed on to the transports.
They are used by Ranch while setting up the listeners.
=== ref() = any()
Unique name used to refer to a listener.
== Option descriptions
None of the options are required.
ack_timeout (5000)::
Maximum allowed time for the `ranch:accept_ack/1` call to finish.
connection_type (worker)::
Type of process that will handle the connection.
max_connections (1024)::
Maximum number of active connections. Soft limit. Using `infinity` will disable the limit entirely.
shutdown (5000)::
Maximum allowed time for children to stop on listener shutdown.
socket::
Listening socket opened externally to be used instead of calling `Transport:listen/1`.
== Exports
=== accept_ack(Ref) -> ok
Ref = ref():: Listener name.
Acknowledge that the connection is accepted.
This function MUST be used by a connection process to inform
Ranch that it initialized properly and let it perform any
additional operations before the socket can be safely used.
=== child_spec(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts) -> supervisor:child_spec()
Ref = ref():: Listener name.
NumAcceptors = non_neg_integer():: Number of acceptor processes.
Transport = module():: Transport module.
TransOpts = any():: Transport options.
Protocol = module():: Protocol module.
ProtoOpts = any():: Protocol options.
Return child specifications for a new listener.
This function can be used to embed a listener directly
in an application instead of letting Ranch handle it.
=== get_addr(Ref) -> {IP, Port}
Ref = ref():: Listener name.
IP = inet:ip_address():: IP of the interface used by this listener.
Port = inet:port_number():: Port number used by this listener.
Return the IP address and port for the given listener.
=== get_max_connections(Ref) -> MaxConns
Ref = ref():: Listener name.
MaxConns = max_conns():: Current maximum number of connections.
Return the max number of connections allowed for the given listener.
=== get_port(Ref) -> Port
Ref = ref():: Listener name.
Port = inet:port_number():: Port number used by this listener.
Return the port for the given listener.
=== get_protocol_options(Ref) -> ProtoOpts
Ref = ref():: Listener name.
ProtoOpts = any():: Current protocol options.
Return the protocol options set for the given listener.
=== info() -> [{Ref, [{Key, Value}]}]
Ref = ref():: Listener name.
Key = atom():: Information key.
Value = any():: Information value.
Return detailed information about all Ranch listeners.
The following keys are defined:
pid:: Pid of the listener's top-level supervisor.
ip:: Interface Ranch listens on.
port:: Port number Ranch listens on.
num_acceptors:: Number of acceptor processes.
max_connections:: Maximum number of connections.
active_connections:: Number of active connections.
all_connections:: Number of connections, including those removed from the count.
transport:: Transport module.
transport_options:: Transport options.
protocol:: Protocol module.
protocol_options:: Protocol options.
=== procs(Ref, acceptors | connections) -> [pid()]
Ref = ref():: Listener name.
Return all acceptor or connection processes for one listener.
=== remove_connection(Ref) -> ok
Ref = ref():: Listener name.
Do not count this connection when limiting the number of connections.
You can use this function for long-running connection processes
which spend most of their time idling rather than consuming
resources. This allows Ranch to accept a lot more connections
without sacrificing the latency of the system.
This function may only be called from a connection process.
=== set_max_connections(Ref, MaxConns) -> ok
Ref = ref():: Listener name.
MaxConns = max_conns():: New maximum number of connections.
Set the max number of connections for the given listener.
The change will be applied immediately. If the new value is
smaller than the previous one, Ranch will not kill the extra
connections, but will wait for them to terminate properly.
=== set_protocol_options(Ref, ProtoOpts) -> ok
Ref = ref():: Listener name.
ProtoOpts = any():: New protocol options.
Set the protocol options for the given listener.
The change will be applied immediately for all new connections.
Old connections will not receive the new options.
=== start_listener(Ref, NumAcceptors, Transport, TransOpts, Protocol, ProtoOpts) -> {ok, pid()} | {error, badarg}
Ref = ref():: Listener name.
NumAcceptors = non_neg_integer():: Number of acceptor processes.
Transport = module():: Transport module.
TransOpts = any():: Transport options.
Protocol = module():: Protocol module.
ProtoOpts = any():: Protocol options.
Start listening for connections using the given transport
and protocol. Returns the pid for this listener's supervisor.
There are additional transport options that apply
regardless of transport. They allow configuring how the
connections are supervised, rate limited and more. Please
consult the previous section for more details.
=== stop_listener(Ref) -> ok | {error, not_found}
Ref = ref():: Listener name.
Stop the given listener.
The listener is stopped gracefully, first by closing the
listening port, then by stopping the connection processes.
These processes are stopped according to the `shutdown`
transport option, which may be set to brutally kill all
connection processes or give them some time to stop properly.
This function does not return until the listener is
completely stopped.
|