WebsockexNova.Gun.ConnectionWrapper.MessageHandlers (WebsockexNova v0.1.1)
View SourceHandles Gun message processing for the ConnectionWrapper.
This module provides a set of functions for handling different types of Gun messages, organized by category (connection lifecycle, WebSocket, HTTP, error messages). Each handler receives the relevant parameters and the current state, and returns an updated state.
Summary
Functions
Handles the :gun_down
message when a connection is lost.
Handles the :gun_up
message when a connection is established.
Handles the :gun_error
message when an error occurs.
Handles the :gun_data
message when HTTP data is received.
Handles the :gun_response
message when an HTTP response is received.
Handles the :gun_ws
message when a WebSocket frame is received.
Handles the :gun_upgrade
message when a WebSocket upgrade succeeds.
Notifies a callback process of an event.
Functions
@spec handle_connection_down( pid(), atom(), term(), WebsockexNova.Gun.ConnectionState.t(), [reference()] | nil, [reference()] | nil ) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()} | {:noreply, {:reconnect, WebsockexNova.Gun.ConnectionState.t()}} | {:stop, term(), WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_down
message when a connection is lost.
Parameters
gun_pid
- The Gun connection PIDprotocol
- The protocol that was in usereason
- Reason for the connection lossstate
- Current connection statekilled_streams
- List of stream references that were killedunprocessed_streams
- List of stream references with unprocessed data
Returns
{:noreply, updated_state}
- Standard response{:noreply, {:reconnect, updated_state}}
- Request reconnection{:stop, reason, updated_state}
- Request process termination
@spec handle_connection_up(pid(), atom(), WebsockexNova.Gun.ConnectionState.t()) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_up
message when a connection is established.
Parameters
gun_pid
- The Gun connection PIDprotocol
- The protocol that was negotiatedstate
- Current connection state
Returns
{:noreply, updated_state}
@spec handle_error( pid(), reference() | nil, term(), WebsockexNova.Gun.ConnectionState.t() ) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_error
message when an error occurs.
Parameters
gun_pid
- The Gun connection PIDstream_ref
- Reference to the stream with the error, or nilreason
- The error reasonstate
- Current connection state
Returns
{:noreply, updated_state}
@spec handle_http_data( pid(), reference(), atom(), binary(), WebsockexNova.Gun.ConnectionState.t() ) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_data
message when HTTP data is received.
Parameters
gun_pid
- The Gun connection PIDstream_ref
- Reference to the streamis_fin
- Whether this is the final messagedata
- The response datastate
- Current connection state
Returns
{:noreply, updated_state}
@spec handle_http_response( pid(), reference(), atom(), integer(), list(), WebsockexNova.Gun.ConnectionState.t() ) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_response
message when an HTTP response is received.
Parameters
gun_pid
- The Gun connection PIDstream_ref
- Reference to the streamis_fin
- Whether this is the final messagestatus
- HTTP status codeheaders
- HTTP response headersstate
- Current connection state
Returns
{:noreply, updated_state}
@spec handle_websocket_frame( pid(), reference(), tuple() | atom(), WebsockexNova.Gun.ConnectionState.t() ) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_ws
message when a WebSocket frame is received.
Parameters
gun_pid
- The Gun connection PIDstream_ref
- Reference to the stream that received the frameframe
- The WebSocket framestate
- Current connection state
Returns
{:noreply, updated_state}
@spec handle_websocket_upgrade( pid(), reference(), list(), WebsockexNova.Gun.ConnectionState.t() ) :: {:noreply, WebsockexNova.Gun.ConnectionState.t()}
Handles the :gun_upgrade
message when a WebSocket upgrade succeeds.
Parameters
gun_pid
- The Gun connection PIDstream_ref
- Reference to the stream that was upgradedheaders
- Response headers from the upgradestate
- Current connection state
Returns
{:noreply, updated_state}
Notifies a callback process of an event.
Parameters
callback_pid
- PID of the process to notify (or nil)message
- Message to send
Returns
:ok