summaryrefslogtreecommitdiff
path: root/opentracker.c
diff options
context:
space:
mode:
authorerdgeist <>2007-11-14 13:06:34 +0000
committererdgeist <>2007-11-14 13:06:34 +0000
commite476006019722606d0dcfc032224bad55010631a (patch)
tree9c5ad61c83d783483196c222b3acc63a9bc3712a /opentracker.c
parentcf26f2ab2387147480baaf41a38c15ded9b77158 (diff)
Move dead socket handling from handle_(read,write,timedout) into its own function handle_dead
Diffstat (limited to 'opentracker.c')
-rw-r--r--opentracker.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/opentracker.c b/opentracker.c
index 3c2aab7..501213d 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -39,6 +39,7 @@
39#include "ot_fullscrape.h" 39#include "ot_fullscrape.h"
40#include "ot_iovec.h" 40#include "ot_iovec.h"
41#include "ot_accesslist.h" 41#include "ot_accesslist.h"
42#include "ot_mutex.h"
42 43
43/* Globals */ 44/* Globals */
44static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80; 45static const size_t SUCCESS_HTTP_HEADER_LENGTH = 80;
@@ -77,8 +78,9 @@ static char debug_request[8192];
77#endif 78#endif
78 79
79typedef enum { 80typedef enum {
80 STRUCT_HTTP_FLAG_ARRAY_USED = 1, 81 STRUCT_HTTP_FLAG_ARRAY_USED = 1,
81 STRUCT_HTTP_FLAG_IOB_USED = 2 82 STRUCT_HTTP_FLAG_IOB_USED = 2,
83 STRUCT_HTTP_FLAG_WAITINGFORTASK = 4
82} STRUCT_HTTP_FLAG; 84} STRUCT_HTTP_FLAG;
83 85
84struct http_data { 86struct http_data {
@@ -619,19 +621,26 @@ static void help( char *name ) {
619} 621}
620#undef HELPLINE 622#undef HELPLINE
621 623
624static void handle_dead( const int64 socket ) {
625 struct http_data* h=io_getcookie( socket );
626 if( h ) {
627 if( h->flag & STRUCT_HTTP_FLAG_IOB_USED )
628 iob_reset( &h->batch );
629 if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED )
630 array_reset( &h->request );
631 if( h->flag & STRUCT_HTTP_FLAG_WAITINGFORTASK )
632 mutex_workqueue_canceltask( socket );
633 free( h );
634 }
635 io_close( socket );
636}
637
622static void handle_read( const int64 clientsocket ) { 638static void handle_read( const int64 clientsocket ) {
623 struct http_data* h = io_getcookie( clientsocket ); 639 struct http_data* h = io_getcookie( clientsocket );
624 ssize_t l; 640 ssize_t l;
625 641
626 if( ( l = io_tryread( clientsocket, static_inbuf, sizeof static_inbuf ) ) <= 0 ) { 642 if( ( l = io_tryread( clientsocket, static_inbuf, sizeof static_inbuf ) ) <= 0 )
627 if( h ) { 643 return handle_dead( clientsocket );
628 if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED )
629 array_reset( &h->request );
630 free( h );
631 }
632 io_close( clientsocket );
633 return;
634 }
635 644
636#ifdef _DEBUG_HTTPERROR 645#ifdef _DEBUG_HTTPERROR
637 memcpy( debug_request, "500!\0", 5 ); 646 memcpy( debug_request, "500!\0", 5 );
@@ -660,12 +669,8 @@ static void handle_read( const int64 clientsocket ) {
660 669
661static void handle_write( const int64 clientsocket ) { 670static void handle_write( const int64 clientsocket ) {
662 struct http_data* h=io_getcookie( clientsocket ); 671 struct http_data* h=io_getcookie( clientsocket );
663 if( !h ) return; 672 if( !h || ( iob_send( clientsocket, &h->batch ) <= 0 ) )
664 if( iob_send( clientsocket, &h->batch ) <= 0 ) { 673 handle_dead( clientsocket );
665 iob_reset( &h->batch );
666 io_close( clientsocket );
667 free( h );
668 }
669} 674}
670 675
671static void handle_accept( const int64 serversocket ) { 676static void handle_accept( const int64 serversocket ) {
@@ -703,21 +708,15 @@ static void handle_accept( const int64 serversocket ) {
703 708
704static void handle_timeouted( void ) { 709static void handle_timeouted( void ) {
705 int64 i; 710 int64 i;
706 while( ( i = io_timeouted() ) != -1 ) { 711 while( ( i = io_timeouted() ) != -1 )
707 struct http_data* h=io_getcookie( i ); 712 handle_dead( i );
708 if( h ) {
709 if( h->flag & STRUCT_HTTP_FLAG_IOB_USED )
710 iob_reset( &h->batch );
711 if( h->flag & STRUCT_HTTP_FLAG_ARRAY_USED )
712 array_reset( &h->request );
713 free( h );
714 }
715 io_close(i);
716 }
717} 713}
718 714
719static void server_mainloop( ) { 715static void server_mainloop( ) {
720 time_t next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL; 716 time_t next_timeout_check = g_now + OT_CLIENT_TIMEOUT_CHECKINTERVAL;
717/* Later we will poll for finished tasks
718 struct iovec *iovector;
719 int iovec_entries;*/
721 720
722 for( ; ; ) { 721 for( ; ; ) {
723 int64 i; 722 int64 i;
@@ -734,6 +733,10 @@ static void server_mainloop( ) {
734 handle_read( i ); 733 handle_read( i );
735 } 734 }
736 735
736/* Later we will poll for finished tasks
737 while( ( i = mutex_workqueue_popresult( &iovec_entries, &iovector ) ) != -1 )
738 sendiovecdata( i, iovec_entries, iovector ); */
739
737 while( ( i = io_canwrite( ) ) != -1 ) 740 while( ( i = io_canwrite( ) ) != -1 )
738 handle_write( i ); 741 handle_write( i );
739 742