SMPPEX.MC (smppex v3.0.4) View Source
This is a module for launching a TCP listener (or any other listener supported by ranch, for example, ssl) which handles incoming connections with the passed SMPPEX.Session implementations.
To start an MC one generally should do the following.
- Implement an
SMPPEX.Sessionbehaviour.
defmodule MyMCSession do
use SMPPEX.Session
# ...Callback implementation
end
- Start a listener passing implemented behaviour as a callback module.
{:ok, listener} = SMPPEX.MC.start({MyESMESession, some_args},
transport_opts: [port: 2775])The important things to note are:
- There is no
start_linkmethod, since started listener is not a standaloneGenServerbut a pool of socket acceptors running underRanchsupervisor. - Each received connection is served with its own process which uses passed callback module (
MyESMESession) for handling connection events. Each process has his own state initialized byinitcallback receivingsocket,transportand a copy of arguments (some_args).
Link to this section Summary
Link to this section Functions
Specs
start({module(), args :: term()}, opts :: Keyword.t()) ::
{:ok, listener_ref :: :ranch.ref()} | {:error, reason :: term()}
Starts listener for MC entitiy.
module is the callback module which should implement SMPPEX.Session behaviour.
args is the argument passed to the init callback each time a new connection is received.
opts is a keyword list of different options:
:transportis Ranch transport used for TCP connections: eitherranch_tcp(the default) orranch_ssl;:transport_optsis a map of Ranch transport options. The major key issocket_optswhich contains a list of important options such as{:port, port}. The port is set to0by default, which means that the listener will accept connections on a random free port. For backward compatibility one can pass a list of socket options instead oftransport_optsmap (as in Ranch 1.x).:session_moduleis a module to use as an alternative toSMPPEX.Sessionfor handling sessions (if needed). For example,SMPPEX.TelemetrySession.:acceptor_countis the number of Ranch listener acceptors, 50 by default.:mc_optsis a keyword list of MC options::timer_resolutionis interval of internaltickson which time related events happen, like checking timeouts for pdus, checking SMPP timers, etc. The default is 100 ms;:session_init_limitis the maximum time for which a session waits an incoming bind request. If no bind request is received within this interval of time, the session stops. The default value is 10000 ms;:enquire_link_limitis value for enquire_link SMPP timer, i.e. the interval of SMPP session inactivity after which enquire_link PDU is send to "ping" the connetion. The default value is 30000 ms;:enquire_link_resp_limitis the maximum time for which a session waits for enquire_link PDU response. If the response is not received within this interval of time and no activity from the peer occurs, the session is then considered dead and the session stops. The default value is 30000 ms;:inactivity_limitis the maximum time for which a peer is allowed not to send PDUs (which are not response PDUs). If no such PDUs are received within this interval of time, the session stops. The default is :infinity ms;:response_limitis the maximum time to wait for a response for a previously sent PDU. If the response is not received within this interval,handle_resp_timeoutcallback is triggered for the original pdu. If the response is received later, it is discarded. The default value is 60000 ms.:default_call_timeoutis an integer greater than zero which specifies how many milliseconds to wait for a reply, or the atom :infinity to wait indefinitely.If no reply is received within the specified time, the function call fails and the caller exits. The default value is 5000 ms. If:mc_optslist of options is ommited, all options take their default values. The returned value is either{:ok, ref}or{:error, reason}. Therefcan be later used to stop the whole MC listener and all sessions received by it.
Specs
stop(:ranch.ref()) :: :ok
Stops MC listener and all its sessions.