Re: [Patch] To add timeouts to SMPP connections

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Organization Centrium GmbH
Message-ID <[email protected]>
Hi Alex,

sorry for the long delay...

I have another patch here, that I would like to commit if nobody has any 
ojections... Please try it, it works very well on our production systems 
since 6 months or so...

On Monday 18 August 2003 17:29, Alex Judd wrote:
> How about a quick code review and a commit of this?
>
> Not to say that discussing the email list isn't important but ...
>
> :)
>
> Alex
>
> ----- Original Message -----
> From: "Alex Judd" <[email protected]>
> To: "Alex Judd" <[email protected]>; "Aaron Brady"
> <[email protected]>; <[email protected]>
> Sent: Friday, August 15, 2003 2:54 PM
> Subject: [Patch] To add timeouts to SMPP connections
>
> > 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

-- 
Best regards / Mit besten Grüßen aus Düsseldorf

Dipl.-Ing.
Alexander Malysh
___________________________________

Centrium GmbH
Vogelsanger Weg 80
40470 Düsseldorf

Fon: +49 (0211) 74 84 51 80
Fax: +49 (0211) 277 49 109

email: a.malysh at centrium.de
web: http://www.centrium.de
msn: olek2002 at hotmail.com
icq: 98063111
___________________________________________

Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
smpp_connection_timeout.diff (text/x-diff, 4.4 KB)
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.92
diff -a -u -r1.92 cfg.def
--- gwlib/cfg.def	8 Aug 2003 14:24:38 -0000	1.92
+++ gwlib/cfg.def	18 Aug 2003 17:07:31 -0000
@@ -277,6 +277,7 @@
     OCTSTR(notification-addr)
     OCTSTR(msg-id-type)
     OCTSTR(no-dlr)
+    OCTSTR(connection-timeout)
 )
 
 
Index: gw/smsc/smsc_smpp.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_smpp.c,v
retrieving revision 1.46
diff -a -u -r1.46 smsc_smpp.c
--- gw/smsc/smsc_smpp.c	3 Aug 2003 22:36:35 -0000	1.46
+++ gw/smsc/smsc_smpp.c	18 Aug 2003 17:07:35 -0000
@@ -54,6 +54,7 @@
 #define SMPP_DEFAULT_VERSION        0x34
 #define SMPP_DEFAULT_PRIORITY       0
 #define SMPP_THROTTLING_SLEEP_TIME  15
+#define SMPP_DEFAULT_CONNECTION_TIMEOUT  5 * SMPP_ENQUIRE_LINK_INTERVAL
 
 
 /***********************************************************************
@@ -91,6 +92,7 @@
     int smpp_msg_id_type;  /* msg id in C string, hex or decimal */
     int autodetect_addr;
     Octstr *alt_charset;
+    long connection_timeout;
     SMSCConn *conn; 
 } SMPP; 
  
@@ -105,7 +107,7 @@
                          int max_pending_submits, int version, int priority,
                          Octstr *my_number, int smpp_msg_id_type, 
                          int autodetect_addr, Octstr *alt_charset, 
-                         Octstr *service_type) 
+                         Octstr *service_type, long connection_timeout) 
 { 
     SMPP *smpp; 
      
@@ -141,6 +143,7 @@
     smpp->smpp_msg_id_type = smpp_msg_id_type;    
     smpp->autodetect_addr = autodetect_addr;
     smpp->alt_charset = octstr_duplicate(alt_charset);
+    smpp->connection_timeout = connection_timeout;
  
     return smpp; 
 } 
@@ -1149,6 +1152,7 @@
     long len;
     SMPP_PDU *pdu;
     double timeout;
+    time_t last_response;
 
     io_arg = arg;
     smpp = io_arg->smpp;
@@ -1174,6 +1178,7 @@
         pending_submits = -1;
         len = 0;
         smpp->throttling_err_time = 0;
+        last_response = time(NULL);
         for (;conn != NULL;) {
             timeout = last_enquire_sent + smpp->enquire_link_interval
                         - date_universal_now();
@@ -1199,6 +1204,7 @@
             send_enquire_link(smpp, conn, &last_enquire_sent);
 
             while ((ret = read_pdu(smpp, conn, &len, &pdu)) == 1) {
+                last_response = time(NULL);
                 /* Deal with the PDU we just got */
                 dump_pdu("Got PDU:", smpp->conn->id, pdu);
                 handle_pdu(smpp, conn, pdu, &pending_submits);
@@ -1230,6 +1236,14 @@
                 break;
             }
 
+            /* if no PDU was received and connection timeout was set and over the limit */
+            if (ret == 0 && smpp->connection_timeout > 0 &&
+                difftime(time(NULL), last_response) > smpp->connection_timeout) {
+                error(0, "SMPP[%s]: No responses from SMSC within %ld sec. Reconnecting.",
+                         octstr_get_cstr(smpp->conn->id), smpp->connection_timeout);
+                break;
+            }
+
             if (transmitter && difftime(time(NULL), smpp->throttling_err_time) > SMPP_THROTTLING_SLEEP_TIME) {
                 smpp->throttling_err_time = 0;
                 send_messages(smpp, conn, &pending_submits);
@@ -1372,6 +1386,7 @@
     long smpp_msg_id_type;
     int autodetect_addr;
     Octstr *alt_charset;
+    long connection_timeout;
 
     my_number = alt_charset = NULL;
     transceiver_mode = 0;
@@ -1479,6 +1494,10 @@
 
     /* check for an alternative charset */
     alt_charset = cfg_get(grp, octstr_imm("alt-charset"));
+    
+    /* check for connection timeout */
+    if (cfg_get_integer(&connection_timeout, grp, octstr_imm("connection-timeout")) == -1)
+        connection_timeout = SMPP_DEFAULT_CONNECTION_TIMEOUT;
 
     smpp = smpp_create(conn, host, port, receive_port, system_type,  
     	    	       username, password, address_range,
@@ -1486,7 +1505,7 @@
                        dest_addr_npi, enquire_link_interval, 
                        max_pending_submits, version, priority, my_number, 
                        smpp_msg_id_type, autodetect_addr, alt_charset, 
-                       service_type); 
+                       service_type, connection_timeout); 
  
     conn->data = smpp; 
     conn->name = octstr_format("SMPP:%S:%d/%d:%S:%S",
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.