View Source SMPPEX.Session behaviour (smppex v3.2.1)

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

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.

Link to this section Types

@type from() :: SMPPEX.TransportSession.from()
@type reason() :: term()
@type reply() :: term()
@type request() :: term()
@type send_pdu_result() :: SMPPEX.TransportSession.send_pdu_result()
@type session() :: pid()
@type state() :: term()

Link to this section Callbacks

Link to this callback

code_change(old_vsn, state, extra)

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

Link to this callback

handle_call(request, from, state)

View Source
@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 with reply and use state as the new state;
  • {:reply, reply, pdus, state} — reply with reply, use state as the new state and additionally send pdus to the peer;
  • {:noreply, state} — do not reply and use state as the new state. The reply can be send later via Session.reply;
  • {:noreply, pdus, state} — do not reply, use state as the new state and additionally send pdus to the peer. The reply can be send later via Session.reply;
  • {:stop, reason, reply, state} — reply with reply, use state as the new state and exit with reason;
  • {:stop, reason, state} — do not reply, use state as the new state and exit with reason.
Link to this callback

handle_cast(request, state)

View Source
@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} — use state as the new state;
  • {:noreply, pdus, state} — use state as the new state and additionally send pdus to the peer.;
  • {:stop, reason, state} — use state as the new state and exit with reason.
Link to this callback

handle_info(request, state)

View Source
@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} — use state as the new state;
  • {:noreply, pdus, state} — use state as the new state and additionally send pdus to the peer.;
  • {:stop, reason, state} — use state as the new state and exit with reason.
@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} — use state as the new session state;
  • {:ok, pdus, state} — use state as the new session state and additionally send pdus to the connection;
  • {:stop, reason, state} — stop with reason reason and use state as the new session state.
Link to this callback

handle_resp(pdu, original_pdu, state)

View Source
@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} — use state as the new session state;
  • {:ok, pdus, state} — use state as the new session state and additionally send pdus to the connection;
  • {:stop, reason, state} — stop with reason reason and use state as the new session state.
Link to this callback

handle_resp_timeout(pdus, state)

View Source
@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} — use state as the new session state;
  • {:ok, pdus, state} — use state as the new session state and additionally send pdus to the connection;
  • {:stop, reason, state} — stop with reason reason and use state as the new session state.
Link to this callback

handle_send_pdu_result(pdu, send_pdu_result, state)

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

Link to this callback

handle_socket_closed(state)

View Source
@callback handle_socket_closed(state()) :: {exit_reason :: term(), state()}

Invoked when the connection is closed by the peer.

The returned value should be {reason, state}. The session stops then with reason.

Link to this callback

handle_socket_error(error, state)

View Source
@callback handle_socket_error(error :: term(), state()) ::
  {exit_reason :: term(), state()}

Invoked when the connection's socket reported a error.

The returned value should be {reason, state}. The session stops then with reason.

Link to this callback

handle_timeout(stop_reason, state)

View Source
@callback handle_timeout(SMPPEX.SMPPTimers.stop_reason(), state()) ::
  exit_reason :: term()

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}.

Link to this callback

handle_unparsed_pdu(pdu, error, state)

View Source
@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} — use state as the new session state;
  • {:ok, pdus, state} — use state as the new session state and additionally send pdus to the connection;
  • {:stop, reason, state} — stop with reason reason and use state as the new session state.
Link to this callback

init(socket, transport, args)

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

Link to this callback

terminate(reason, lost_pdus, state)

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

Link to this section Functions

Link to this function

call(pid, request, timeout \\ 5000)

View Source
@spec call(session(), request :: term(), timeout()) :: term()

Makes a syncronous call to the session.

The call is handled by handle_call/3 SMPPEX.Session callback.

@spec cast(session(), request :: term()) :: :ok

Makes an asyncronous call to Session.

The call is handled by handle_cast/2 SMPPEX.Session callback.

@spec reply(from(), response :: term()) :: :ok

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.

Link to this function

send_pdu(pid, pdu, timeout \\ 5000)

View Source

Sends a PDU from the session to the peer.

Link to this function

stop(pid, reason \\ :normal)

View Source

Stops the session syncronously.