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} calls handle_close/2.
  • {:error, err, state} calls handle_error/3. Timeouts callback handle_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} calls handle_close/2.
  • {:error, err, state} calls handle_error/3. Timeouts callback handle_timeout/2

Link to this section Callbacks

Link to this callback

handle_close(socket, state)

View Source
@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.

Link to this callback

handle_connection(socket, state)

View Source
@callback handle_connection(socket :: Soyaki.Socket.t(), state :: term()) ::
  handler_result()

Accepts a connection. Doesn't grab the first packet, returns handler_result

Link to this callback

handle_error(error, socket, state)

View Source
@callback handle_error(error :: atom(), socket :: Soyaki.Socket.t(), state :: term()) ::
  term()

Called when shut down for any other reason. Automatically closes the socket.

Link to this callback

handle_packet(packet, socket, state)

View Source
@callback handle_packet(packet :: binary(), socket :: Soyaki.Socket.t(), state :: term()) ::
  handler_result()

Called after the connection was accepted, returns handler_result

Link to this callback

handle_shutdown(socket, state)

View Source
@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.

Link to this callback

handle_timeout(socket, state)

View Source
@callback handle_timeout(socket :: Soyaki.Socket.t(), state :: term()) :: term()

Called when terminating due to :timeout. Automatically closes the socket.

Link to this callback

init_state(socket, handler_init)

View Source
@callback init_state(socket :: Soyaki.Socket.t(), handler_init :: term()) ::
  state :: term()

Called during init, returns state.