quic_listener (quic v1.3.0)
View SourceQUIC server listener for accepting connections.
This module handles: - UDP socket management - Initial packet routing to connections - Connection ID management - Stateless retry (optional)
Connection Handler Callback
The connection_handler option allows custom handling of new connections:
Opts = #{
cert => Cert,
key => Key,
connection_handler => fun(Conn) ->
%% Conn is the connection pid
%% Spawn your handler and return its pid
HandlerPid = spawn(fun() -> my_handler(Conn) end),
%% Ownership will be transferred to HandlerPid
{ok, HandlerPid}
end
}
Summary
Functions
Get list of active connections.
Get the port the listener is bound to.
false
false
false Handle incoming UDP packets (gen_udp backend)
false
Start a QUIC listener (without linking to caller).
Start a QUIC listener on the given port. Options: - cert: Server certificate (DER binary) - cert_chain: Certificate chain [binary()] - key: Private key - alpn: List of supported ALPN protocols - active_n: Number of packets before socket goes passive (default 100) - reuseport: Enable SO_REUSEPORT for multiple listeners (default false) - connections_table: Shared ETS table for connection tracking (pool mode) - preferred_ipv4: {IP, Port} for preferred IPv4 address (RFC 9000 Section 9.6) - preferred_ipv6: {IP, Port} for preferred IPv6 address (RFC 9000 Section 9.6)
Stop the listener.
Types
-type state() :: #listener_state{socket :: gen_udp:socket() | socket:socket(), socket_state :: quic_socket:socket_state() | undefined, socket_backend :: gen_udp | socket, gro_receiver :: pid() | undefined, port :: inet:port_number(), cert :: binary(), cert_chain :: [binary()], private_key :: term(), alpn_list :: [binary()], connections :: ets:tid(), tickets_table :: ets:tid(), owns_tables :: boolean(), reset_secret :: binary(), address_validation :: never | always, token_max_age_ms :: non_neg_integer(), connection_handler :: fun((pid()) -> {ok, pid()} | {error, term()}) | fun((pid(), binary()) -> {ok, pid()} | {error, term()}) | undefined, cid_config :: #cid_config{lb_config :: #lb_config{config_rotation :: 0..6, algorithm :: plaintext | stream_cipher | block_cipher, server_id :: binary(), server_id_len :: 1..15, nonce_len :: 4..18, key :: binary() | undefined} | undefined, cid_len :: 1..20, reset_secret :: binary() | undefined} | undefined, dcid_len :: pos_integer(), opts :: map()}.
Functions
false
Get list of active connections.
-spec get_port(pid()) -> inet:port_number().
Get the port the listener is bound to.
-spec handle_call(term(), gen_server:from(), state()) -> {reply, term(), state()}.
false
false
false
false Handle incoming UDP packets (gen_udp backend)
-spec init({inet:port_number(), map()}) -> term().
false
-spec start(inet:port_number(), map()) -> {ok, pid()} | {error, term()}.
Start a QUIC listener (without linking to caller).
-spec start_link(inet:port_number(), map()) -> {ok, pid()} | {error, term()}.
Start a QUIC listener on the given port. Options: - cert: Server certificate (DER binary) - cert_chain: Certificate chain [binary()] - key: Private key - alpn: List of supported ALPN protocols - active_n: Number of packets before socket goes passive (default 100) - reuseport: Enable SO_REUSEPORT for multiple listeners (default false) - connections_table: Shared ETS table for connection tracking (pool mode) - preferred_ipv4: {IP, Port} for preferred IPv4 address (RFC 9000 Section 9.6) - preferred_ipv6: {IP, Port} for preferred IPv6 address (RFC 9000 Section 9.6)
-spec stop(pid()) -> ok.
Stop the listener.
false