--- bb_smscconn.c.orig	2006-06-20 18:36:48.000000000 -0600
+++ bb_smscconn.c	2006-06-20 19:14:30.000000000 -0600
@@ -171,15 +171,20 @@
     struct split_parts *split = msg->sms.split_parts;
     
     /*
-     * If temporarely failed, try again immediately but only if connection active.
+     * If temporarely failed, try again if max retry is not reached (only if connection active).
      * Because if connection is not active we will loop for ever here consuming 100% CPU
      * time due to internal queue cleanup in smsc module that call bb_smscconn_failed.
      */
-    if (reason == SMSCCONN_FAILED_TEMPORARILY && smscconn_status(conn) == SMSCCONN_ACTIVE &&
-        smscconn_send(conn, msg) == 0) {
-        /* destroy this message because it will be duplicated in smsc module */
-        msg_destroy(msg);
-        return;
+    if (sms_resend_retry >= 0 && msg->sms.resend_try >= sms_resend_retry) {
+        warning(0, "Maximum retries for message exceeded, discarding it!");
+        reason = SMSCCONN_FAILED_DISCARDED;
+    } else {
+        msg->sms.resend_try = (msg->sms.resend_try > 0 ? msg->sms.resend_try + 1 : 1);
+        time(&msg->sms.resend_time);
+        if (reason == SMSCCONN_FAILED_TEMPORARILY && smscconn_status(conn) == SMSCCONN_ACTIVE){
+            gwlist_produce(outgoing_sms, msg);
+            return;
+        }
     }
     
     /*
