smppex v2.2.1 SMPPEX.Session behaviour View Source
Module for implementing custom SMPP Session entities.
To implement an Session entitiy, one should implement several callbacks (SMPPEX.Session behaviour).
The most proper way to do it is to use SMPPEX.Session:
defmodule MySession do
use SMPPEX.Session
# ...Callback implementation
end
In this case all callbacks have reasonable defaults.
Link to this section Summary
Functions
Makes a syncronous call to the session
Makes an asyncronous call to Session
Callback implementation for c:SMPPEX.TransportSession.code_change/3
Callback implementation for c:SMPPEX.TransportSession.handle_call/3
Callback implementation for c:SMPPEX.TransportSession.handle_cast/2
Callback implementation for c:SMPPEX.TransportSession.handle_pdu/2
Callback implementation for c:SMPPEX.TransportSession.handle_send_pdu_result/3
Callback implementation for c:SMPPEX.TransportSession.handle_socket_closed/1
Callback implementation for c:SMPPEX.TransportSession.handle_socket_error/2
Callback implementation for c:SMPPEX.TransportSession.init/3
Replies to a client calling Session.call method
Sends a PDU from the session to the peer
Stops the session syncronously
Callback implementation for c:SMPPEX.TransportSession.terminate/2
Callbacks
Invoked to change the state of the session when a different version of a module is loaded (hot code swapping) and the state’s term structure should be changed. The method has the same semantics as the original GenServer.code_change/3 callback
Invoked to handle an arbitrary syncronous request sent to the session with Session.call/3 method
Invoked to handle an arbitrary asyncronous request sent to the session with Session.cast/2 method
Invoked to handle a generic message request sent to the session process
Invoked when the session receives an incoming PDU (which is not a response PDU)
Invoked when the session receives a response to a previously sent PDU
Invoked when the session does not receive a response to a previously sent PDU within the specified timeout
Invoked when the SMPP session successfully sent PDU to transport or failed to do this
Invoked when the connection is closed by the peer
Invoked when the connection’s socket reported a error
Invoked when the session receives an incoming PDU which couldn’t be correctly parsed
Invoked when a session is started after a connection successfully established
Invoked when the session process is about to exit
Link to this section Types
send_pdu_result() :: SMPPEX.TransportSession.send_pdu_result
Link to this section Functions
call(session, request :: term, timeout) :: term
Makes a syncronous call to the session.
The call is handled by handle_call/3 SMPPEX.Session callback.
Makes an asyncronous call to Session.
The call is handled by handle_cast/2 SMPPEX.Session callback.
Callback implementation for c:SMPPEX.TransportSession.code_change/3.
Callback implementation for c:SMPPEX.TransportSession.handle_call/3.
Callback implementation for c:SMPPEX.TransportSession.handle_cast/2.
Callback implementation for c:SMPPEX.TransportSession.handle_pdu/2.
Callback implementation for c:SMPPEX.TransportSession.handle_send_pdu_result/3.
Callback implementation for c:SMPPEX.TransportSession.handle_socket_closed/1.
Callback implementation for c:SMPPEX.TransportSession.handle_socket_error/2.
Callback implementation for c:SMPPEX.TransportSession.init/3.
Replies to a client calling Session.call method.
This function can be used to explicitly send a reply to a client that called call/3.
from must be the from argument (the second argument) accepted by handle_call/3 callbacks.
The return value is always :ok.
Sends a PDU from the session to the peer.
Stops the session syncronously.
Callback implementation for c:SMPPEX.TransportSession.terminate/2.
Link to this section Callbacks
Invoked to change the state of the session when a different version of a module is loaded (hot code swapping) and the state’s term structure should be changed. The method has the same semantics as the original GenServer.code_change/3 callback.
Invoked to handle an arbitrary syncronous request sent to the session with Session.call/3 method.
from argument can be used to send a response asyncronously via Session.reply/2.
The returned values indicate the following:
{:reply, reply, state}— reply withreplyand usestateas the new state;{:reply, reply, pdus, state}— reply withreply, usestateas the new state and additionally sendpdusto the peer;{:noreply, state}— do not reply and usestateas the new state. The reply can be send later viaSession.reply;{:noreply, pdus, state}— do not reply, usestateas the new state and additionally sendpdusto the peer. The reply can be send later viaSession.reply;{:stop, reason, reply, state}— reply withreply, usestateas the new state and exit withreason;{:stop, reason, state}— do not reply, usestateas the new state and exit withreason.
Invoked to handle an arbitrary asyncronous request sent to the session with Session.cast/2 method.
The returned values indicate the following:
{:noreply, state}— usestateas the new state;{:noreply, pdus, state}— usestateas the new state and additionally sendpdusto the peer.;{:stop, reason, state}— usestateas the new state and exit withreason.
Invoked to handle a generic message request sent to the session process.
The returned values indicate the following:
{:noreply, state}— usestateas the new state;{:noreply, pdus, state}— usestateas the new state and additionally sendpdusto the peer.;{:stop, reason, state}— usestateas the new state and exit withreason.
handle_pdu(pdu :: SMPPEX.Pdu.t, state) :: {:ok, state} | {:ok, [SMPPEX.Pdu.t], state} | {:stop, reason, state}
Invoked when the session receives an incoming PDU (which is not a response PDU).
The callback return values indicate the following:
{:ok, state}— usestateas the new session state;{:ok, pdus, state}— usestateas the new session state and additionally sendpdusto the connection;{:stop, reason, state}— stop with reasonreasonand usestateas the new session state.
handle_resp(pdu :: SMPPEX.Pdu.t, original_pdu :: SMPPEX.Pdu.t, state) :: {:ok, state} | {:ok, [SMPPEX.Pdu.t], state} | {:stop, reason, state}
Invoked when the session receives a response to a previously sent PDU.
pdu argument contains the received response PDU, original_pdu contains
the previously sent pdu for which the handled response is received.
The callback return values indicate the following:
{:ok, state}— usestateas the new session state;{:ok, pdus, state}— usestateas the new session state and additionally sendpdusto the connection;{:stop, reason, state}— stop with reasonreasonand usestateas the new session state.
handle_resp_timeout(pdus :: [SMPPEX.Pdu.t], state) :: {:ok, state} | {:ok, [SMPPEX.Pdu.t], state} | {:stop, reason, state}
Invoked when the session does not receive a response to a previously sent PDU within the specified timeout.
pdu argument contains the PDU for which no response was received. If the response
will be received later it will be dropped (with an info log message).
The callback return values indicate the following:
{:ok, state}— usestateas the new session state;{:ok, pdus, state}— usestateas the new session state and additionally sendpdusto the connection;{:stop, reason, state}— stop with reasonreasonand usestateas the new session state.
handle_send_pdu_result(pdu :: SMPPEX.Pdu.t, send_pdu_result, state) :: state
Invoked when the SMPP session successfully sent PDU to transport or failed to do this.
pdu argument contains the PDU for which send status is reported. send_pdu_result can be
either :ok or {:error, reason}.
The returned value is used as the new state.
Invoked when the connection is closed by the peer.
The returned value should be {reason, state}. The session stops then with reason.
Invoked when the connection’s socket reported a error.
The returned value should be {reason, state}. The session stops then with reason.
Invoked when the session receives an incoming PDU which couldn’t be correctly parsed.
The callback return values indicate the following:
{:ok, state}— usestateas the new session state;{:ok, pdus, state}— usestateas the new session state and additionally sendpdusto the connection;{:stop, reason, state}— stop with reasonreasonand usestateas the new session state.
Invoked when a session is started after a connection successfully established.
args argument is taken directly from ESME.start_link or MC.start call.
The return value should be either {:ok, state}, then the session will successfully start and the returned state will be later passed to the other callbacks, or {:stop, reason}, then the session will stop with the returned reason.
terminate(reason, lost_pdus :: [SMPPEX.Pdu.t], state) :: :stop | {:stop, [SMPPEX.Pdu.t], state}
Invoked when the session process is about to exit.
lost_pdus contain a list of nonresp pdus sent by the session to the peer and which have not yet received a response.
The returned value is ignored.
This callback is called from the underlying GenServer terminate callbacks, so it has all the corresponding caveats, see GenServer.terminate/2 docs.