comparison 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
comparison
equal deleted inserted replaced
359:8f3c102db611 360:b465a17ffa47
1534 printMsg(NULL, "%s\n", th_prog_author); 1534 printMsg(NULL, "%s\n", th_prog_author);
1535 printMsg(NULL, "%s\n", th_prog_license); 1535 printMsg(NULL, "%s\n", th_prog_license);
1536 } 1536 }
1537 1537
1538 /* Enter mainloop */ 1538 /* Enter mainloop */
1539 nn_conn_reset(conn);
1539 while (!isError && !exitProg) { 1540 while (!isError && !exitProg) {
1540 int cres = nn_conn_pull(conn); 1541 int cres = nn_conn_pull(conn);
1541 if (cres == 0) { 1542 if (cres == 0 && *(conn->ptr - 1) == 0) {
1543 char *ptr = conn->buf;
1542 do { 1544 do {
1543 size_t bufLen = strlen(conn->ptr) + 1; 1545 size_t bufLen = strlen(ptr) + 1;
1544 int result = handleProtocol(conn, conn->ptr, bufLen); 1546 int result = handleProtocol(conn, ptr, bufLen);
1545 1547
1546 if (result > 0) { 1548 if (result > 0) {
1547 /* Couldn't handle the message for some reason */ 1549 /* Couldn't handle the message for some reason */
1548 printMsg(currWin, "Could not handle: %s\n", conn->ptr); 1550 printMsg(currWin, "Could not handle: %s\n", ptr);
1549 } else if (result < 0) { 1551 } else if (result < 0) {
1550 /* Fatal error, quit */ 1552 /* Fatal error, quit */
1551 errorMsg("Fatal error with message: %s\n", conn->ptr); 1553 errorMsg("Fatal error with message: %s\n", ptr);
1552 isError = TRUE; 1554 isError = TRUE;
1553 } 1555 }
1554 1556
1555 conn->got -= bufLen; 1557 conn->total -= bufLen;
1556 conn->ptr += bufLen; 1558 ptr += bufLen;
1557 } while (conn->got > 0 && !isError); 1559 } while (conn->total > 0 && !isError);
1560 nn_conn_reset(conn);
1558 } 1561 }
1559 if (!nn_conn_check(conn)) 1562 if (!nn_conn_check(conn))
1560 isError = TRUE; 1563 isError = TRUE;
1561 1564
1562 /* Handle user input */ 1565 /* Handle user input */