Mercurial > hg > nnchat
comparison main.c @ 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 | 8e9690a3f973 |
children | ecbd9773c74b |
comparison
equal
deleted
inserted
replaced
438:3be600124da8 | 439:70ea06294f3f |
---|---|
1902 | 1902 |
1903 // Enter mainloop | 1903 // Enter mainloop |
1904 nn_conn_reset(conn); | 1904 nn_conn_reset(conn); |
1905 while (!isError && !exitProg) | 1905 while (!isError && !exitProg) |
1906 { | 1906 { |
1907 nn_conn_reset(conn); | 1907 int cres = nn_conn_pull(conn); |
1908 do { | 1908 if (cres == 0) |
1909 int cres = nn_conn_pull(conn); | 1909 { |
1910 if (cres == 0 && *(conn->in_ptr - 1) == 0) | 1910 int retries = 3; |
1911 while (conn->ptr < conn->in_ptr && | |
1912 *(conn->in_ptr - 1) == 0 && | |
1913 retries > 0) | |
1911 { | 1914 { |
1915 // nn_conn_dump_buffer(stderr, conn); | |
1912 int result = nn_parse_protocol(conn); | 1916 int result = nn_parse_protocol(conn); |
1913 if (result == 0) | 1917 if (result == 0) |
1914 { | 1918 { |
1915 nn_conn_buf_skip(conn, 1); | 1919 nn_conn_buf_skip(conn, 1); |
1916 } | 1920 } |
1917 else | 1921 else |
1918 if (result > 0) | 1922 if (result > 0) |
1919 { | 1923 { |
1920 // Couldn't handle the message for some reason | 1924 if (--retries > 0) |
1921 printMsg(currWin, "Could not handle: %s\n", conn->ptr); | 1925 { |
1926 cres = nn_conn_pull(conn); | |
1927 } | |
1928 else | |
1929 { | |
1930 // Couldn't handle the message for some reason | |
1931 printMsg(currWin, "Could not handle: %s\n", conn->ptr); | |
1932 nn_conn_buf_skip(conn, strlen(conn->ptr) + 1); | |
1933 } | |
1922 } | 1934 } |
1923 else | 1935 else |
1924 { | 1936 { |
1925 // Fatal error, quit | 1937 // Fatal error, quit |
1926 errorMsg("Fatal error with message: %s\n", conn->ptr); | 1938 errorMsg("Fatal error with message: %s\n", conn->ptr); |
1927 isError = TRUE; | 1939 isError = TRUE; |
1928 } | 1940 } |
1929 } | 1941 } |
1930 else if (cres < 0) | 1942 } |
1931 isError = TRUE; | 1943 else |
1932 else | 1944 if (cres < 0 || !nn_conn_check(conn)) |
1933 break; | |
1934 } | |
1935 while (conn->total_bytes > 0 && !isError); | |
1936 | |
1937 if (!nn_conn_check(conn)) | |
1938 isError = TRUE; | 1945 isError = TRUE; |
1939 | 1946 |
1940 // Handle user input | 1947 // Handle user input |
1941 if (cursesInit) | 1948 if (cursesInit) |
1942 { | 1949 { |