Module acceptor_pool

This module provides a gen_tcp acceptor pool supervisor.

Behaviours: gen_server.

This module defines the acceptor_pool behaviour.
Required callback functions: init/1.

See also: acceptor, supervisor.

Description

This module provides a gen_tcp acceptor pool supervisor. An acceptor_pool must define the acceptor_pool behaviour callback, which is very similar to the supervisor behaviour except all children must be acceptor proccesses and only the map terms are supported. The only callback is init/1:
 -callback init(Args) -> {ok, {PoolFlags, [AcceptorSpec, ...]}} | ignore when
     Args :: any(),
     PoolFlags :: pool_flags(),
     AcceptorSpec :: acceptor_spec().

The pool_flags() are the intensity and period pairs as in as supervisor:sup_flags/0 and have the equivalent behaviour.

There must be list of a single acceptor_spec(), just as there can only be a single supervisor:child_spec/0 when the strategy is simple_one_for_one. The map pairs are the same as supervisor:child_spec/0 except that start's value is of form:
  {AcceptorMod :: module(), AcceptorArg :: term(), Opts :: [acceptor:option()]}

AcceptorMod is an acceptor callback module that will be called with argument AcceptorArg, and spawned with acceptor options Opts.

There is an additional grace key, that has a timeout() value. This is the time in milliseconds that the acceptor pool will wait for children to exit before starting to shut them down when terminating. This allows connections to be gracefully closed.

To start accepting connections using the acceptor_pool call accept_socket/3.

Data Types

acceptor_spec()

acceptor_spec() = #{id := term(), start := {module(), any(), [acceptor:option()]}, restart => permanent | transient | temporary, shutdown => timeout() | brutal_kill, grace => timeout(), type => worker | supervisor, modules => [module()] | dynamic}

name()

name() = {inet:ip_address(), inet:port_number()} | inet:returned_non_ip_address()

pool()

pool() = pid() | atom() | {atom(), node()} | {via, module(), any()} | {global, any()}

pool_flags()

pool_flags() = #{intensity => non_neg_integer(), period => pos_integer()}

Function Index

accept_socket/3Ask acceptor_pool Pool to accept on the listen socket Sock with Acceptors number of acceptors.
count_children/1Count the children of the acceptor_pool.
start_link/2Start an acceptor_pool with callback module Module and argument Args.
start_link/3Start an acceptor_pool with name Name, callback module Module and argument Args.
which_children/1List the children of the acceptor_pool.
which_sockets/1List the listen sockets being used by the acceptor_pool.

Function Details

accept_socket/3

accept_socket(Pool, Sock, Acceptors) -> {ok, Ref} | {error, Reason}

Ask acceptor_pool Pool to accept on the listen socket Sock with Acceptors number of acceptors.

Returns {ok, Ref} on success or {error, Reason} on failure. If acceptors fail to accept connections an exit signal is sent Sock.

count_children/1

count_children(Pool) -> Counts

Count the children of the acceptor_pool.

Processes that are waiting for a socket are not included in active.

See also: supervisor:count_children/1.

start_link/2

start_link(Module, Args) -> {ok, Pid} | ignore | {error, Reason}

Start an acceptor_pool with callback module Module and argument Args.

See also: start_link/3.

start_link/3

start_link(Name, Module, Args) -> {ok, Pid} | ignore | {error, Reason}

Start an acceptor_pool with name Name, callback module Module and argument Args.

This function is equivalent to supervisor:start_link/3 except starts an acceptor_pool instead of a supervisor.

See also: supervisor:start_link/3.

which_children/1

which_children(Pool) -> [{Id, Child, Type, Modules}]

List the children of the acceptor_pool.

This function is equivalent to supervisor:which_children/1 except that the peer name, listen socket name and a unique reference are combined with the id from init/1.

Processes that are waiting for a socket are not included.

See also: supervisor:which_children/1.

which_sockets/1

which_sockets(Pool) -> [{SockModule, SockName, Sock, Ref}]

List the listen sockets being used by the acceptor_pool.


Generated by EDoc, Sep 19 2016, 00:22:34.