thrift_runtime_acceptor (thrift_runtime v0.7.0)

View Source

Listens on a port and starts a connection process per client.

Connections are monitored (not linked): a crashing connection touches neither the listener nor its siblings. max_connections caps live connections; while at the cap no new accept is scheduled, and a connection going down resumes accepting, which is the backpressure mechanism.

Summary

Functions

Drains the listener: closes the listen socket, accepts nothing new, and tells every live connection to stop — an idle one exits at once, one with an in-flight request right after it answered. The drain completes when the last connection is gone, or at the Timeout deadline (infinity allowed); the deadline never fails the call: once it passes, whatever is still connected is swept by the supervisor stop that follows. The reply must be deferred (not answered from handle_call) because observing connection exits requires the 'DOWN' messages only a live gen_server loop processes.

Returns the port the listener bound (useful with port = 0).

Starts the listener.

Stops the listener; live connections are not affected.

Types

options()

-type options() ::
          #{handler => module(),
            service => module(),
            services => #{binary() => #{handler := module(), service := module()}},
            transport => thrift_runtime_socket:transport(),
            protocol => binary | compact | module(),
            max_frame_size => pos_integer(),
            max_connections => pos_integer(),
            timeout => pos_integer() | infinity,
            handshake_timeout => pos_integer() | infinity,
            idle_timeout => pos_integer() | infinity,
            active_n => pos_integer(),
            on_event => thrift_runtime_events:handler(),
            record_api => boolean(),
            types => module(),
            backlog => pos_integer(),
            ssl_opts => [ssl:tls_server_option()],
            port := inet:port_number()}.

Functions

drain/2

-spec drain(pid(), timeout()) -> ok.

Drains the listener: closes the listen socket, accepts nothing new, and tells every live connection to stop — an idle one exits at once, one with an in-flight request right after it answered. The drain completes when the last connection is gone, or at the Timeout deadline (infinity allowed); the deadline never fails the call: once it passes, whatever is still connected is swept by the supervisor stop that follows. The reply must be deferred (not answered from handle_call) because observing connection exits requires the 'DOWN' messages only a live gen_server loop processes.

port(Pid)

-spec port(pid()) -> {ok, inet:port_number()}.

Returns the port the listener bound (useful with port = 0).

start_link(Opts)

-spec start_link(options()) -> gen_server:start_ret().

Starts the listener.

init fails (stopping the server) if the port cannot be bound.

stop(Pid)

-spec stop(pid()) -> ok.

Stops the listener; live connections are not affected.