From ce8588c9ef32aa218fa10daafa55f7c5aef352f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 1 Oct 2014 00:56:03 +0200 Subject: [PATCH] Make udp_proxy more robust There seemed to be some race conditions with server closing its fd right after sending HelloVerifyRequest causing the proxy to exit after a failed read. --- programs/test/udp_proxy.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c index 110a7c753..782fe62fb 100644 --- a/programs/test/udp_proxy.c +++ b/programs/test/udp_proxy.c @@ -545,6 +545,9 @@ accept: /* * 3. Forward packets forever (kill the process to terminate it) */ + clear_pending(); + memset( dropped, 0, sizeof( dropped ) ); + nb_fds = client_fd; if( nb_fds < server_fd ) nb_fds = server_fd; @@ -566,24 +569,20 @@ accept: } if( FD_ISSET( listen_fd, &read_fds ) ) - { - clear_pending(); - memset( dropped, 0, sizeof( dropped ) ); goto accept; - } if( FD_ISSET( client_fd, &read_fds ) ) { if( ( ret = handle_message( "S <- C", server_fd, client_fd ) ) != 0 ) - goto exit; + goto accept; } if( FD_ISSET( server_fd, &read_fds ) ) { if( ( ret = handle_message( "S -> C", client_fd, server_fd ) ) != 0 ) - goto exit; + goto accept; } }