Hi List,

attached patch should fix a shutdown sequence for smpp driver. The problem is 
that smpp module should read as long no unbind_resp received otherwise we 
will missing #max-pending-submits ack's from smsc.

smpp_properly_shutdown.diff:
smsc/smsc_smpp.c |   22 +++++++++++++++-------
smscconn.c       |   14 +++++++++++---
2 files changed, 26 insertions(+), 10 deletions(-)

Comments and votes please...

-- 
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: 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
Index: gw/smscconn.c
===================================================================
RCS file: /home/cvs/gateway/gw/smscconn.c,v
retrieving revision 1.40
diff -a -u -r1.40 smscconn.c
--- gw/smscconn.c	27 Jul 2003 14:45:28 -0000	1.40
+++ gw/smscconn.c	2 Sep 2003 15:01:05 -0000
@@ -207,11 +207,19 @@
     }
 
     /* Call SMSC specific destroyer */
-    if (conn->shutdown)
+    if (conn->shutdown) {
+        /* 
+         * we must unlock here, because module manipulate their state
+         * and will try to lock this mutex.Otherwise we have deadlock!
+         */
+        mutex_unlock(conn->flow_mutex);
 	conn->shutdown(conn, finish_sending);
-    else
+    }
+    else {
 	conn->why_killed = SMSCCONN_KILLED_SHUTDOWN;
-    mutex_unlock(conn->flow_mutex);
+        mutex_unlock(conn->flow_mutex);
+    }
+
     return;
 }
 
Index: gw/smsc/smsc_smpp.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc/smsc_smpp.c,v
retrieving revision 1.49
diff -a -u -r1.49 smsc_smpp.c
--- gw/smsc/smsc_smpp.c	2 Sep 2003 11:30:30 -0000	1.49
+++ gw/smsc/smsc_smpp.c	2 Sep 2003 15:01:05 -0000
@@ -56,6 +56,7 @@
 #define SMPP_THROTTLING_SLEEP_TIME  15
 #define SMPP_DEFAULT_CONNECTION_TIMEOUT  10 * SMPP_ENQUIRE_LINK_INTERVAL
 #define SMPP_DEFAULT_WAITACK        60
+#define SMPP_DEFAULT_SHUTDOWN_TIMEOUT 30
 
 
 /* 
@@ -1309,23 +1310,30 @@
             timeout = last_enquire_sent + smpp->enquire_link_interval
                         - date_universal_now();
 
+            if (conn_wait(conn, timeout) == -1)
+                break;
+
             /* unbind
-             * TODO: read so long as unbind_resp received. Otherwise we have
+             * Read so long as unbind_resp received or timeout passed. Otherwise we have
              * double delivered messages.
              */
             if (smpp->quitting) {
                 send_unbind(smpp, conn);
-                while ((ret = read_pdu(smpp, conn, &len, &pdu)) == 1) {
-                    dump_pdu("Got PDU:", smpp->conn->id, pdu);
-                    handle_pdu(smpp, conn, pdu, &pending_submits);
-                    smpp_pdu_destroy(pdu);
+                last_response = time(NULL);
+                while(conn_wait(conn, 1.00) != -1 &&
+                      difftime(time(NULL), last_response) < SMPP_DEFAULT_SHUTDOWN_TIMEOUT &&
+                      smpp->conn->status != SMSCCONN_DISCONNECTED) {
+                    if (read_pdu(smpp, conn, &len, &pdu) == 1) {
+                        dump_pdu("Got PDU:", smpp->conn->id, pdu);
+                        handle_pdu(smpp, conn, pdu, &pending_submits);
+                        smpp_pdu_destroy(pdu);
+                    }
                 }
                 debug("bb.sms.smpp", 0, "SMPP[%s]: %s: break and shutting down",
                       octstr_get_cstr(smpp->conn->id), __PRETTY_FUNCTION__);
-            }
 
-            if (smpp->quitting || conn_wait(conn, timeout) == -1)
                 break;
+            }
 
             send_enquire_link(smpp, conn, &last_enquire_sent);
 

Reply via email to