ranch(3)

Name

ranch - Socket acceptor pool

Description

The module ranch provides functions for starting and manipulating Ranch listeners.

Exports

Start/stop:

Suspend/resume:

Connections:

Options:

Introspection:

Types

max_conns()

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()

opt() = {ack_timeout, timeout()}
      | {connection_type, worker | supervisor}
      | {max_connections, max_conns()}
      | {num_acceptors, pos_integer()}
      | {shutdown, timeout() | brutal_kill}
      | {socket, any()}

Deprecated form for Ranch-specific options.

Please use the opts() type when you need to provide Ranch-specific transport options. Socket options will remain separate from the Ranch-specific options.

opts()

opts() = any() | #{
    connection_type   => worker | supervisor,
    handshake_timeout => timeout(),
    max_connections   => max_conns(),
    logger            => module(),
    num_acceptors     => pos_integer(),
    shutdown          => timeout() | brutal_kill,
    socket            => any(),
    socket_opts       => any()
}

Transport options.

The transport options are a combination of Ranch-specific options and socket options. Socket options may be given directly (assuming they are not a map and no Ranch-specific option needs to be given) or as part of socket_opts.

None of the options are required.

ack_timeout

When ack_timeout is found in a transport options proplist, it is converted to the handshake_timeout option from the map. They are equivalent. The ack_timeout option will be removed in Ranch 2.0.

connection_type (worker)

Type of process that will handle the connection.

handshake_timeout (5000)

Maximum allowed time for the ranch:handshake/1,2 call to finish.

max_connections (1024)

Maximum number of active connections. Soft limit. Use infinity to disable the limit entirely.

num_acceptors (10)

Number of processes that accept connections.

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. This option will be removed in Ranch 2.0. Use a custom transport module acting as a wrapper for ranch_tcp or ranch_ssl instead.

socket_opts

Socket options given to Transport:listen/1. Please refer to the documentation of the transport module you are using for more details.

ref()

ref() = any()

Unique name used to refer to a listener.

Changelog

  • 1.6: The logger option was added.
  • 1.6: The opt() type was deprecated in favor of the new opts() type.

See also

ranch(7)

Ranch 1.7 Function Reference

Navigation

Version select

Like my work? Donate!

Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:

Recurring payment options are also available via GitHub Sponsors. These funds are used to cover the recurring expenses like food, dedicated servers or domain names.