Here is a new version of the mtbach program.

- Introducing a Counter type
- Now handling correclty ack from bearerbox.
- typo fixes.

Vincent



Vincent CHAVANIS a écrit :

The issue is located on the mtbatch program that exit before receiving all ack/nack from bearerbox.
(btw, Thanks to alex pointing me this)

The result is an TCP broken pipe System error 104: Connection reset by peer

This patch fixes this.

Vincent.


--- /gateway-cvs/utils/mtbatch.c        2009-01-14 10:24:23.000000000 +0100
+++ /gateway/utils/mtbatch.c    2009-03-31 18:42:18.000000000 +0200
@@ -65,7 +65,6 @@
  * Stipe Tolj <[email protected]>
  *
  * XXX add udh (etc.) capabilities. Currently we handle only 7-bit.
- * XXX add ACK handling by providing a queue and retrying if failed.
  */
 
 #include <string.h>
@@ -87,6 +86,7 @@
 static Octstr *bb_host;
 static long bb_port;
 static int bb_ssl;
+static Counter *counter;
 static Octstr *service = NULL;
 static Octstr *account = NULL;
 static Octstr *from = NULL;
@@ -135,10 +135,10 @@
 {
     time_t start, t;
     unsigned long secs;
-    unsigned long total_s, total_f, total_ft, total_b;
+    unsigned long total_s, total_f, total_ft, total_b, total_o;
     Msg *msg;
 
-    total_s = total_f = total_ft = total_b = 0;
+    total_s = total_f = total_ft = total_b = total_o = 0;
     start = t = time(NULL);
     while (program_status != shutting_down) {
         int ret;
@@ -162,6 +162,7 @@
              */
             msg_destroy(msg);
         } else if (msg_type(msg) == ack) {
+            counter_increase(counter);
             switch (msg->ack.nack) {
                 case ack_success:
                     total_s++;
@@ -178,13 +179,14 @@
             }
             msg_destroy(msg);
         } else {
-            warning(0, "Received other message than sms/admin, ignoring!");
+            warning(0, "Received other message than ack/admin, ignoring!");
             msg_destroy(msg);
+            total_o++;
         }
     }
     secs = difftime(time(NULL), start);
-    info(0, "Received acks: %ld success, %ld failed, %ld failed temporarly, 
%ld queued in %ld seconds "
-        "(%.2f per second)", total_s, total_f, total_ft, total_b, secs, 
+    info(0, "Received acks: %ld success, %ld failed, %ld failed temporarly, 
%ld queued, %ld other in %.2f seconds "
+        "(%.2f per second)", total_s, total_f, total_ft, total_b, total_o, 
secs, 
          (float)(total_s+total_f+total_ft+total_b) / secs);
 }
 
@@ -284,12 +286,16 @@
 
     info(0,"Receivers file `%s' contains %ld destination numbers.",
          octstr_get_cstr(rfilename), lineno);
+
+    counter = counter_create();
 }
 
-static void run_batch(void)
+unsigned long run_batch(void)
 {
     Octstr *no;
+    unsigned long linerr = 0;
     unsigned long lineno = 0;
+    int r = 0;
 
     while ((no = gwlist_consume(lines)) != NULL) {
        if (octstr_check_range(no, 0, 256, gw_isdigit)) {
@@ -310,6 +317,7 @@
         msg->sms.coding = DC_7BIT;
 
         if (send_message(msg) < 0) {
+            linerr++;
             panic(0,"Failed to send message at line <%ld> for receiver `%s' to 
bearerbox.",
                   lineno, octstr_get_cstr(no));
         }
@@ -317,12 +326,16 @@
         octstr_destroy(no);
         }
     }
+    info(0,"mtbatch has processed %ld messages with %ld errors", lineno, 
linerr);
+    return lineno;
 } 
 
 int main(int argc, char **argv)
 {
     int opt;
+    unsigned long sended;
     Octstr *cf, *rf;
+    sended = 0;
 
     gwlib_init();
 
@@ -373,7 +386,7 @@
     
     if (optind == argc || argc-optind < 2) {
         help();
-        exit(0);
+        panic(0, "Stopping.");
     }
 
     /* check some mandatory elements */
@@ -392,7 +404,9 @@
     identify_to_bearerbox();
     gwthread_create(read_messages_from_bearerbox, NULL);
 
-    run_batch();
+    sended = run_batch();
+
+    while(counter_value(counter) < sended) { /* avoid exiting before sending 
all msgs */ }
 
     program_status = shutting_down;
     gwthread_join_all();
@@ -403,6 +417,7 @@
     octstr_destroy(service);
     octstr_destroy(account);
     octstr_destroy(smsc_id);
+    counter_destroy(counter);
     gwlist_destroy(lines, octstr_destroy_item); 
    
     gwlib_shutdown();

Reply via email to