View Source ElvenGard.Network.Endpoint.Protocol behaviour (ElvenGard.Network v0.1.1)
Wrapper on top of Ranch protocols.
This module defines a protocol behavior to handle incoming connections in the ElvenGard.Network library. It provides callbacks for initializing, handling incoming messages, and handling connection termination.
This protocol behavior serves as a wrapper around Ranch protocols, providing a structured way to implement connection handling within ElvenGard.Network.
For detailed information on implementing and using network protocols with ElvenGard.Network, please refer to the Endpoint Protocol guide.
Link to this section Summary
Callbacks
Callback called after the socket connection is closed and before the GenServer shutdown.
Callback called just before entering the GenServer loop.
Callback called just after receiving a message.
Link to this section Callbacks
@callback handle_halt(reason :: term(), socket :: ElvenGard.Network.Socket.t()) :: {:ok, new_socket} | {:ok, stop_reason :: term(), new_socket} when new_socket: term()
Callback called after the socket connection is closed and before the GenServer shutdown.
@callback handle_init(socket :: ElvenGard.Network.Socket.t()) :: {:ok, new_socket} | {:ok, new_socket, timeout() | :hibernate | {:continue, continue_arg}} | {:stop, reason :: term(), new_socket} when new_socket: ElvenGard.Network.Socket.t(), continue_arg: term()
Callback called just before entering the GenServer loop.
This callback is invoked when a new connection is established and before the GenServer loop starts processing messages.
For the return values, see GenServer.init/1
@callback handle_message(message :: binary(), socket :: ElvenGard.Network.Socket.t()) :: :ignore | {:ignore, new_socket} | {:ok, new_socket} | {:stop, reason :: term(), new_socket} when new_socket: ElvenGard.Network.Socket.t()
Callback called just after receiving a message.
This callback is invoked whenever a message is received on the connection. It should return one of the following:
:ignore
: the message received will not be decoded or processed by the protocol. It will just be ignored{:ignore, new_socket}
: same as:ignore
but also modifies the socket{:ok, new_socket}
: classic loop - decode the packet and process it{:stop, reason, new_socket}
: stop the GenServer/Protocol and disconnect the client