From 5d1f07d3537a3a609f906429dc49f9ecd6a8484d Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Wed, 7 Mar 2007 22:19:00 +0000 Subject: Sanify handling of server sockets --- opentracker.c | 73 +++++++++++++++-------------------------------------------- 1 file changed, 18 insertions(+), 55 deletions(-) (limited to 'opentracker.c') diff --git a/opentracker.c b/opentracker.c index 657f4f3..e286a24 100644 --- a/opentracker.c +++ b/opentracker.c @@ -40,12 +40,9 @@ static const size_t SUCCESS_HTTP_SIZE_OFF = 17; static char static_inbuf[8192]; static char static_outbuf[8192]; -#define OT_MAXSOCKETS_TCP4 64 -#define OT_MAXSOCKETS_UDP4 64 -static int64 ot_sockets_tcp4[ OT_MAXSOCKETS_TCP4 ]; -static int64 ot_sockets_udp4[ OT_MAXSOCKETS_UDP4 ]; -static int ot_sockets_tcp4_count = 0; -static int ot_sockets_udp4_count = 0; +static char *FLAG_TCP = "TCP"; +static char *FLAG_UDP = "UDP"; +static size_t ot_sockets_count = 0; #ifdef _DEBUG_HTTPERROR static char debug_request[8192]; @@ -76,10 +73,7 @@ static void handle_read( const int64 clientsocket ); static void handle_write( const int64 clientsocket ); static void handle_udp4( const int64 serversocket ); -static void ot_try_bind_udp4( char ip[4], uint16 port ); -static void ot_try_bind_tcp4( char ip[4], uint16 port ); -static int ot_in_udp4_sockets( int64 fd ); -static int ot_in_tcp4_sockets( int64 fd ); +static void ot_try_bind( char ip[4], uint16 port, int is_tcp ); static void usage( char *name ); static void help( char *name ); @@ -415,7 +409,7 @@ ANNOUNCE_WORKAROUND: 1. In order to avoid having two buffers, one for header and one for content, we allow all above functions from trackerlogic to write to a fixed location, leaving SUCCESS_HTTP_HEADER_LENGTH bytes in our static buffer, which is enough for the static string - plus dynamic space needed to expand our Content-Length value. We reserve SUCCESS_HTTP_SIZE_OFF for it expansion and calculate + plus dynamic space needed to expand our Content-Length value. We reserve SUCCESS_HTTP_SIZE_OFF for its expansion and calculate the space NOT needed to expand in reply_off */ reply_off = SUCCESS_HTTP_SIZE_OFF - snprintf( static_outbuf, 0, "%zd", reply_size ); @@ -630,22 +624,6 @@ static void handle_udp4( int64 serversocket ) { } } -static int ot_in_tcp4_sockets( int64 fd ) { - int i; - for( i=0; i