View Source SMPPEX.Session behaviour (smppex v3.2.3)
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.
Summary
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 is about to be stopped due to a timeout.
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.
Functions
Makes a syncronous call to the session.
Makes an asyncronous call to Session.
Replies to a client calling Session.call
method.
Sends a PDU from the session to the peer.
Stops the session syncronously.
Types
Callbacks
@callback code_change(old_vsn :: term() | {:down, term()}, state(), extra :: term()) :: {:ok, state()} | {:error, reason()}
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.
@callback handle_call(request(), from(), state()) :: {:reply, reply(), state()} | {:reply, reply(), [SMPPEX.Pdu.t()], state()} | {:noreply, state()} | {:noreply, [SMPPEX.Pdu.t()], state()} | {:stop, reason(), reply(), state()} | {:stop, reason(), state()}
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 withreply
and usestate
as the new state;{:reply, reply, pdus, state}
— reply withreply
, usestate
as the new state and additionally sendpdus
to the peer;{:noreply, state}
— do not reply and usestate
as the new state. The reply can be send later viaSession.reply
;{:noreply, pdus, state}
— do not reply, usestate
as the new state and additionally sendpdus
to the peer. The reply can be send later viaSession.reply
;{:stop, reason, reply, state}
— reply withreply
, usestate
as the new state and exit withreason
;{:stop, reason, state}
— do not reply, usestate
as the new state and exit withreason
.
@callback handle_cast(request(), state()) :: {:noreply, state()} | {:noreply, [SMPPEX.Pdu.t()], state()} | {:stop, reason(), state()}
Invoked to handle an arbitrary asyncronous request
sent to the session with Session.cast/2
method.
The returned values indicate the following:
{:noreply, state}
— usestate
as the new state;{:noreply, pdus, state}
— usestate
as the new state and additionally sendpdus
to the peer.;{:stop, reason, state}
— usestate
as the new state and exit withreason
.
@callback handle_info(request(), state()) :: {:noreply, state()} | {:noreply, [SMPPEX.Pdu.t()], state()} | {:stop, reason(), state()}
Invoked to handle a generic message request
sent to the session process.
The returned values indicate the following:
{:noreply, state}
— usestate
as the new state;{:noreply, pdus, state}
— usestate
as the new state and additionally sendpdus
to the peer.;{:stop, reason, state}
— usestate
as the new state and exit withreason
.
@callback 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}
— usestate
as the new session state;{:ok, pdus, state}
— usestate
as the new session state and additionally sendpdus
to the connection;{:stop, reason, state}
— stop with reasonreason
and usestate
as the new session state.
@callback 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}
— usestate
as the new session state;{:ok, pdus, state}
— usestate
as the new session state and additionally sendpdus
to the connection;{:stop, reason, state}
— stop with reasonreason
and usestate
as the new session state.
@callback 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}
— usestate
as the new session state;{:ok, pdus, state}
— usestate
as the new session state and additionally sendpdus
to the connection;{:stop, reason, state}
— stop with reasonreason
and usestate
as the new session state.
@callback 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 is about to be stopped due to a timeout.
The return value will be used as the exit reason of the session process. The default implementation returns {:timers, reason}
.
@callback handle_unparsed_pdu(pdu :: SMPPEX.RawPdu.t(), error :: term(), state()) :: {:ok, state()} | {:ok, [SMPPEX.Pdu.t()], state()} | {:stop, reason(), state()}
Invoked when the session receives an incoming PDU which couldn't be correctly parsed.
The callback return values indicate the following:
{:ok, state}
— usestate
as the new session state;{:ok, pdus, state}
— usestate
as the new session state and additionally sendpdus
to the connection;{:stop, reason, state}
— stop with reasonreason
and usestate
as the new session state.
@callback init( socket :: SMPPEX.TransportSession.socket(), transport :: SMPPEX.TransportSession.transport(), args :: term() ) :: {:ok, state()} | {:stop, reason()}
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.
@callback 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 either :stop
or {:stop, last_pdus, state}
, where last_pdus
is a list of PDUs which will be sent to the peer before socket close, and state
is the new state. For example, an ESME can send an unbind PDU or an MC can send negative resps for pending submit_sm
s if needed.
This callback is called from the underlying GenServer
terminate
callbacks, so it has all the corresponding caveats, for example, sometimes it may not be called, see GenServer.terminate/2
docs.
Functions
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.
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.