nquic_listener_mgr (nquic v1.0.0)

View Source

Listener manager gen_server.

Holds the mutable state that used to live inside the legacy nquic_listener gen_server: the accept queue, the parked acceptors, the configured listen options, and the resolved UDP port. Publishes its own pid to the listener's dispatch table on init so receivers and connections can route the connection_established notification through nquic_dispatch:get_mgr/1.

Started as the first child of nquic_listener_sup under a rest_for_one strategy, so a crash here cascades into a fresh sub-tree below (partitions, receivers) instead of leaving stale references in the dispatch table.

Summary

Functions

Accept a new connection, blocking until one is available or timeout expires.

Hand a freshly handshaked, proactively exported connection to the listener manager. The handshake gen_statem has already terminated; Entry carries the protocol state, socket, dispatch handle, and the per-conn-fd flag.

Return the dispatch table for this listener.

Return the metrics handle attached to this listener's dispatch table.

Return the UDP port number this listener is bound to.

Return the listener's static stateless-reset key.

Return a single listener option as seen at startup.

Start the listener manager. Args carries the dispatch handle and resolved opts.

Types

accept_entry()

-type accept_entry() ::
          {exported,
           nquic_protocol:state(),
           nquic_socket:t(),
           nquic_dispatch:t() | undefined,
           boolean(),
           pid()}.

Functions

accept(Mgr, Timeout)

-spec accept(pid(), timeout()) -> {ok, accept_entry()} | {error, nquic_error:any_reason()}.

Accept a new connection, blocking until one is available or timeout expires.

connection_established(Mgr, Entry)

-spec connection_established(pid(), accept_entry()) -> ok.

Hand a freshly handshaked, proactively exported connection to the listener manager. The handshake gen_statem has already terminated; Entry carries the protocol state, socket, dispatch handle, and the per-conn-fd flag.

get_dispatch(Mgr)

-spec get_dispatch(pid()) -> {ok, nquic_dispatch:t()} | {error, nquic_error:any_reason()}.

Return the dispatch table for this listener.

get_metrics(Mgr)

-spec get_metrics(pid()) -> {ok, nquic_metrics:t()} | {error, nquic_error:any_reason()}.

Return the metrics handle attached to this listener's dispatch table.

get_port(Mgr)

-spec get_port(pid()) -> {ok, inet:port_number()} | {error, nquic_error:any_reason()}.

Return the UDP port number this listener is bound to.

get_static_key(Mgr)

-spec get_static_key(pid()) -> {ok, binary()} | {error, nquic_error:any_reason()}.

Return the listener's static stateless-reset key.

handle_call/3

-spec handle_call(term(),
                  gen_server:from(),
                  #state{dispatch :: nquic_dispatch:t(),
                         opts :: map(),
                         port :: inet:port_number(),
                         static_key :: binary(),
                         accept_queue :: queue:queue(accept_entry()),
                         waiting_acceptors :: [gen_server:from()],
                         max_accept_queue :: non_neg_integer()}) ->
                     {reply,
                      term(),
                      #state{dispatch :: nquic_dispatch:t(),
                             opts :: map(),
                             port :: inet:port_number(),
                             static_key :: binary(),
                             accept_queue :: queue:queue(accept_entry()),
                             waiting_acceptors :: [gen_server:from()],
                             max_accept_queue :: non_neg_integer()}} |
                     {noreply,
                      #state{dispatch :: nquic_dispatch:t(),
                             opts :: map(),
                             port :: inet:port_number(),
                             static_key :: binary(),
                             accept_queue :: queue:queue(accept_entry()),
                             waiting_acceptors :: [gen_server:from()],
                             max_accept_queue :: non_neg_integer()}}.

handle_cast/2

-spec handle_cast(term(),
                  #state{dispatch :: nquic_dispatch:t(),
                         opts :: map(),
                         port :: inet:port_number(),
                         static_key :: binary(),
                         accept_queue :: queue:queue(accept_entry()),
                         waiting_acceptors :: [gen_server:from()],
                         max_accept_queue :: non_neg_integer()}) ->
                     {noreply,
                      #state{dispatch :: nquic_dispatch:t(),
                             opts :: map(),
                             port :: inet:port_number(),
                             static_key :: binary(),
                             accept_queue :: queue:queue(accept_entry()),
                             waiting_acceptors :: [gen_server:from()],
                             max_accept_queue :: non_neg_integer()}}.

handle_info(Info, State)

-spec handle_info(term(),
                  #state{dispatch :: nquic_dispatch:t(),
                         opts :: map(),
                         port :: inet:port_number(),
                         static_key :: binary(),
                         accept_queue :: queue:queue(accept_entry()),
                         waiting_acceptors :: [gen_server:from()],
                         max_accept_queue :: non_neg_integer()}) ->
                     {noreply,
                      #state{dispatch :: nquic_dispatch:t(),
                             opts :: map(),
                             port :: inet:port_number(),
                             static_key :: binary(),
                             accept_queue :: queue:queue(accept_entry()),
                             waiting_acceptors :: [gen_server:from()],
                             max_accept_queue :: non_neg_integer()}}.

init/1

-spec init(map()) ->
              {ok,
               #state{dispatch :: nquic_dispatch:t(),
                      opts :: map(),
                      port :: inet:port_number(),
                      static_key :: binary(),
                      accept_queue :: queue:queue(accept_entry()),
                      waiting_acceptors :: [gen_server:from()],
                      max_accept_queue :: non_neg_integer()}} |
              {stop, term()}.

opt(Mgr, Key)

-spec opt(pid(), atom()) -> {ok, term()} | {error, nquic_error:any_reason()}.

Return a single listener option as seen at startup.

start_link(Args)

-spec start_link(#{dispatch := nquic_dispatch:t(), opts := map()}) ->
                    {ok, pid()} | ignore | {error, term()}.

Start the listener manager. Args carries the dispatch handle and resolved opts.

terminate(Reason, State)

-spec terminate(term(),
                #state{dispatch :: nquic_dispatch:t(),
                       opts :: map(),
                       port :: inet:port_number(),
                       static_key :: binary(),
                       accept_queue :: queue:queue(accept_entry()),
                       waiting_acceptors :: [gen_server:from()],
                       max_accept_queue :: non_neg_integer()}) ->
                   ok.