View Source Soyaki.Handler behaviour (soyaki v1.0.1)
Link to this section Summary
Types
{:continue, state :: term()}
subscribes with the socket's read_timeout, which defaults at 5000ms.{:continue, state :: term(), timeout()}
subscribes with given timeout.{:close, state}
callshandle_close/2
.{:error, err, state}
callshandle_error/3
. Timeouts callbackhandle_timeout/2
Callbacks
Called when shutting down the genserver with a reason, usually :local_closed
from returning a {:close, state}
continuation. Automatically closes the socket.
Accepts a connection. Doesn't grab the first packet, returns handler_result
Called when shut down for any other reason. Automatically closes the socket.
Called after the connection was accepted, returns handler_result
Called when straight up shutting down a genserver (:shutdown
) in terminate callback.
Doesn't automatically close the socket.
Called when terminating due to :timeout
. Automatically closes the socket.
Called during init
, returns state.
Link to this section Types
@type handler_result() :: {:continue, state :: term()} | {:continue, state :: term(), timeout()} | {:close, state :: term()} | {:error, term(), state :: term()}
{:continue, state :: term()}
subscribes with the socket's read_timeout, which defaults at 5000ms.{:continue, state :: term(), timeout()}
subscribes with given timeout.{:close, state}
callshandle_close/2
.{:error, err, state}
callshandle_error/3
. Timeouts callbackhandle_timeout/2
Link to this section Callbacks
@callback handle_close(socket :: Soyaki.Socket.t(), state :: term()) :: term()
Called when shutting down the genserver with a reason, usually :local_closed
from returning a {:close, state}
continuation. Automatically closes the socket.
@callback handle_connection(socket :: Soyaki.Socket.t(), state :: term()) :: handler_result()
Accepts a connection. Doesn't grab the first packet, returns handler_result
@callback handle_error(error :: atom(), socket :: Soyaki.Socket.t(), state :: term()) :: term()
Called when shut down for any other reason. Automatically closes the socket.
@callback handle_packet(packet :: binary(), socket :: Soyaki.Socket.t(), state :: term()) :: handler_result()
Called after the connection was accepted, returns handler_result
@callback handle_shutdown(socket :: Soyaki.Socket.t(), state :: term()) :: term()
Called when straight up shutting down a genserver (:shutdown
) in terminate callback.
Doesn't automatically close the socket.
@callback handle_timeout(socket :: Soyaki.Socket.t(), state :: term()) :: term()
Called when terminating due to :timeout
. Automatically closes the socket.
@callback init_state(socket :: Soyaki.Socket.t(), handler_init :: term()) :: state :: term()
Called during init
, returns state.