changeset 445:7e46f2f0ba34

Cleanup packet retrying a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 May 2012 22:42:50 +0300
parents 29a341fa80a1
children 3396acd40147
files main.c
diffstat 1 files changed, 11 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Fri May 25 22:02:24 2012 +0300
+++ b/main.c	Fri May 25 22:42:50 2012 +0300
@@ -1904,13 +1904,15 @@
     nn_conn_reset(conn);
     while (!isError && !exitProg)
     {
-        int cres = nn_conn_pull(conn);
+        int retries = 3, cres;
+
+packet_retry:
+        cres = nn_conn_pull(conn);
         if (cres == 0)
         {
-            int retries = 3;
             while (conn->ptr < conn->in_ptr &&
                    *(conn->in_ptr - 1) == 0 &&
-                   retries > 0)
+                   retries > 0 && !isError)
             {
 //                nn_conn_dump_buffer(stderr, conn);
                 int result = nn_parse_protocol(conn);
@@ -1921,16 +1923,13 @@
                 else
                 if (result > 0)
                 {
+                    // Retry if possible
                     if (--retries > 0)
-                    {
-                        cres = nn_conn_pull(conn);
-                    }
-                    else
-                    {
-                        // Couldn't handle the message for some reason
-                        printMsg(currWin, "Could not handle: %s\n", conn->ptr);
-                        nn_conn_buf_skip(conn, strlen(conn->ptr) + 1);
-                    }
+                        goto packet_retry;
+
+                    // Couldn't handle the message for some reason
+                    printMsg(currWin, "Could not handle: %s\n", conn->ptr);
+                    nn_conn_buf_skip(conn, strlen(conn->ptr) + 1);
                 }
                 else
                 {