comparison main.c @ 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
comparison
equal deleted inserted replaced
444:29a341fa80a1 445:7e46f2f0ba34
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 int cres = nn_conn_pull(conn); 1907 int retries = 3, cres;
1908
1909 packet_retry:
1910 cres = nn_conn_pull(conn);
1908 if (cres == 0) 1911 if (cres == 0)
1909 { 1912 {
1910 int retries = 3;
1911 while (conn->ptr < conn->in_ptr && 1913 while (conn->ptr < conn->in_ptr &&
1912 *(conn->in_ptr - 1) == 0 && 1914 *(conn->in_ptr - 1) == 0 &&
1913 retries > 0) 1915 retries > 0 && !isError)
1914 { 1916 {
1915 // nn_conn_dump_buffer(stderr, conn); 1917 // nn_conn_dump_buffer(stderr, conn);
1916 int result = nn_parse_protocol(conn); 1918 int result = nn_parse_protocol(conn);
1917 if (result == 0) 1919 if (result == 0)
1918 { 1920 {
1919 nn_conn_buf_skip(conn, 1); 1921 nn_conn_buf_skip(conn, 1);
1920 } 1922 }
1921 else 1923 else
1922 if (result > 0) 1924 if (result > 0)
1923 { 1925 {
1926 // Retry if possible
1924 if (--retries > 0) 1927 if (--retries > 0)
1925 { 1928 goto packet_retry;
1926 cres = nn_conn_pull(conn); 1929
1927 } 1930 // Couldn't handle the message for some reason
1928 else 1931 printMsg(currWin, "Could not handle: %s\n", conn->ptr);
1929 { 1932 nn_conn_buf_skip(conn, strlen(conn->ptr) + 1);
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 }
1934 } 1933 }
1935 else 1934 else
1936 { 1935 {
1937 // Fatal error, quit 1936 // Fatal error, quit
1938 errorMsg("Fatal error with message: %s\n", conn->ptr); 1937 errorMsg("Fatal error with message: %s\n", conn->ptr);