[Patch] To add timeouts to SMPP connections

"Alex Judd" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
I've reworked Aaron's patch to be a bit more Kannel standard and allowed for
definition of enquire-link-retry externally to the code and a standard value
of 10 per suggestions.

It's working for me here but would be good for one of the team to once over.

Alex
Skywire

----- Original Message -----
From: "Alex Judd" <[email protected]>
To: "Aaron Brady" <[email protected]>; <[email protected]>
Sent: Friday, August 08, 2003 10:43 AM
Subject: Re: Patch: To add timeouts to SMPP connections


> Aaron
>
> Seeing as I picked this up in the first place, how about I rework your
patch
> to be a bit more flexible and submit it back for testing.
>
> This way we get the best of both worlds?
>
> Alex
>
> ----- Original Message -----
> From: "Aaron Brady" <[email protected]>
> To: <[email protected]>
> Sent: Friday, August 08, 2003 10:25 AM
> Subject: Re: Patch: To add timeouts to SMPP connections
>
>
> > > Looks good, however I'd potentially make it more configurable so that
> the
> > X
> > > x wait is one of the default settings and can be configured should it
> need
> > > be.
> >
> > If it's easy enough, then I don't see why not, but I'm not altogether
> > familiar with the internals of Kannel, so other than using your below
code
> > as a starting point, I wouldn't know what to do. Personally, I think
that
> > given enquire_link_interval is configurable that adds enough
flexability -
> > this is similar to how IRC servers do things, with a configurable
> ping-time,
> > but if you miss two then you're disconnected, but if people think it
needs
> > the extra option then I can try and add it.
> >
> > > For example
> > >
> > >
> > >     if (cfg_get_integer(&enquire_link_interval, grp,
> > >                      octstr_imm("enquire-link-retry")) == -1)
> > >         enquire_link_interval = SMPP_ENQUIRE_LINK_RETRY;
> > >
> > > <other bits of code needed to map the parameter to the smpp structure>
> > >
> > >            if(date_universal_now() - smpp->last_enquire_received
> > >               > (smpp->enquire_link_retry *
> smpp->enquire_link_interval))
> > {
> > >
> > > etc.
> > >
> > > Also - would it make sense to send an extra send_enquire_link to make
> sure
> > > that the other end is not contacting?
> >
> > I think that if the connection has gotten so far as to miss three pings,
> > it's not likely to recover, and manually sending another enquire_link
> would
> > complicate the code needlessly, but again, I'm sure there are people
more
> > knowledgable about this than me and if they think different, then I can
> try
> > and implement it.
> >
> > Aaron
> >
>
enquire_link_retry.diff (application/octet-stream, 3.9 KB)
[root@pigwidgeon smsc]# diff -u smsc_smpp.c.orig smsc_smpp.c
--- smsc_smpp.c.orig    Fri Aug 15 12:30:38 2003
+++ smsc_smpp.c Fri Aug 15 13:16:20 2003
@@ -50,6 +50,7 @@
  */

 #define SMPP_ENQUIRE_LINK_INTERVAL  30.0
+#define SMPP_ENQUIRE_LINK_RETRY     10
 #define SMPP_MAX_PENDING_SUBMITS    10
 #define SMPP_DEFAULT_VERSION        0x34
 #define SMPP_DEFAULT_PRIORITY       0
@@ -84,6 +85,8 @@
     int receive_port;
     int quitting;
     long enquire_link_interval;
+    long enquire_link_retry;
+    long last_enquire_received;
     long max_pending_submits;
     int version;
     int priority;       /* set default priority for messages */
@@ -101,7 +104,7 @@
                         Octstr *address_range,
                          int source_addr_ton, int source_addr_npi,
                          int dest_addr_ton, int dest_addr_npi,
-                         int enquire_link_interval,
+                         int enquire_link_interval, int enquire_link_retry, int last_enquire_received,
                          int max_pending_submits, int version, int priority,
                          Octstr *my_number, int smpp_msg_id_type,
                          int autodetect_addr, Octstr *alt_charset,
@@ -132,6 +135,8 @@
     smpp->transmit_port = transmit_port;
     smpp->receive_port = receive_port;
     smpp->enquire_link_interval = enquire_link_interval;
+    smpp->enquire_link_retry = enquire_link_retry;
+    smpp->last_enquire_received = 0;
     smpp->max_pending_submits = max_pending_submits;
     smpp->quitting = 0;
     smpp->version = version;
@@ -931,6 +936,7 @@
             break;

         case enquire_link_resp:
+            smpp->last_enquire_received = date_universal_now();
             break;

         case submit_sm_resp:
@@ -1171,12 +1177,19 @@
             conn = open_receiver(smpp);

         last_enquire_sent = date_universal_now();
+        smpp->last_enquire_received = date_universal_now();
         pending_submits = -1;
         len = 0;
         smpp->throttling_err_time = 0;
         for (;conn != NULL;) {
             timeout = last_enquire_sent + smpp->enquire_link_interval
                         - date_universal_now();
+            if(date_universal_now() - smpp->last_enquire_received
+                            > (smpp->enquire_link_retry * smpp->enquire_link_interval)) {
+                    debug("bb.sms.smpp", 0, "SMSC Timeout");
+                    smpp->conn->status = SMSCCONN_RECONNECTING;
+                    break;
+            }

             /* unbind
              * TODO: read so long as unbind_resp received. Otherwise we have
@@ -1366,6 +1379,8 @@
     int transceiver_mode;
     Octstr *smsc_id;
     long enquire_link_interval;
+    long enquire_link_retry;
+    long last_enquire_received;
     long max_pending_submits;
     long version;
     long priority;
@@ -1408,6 +1423,9 @@
     if (cfg_get_integer(&enquire_link_interval, grp,
                         octstr_imm("enquire-link-interval")) == -1)
         enquire_link_interval = SMPP_ENQUIRE_LINK_INTERVAL;
+    if (cfg_get_integer(&enquire_link_retry, grp,
+                        octstr_imm("enquire-link-retry")) == -1)
+        enquire_link_retry = SMPP_ENQUIRE_LINK_RETRY;
     if (cfg_get_integer(&max_pending_submits, grp,
                         octstr_imm("max-pending-submits")) == -1)
         max_pending_submits = SMPP_MAX_PENDING_SUBMITS;
@@ -1483,7 +1501,7 @@
     smpp = smpp_create(conn, host, port, receive_port, system_type,
                       username, password, address_range,
                        source_addr_ton, source_addr_npi, dest_addr_ton,
-                       dest_addr_npi, enquire_link_interval,
+                       dest_addr_npi, enquire_link_interval, enquire_link_retry, last_enquire_received,
                        max_pending_submits, version, priority, my_number,
                        smpp_msg_id_type, autodetect_addr, alt_charset,
                        service_type);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.