Mercurial > hg > nnchat
changeset 439:70ea06294f3f
Possibly fix packet handling after the whole mess of refactoring.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 25 May 2012 21:31:15 +0300 |
parents | 3be600124da8 |
children | 24d01a1d7747 |
files | main.c |
diffstat | 1 files changed, 20 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/main.c Fri May 25 21:30:57 2012 +0300 +++ b/main.c Fri May 25 21:31:15 2012 +0300 @@ -1904,11 +1904,15 @@ nn_conn_reset(conn); while (!isError && !exitProg) { - nn_conn_reset(conn); - do { - int cres = nn_conn_pull(conn); - if (cres == 0 && *(conn->in_ptr - 1) == 0) + int cres = nn_conn_pull(conn); + if (cres == 0) + { + int retries = 3; + while (conn->ptr < conn->in_ptr && + *(conn->in_ptr - 1) == 0 && + retries > 0) { +// nn_conn_dump_buffer(stderr, conn); int result = nn_parse_protocol(conn); if (result == 0) { @@ -1917,8 +1921,16 @@ else if (result > 0) { - // Couldn't handle the message for some reason - printMsg(currWin, "Could not handle: %s\n", conn->ptr); + 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); + } } else { @@ -1927,14 +1939,9 @@ isError = TRUE; } } - else if (cres < 0) - isError = TRUE; - else - break; } - while (conn->total_bytes > 0 && !isError); - - if (!nn_conn_check(conn)) + else + if (cres < 0 || !nn_conn_check(conn)) isError = TRUE; // Handle user input