diff nnchat.c @ 360:b465a17ffa47

Finally fix handling of long packets.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 23 Jun 2011 10:37:11 +0300
parents 8f3c102db611
children 461a6befb7c3
line wrap: on
line diff
--- a/nnchat.c	Thu Jun 23 10:11:45 2011 +0300
+++ b/nnchat.c	Thu Jun 23 10:37:11 2011 +0300
@@ -1536,25 +1536,28 @@
     }
 
     /* Enter mainloop */
+    nn_conn_reset(conn);
     while (!isError && !exitProg) {
         int cres = nn_conn_pull(conn);
-        if (cres == 0) {
+        if (cres == 0 && *(conn->ptr - 1) == 0) {
+            char *ptr = conn->buf;
             do {
-                size_t bufLen = strlen(conn->ptr) + 1;
-                int result = handleProtocol(conn, conn->ptr, bufLen);
+                size_t bufLen = strlen(ptr) + 1;
+                int result = handleProtocol(conn, ptr, bufLen);
 
                 if (result > 0) {
                     /* Couldn't handle the message for some reason */
-                    printMsg(currWin, "Could not handle: %s\n", conn->ptr);
+                    printMsg(currWin, "Could not handle: %s\n", ptr);
                 } else if (result < 0) {
                     /* Fatal error, quit */
-                    errorMsg("Fatal error with message: %s\n", conn->ptr);
+                    errorMsg("Fatal error with message: %s\n", ptr);
                     isError = TRUE;
                 }
 
-                conn->got -= bufLen;
-                conn->ptr += bufLen;
-            } while (conn->got > 0 && !isError);
+                conn->total -= bufLen;
+                ptr += bufLen;
+            } while (conn->total > 0 && !isError);
+            nn_conn_reset(conn);
         }
         if (!nn_conn_check(conn))
             isError = TRUE;