Browse Source

Move dead socket handling from handle_(read,write,timedout) into its own function handle_dead

dynamic-accesslists
erdgeist 17 years ago
parent
commit
e476006019
  1. 53
      opentracker.c

53
opentracker.c

@ -39,6 +39,7 @@
#include "ot_fullscrape.h" #include "ot_fullscrape.h"
#include "ot_iovec.h" #include "ot_iovec.h"
#include "ot_accesslist.h" #include "ot_accesslist.h"
#include "ot_mutex.h"
/* Globals */ /* Globals */
static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80;
@ -78,7 +79,8 @@ static char debug_request[8192];
typedef enum { typedef enum {
STRUCT_HTTP_FLAG_ARRAY_USED = 1, STRUCT_HTTP_FLAG_ARRAY_USED = 1,
STRUCT_HTTP_FLAG_IOB_USED = 2 STRUCT_HTTP_FLAG_IOB_USED = 2,
STRUCT_HTTP_FLAG_WAITINGFORTASK = 4
} STRUCT_HTTP_FLAG; } STRUCT_HTTP_FLAG;
struct http_data { struct http_data {
@ -619,20 +621,27 @@ static void help( char *name ) {
} }
#undef HELPLINE #undef HELPLINE
static void handle_read( const int64 clientsocket ) { static void handle_dead( const int64 socket ) {
struct http_data* h = io_getcookie( clientsocket ); struct http_data* h=io_getcookie( socket );
ssize_t l;
if( ( l = io_tryread( clientsocket, static_inbuf, sizeof static_inbuf ) ) <= 0 ) {
if( h ) { if( h ) {
if( h->flag & STRUCT_HTTP_FLAG_IOB_USED )
iob_reset( &h->batch );
if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED ) if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED )
array_reset( &h->request ); array_reset( &h->request );
if( h->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK )
mutex_workqueue_canceltask( socket );
free( h ); free( h );
} }
io_close( clientsocket ); io_close( socket );
return;
} }
static void handle_read( const int64 clientsocket ) {
struct http_data* h = io_getcookie( clientsocket );
ssize_t l;
if( ( l = io_tryread( clientsocket, static_inbuf, sizeof static_inbuf ) ) <= 0 )
return handle_dead( clientsocket );
#ifdef _DEBUG_HTTPERROR #ifdef _DEBUG_HTTPERROR
memcpy( debug_request, "500!\0", 5 ); memcpy( debug_request, "500!\0", 5 );
#endif #endif
@ -660,12 +669,8 @@ static void handle_read( const int64 clientsocket ) {
static void handle_write( const int64 clientsocket ) { static void handle_write( const int64 clientsocket ) {
struct http_data* h=io_getcookie( clientsocket ); struct http_data* h=io_getcookie( clientsocket );
if( !h ) return; if( !h || ( iob_send( clientsocket, &h->batch ) <= 0 ) )
if( iob_send( clientsocket, &h->batch ) <= 0 ) { handle_dead( clientsocket );
iob_reset( &h->batch );
io_close( clientsocket );
free( h );
}
} }
static void handle_accept( const int64 serversocket ) { static void handle_accept( const int64 serversocket ) {
@ -703,21 +708,15 @@ static void handle_accept( const int64 serversocket ) {
static void handle_timeouted( void ) { static void handle_timeouted( void ) {
int64 i; int64 i;
while( ( i = io_timeouted() ) != -1 ) { while( ( i = io_timeouted() ) != -1 )
struct http_data* h=io_getcookie( i ); handle_dead( i );
if( h ) {
if( h->flag & STRUCT_HTTP_FLAG_IOB_USED )
iob_reset( &h->batch );
if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED )
array_reset( &h->request );
free( h );
}
io_close(i);
}
} }
static void server_mainloop( ) { static void server_mainloop( ) {
time_t next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL; time_t next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL;
/* Later we will poll for finished tasks
struct iovec *iovector;
int iovec_entries;*/
for( ; ; ) { for( ; ; ) {
int64 i; int64 i;
@ -734,6 +733,10 @@ static void server_mainloop( ) {
handle_read( i ); handle_read( i );
} }
/* Later we will poll for finished tasks
while( ( i = mutex_workqueue_popresult( &iovec_entries, &iovector ) ) != -1 )
sendiovecdata( i, iovec_entries, iovector ); */
while( ( i = io_canwrite( ) ) != -1 ) while( ( i = io_canwrite( ) ) != -1 )
handle_write( i ); handle_write( i );

Loading…
Cancel
Save