diff options
author | erdgeist <> | 2007-01-19 17:50:36 +0000 |
---|---|---|
committer | erdgeist <> | 2007-01-19 17:50:36 +0000 |
commit | 07a604e3d6c1800374c9713c0ef954eb7d18a40a (patch) | |
tree | 9d5e0d14038e8ae100f0ba898e3cbcd0f354b9c1 /opentracker.c | |
parent | 6c62ed79284eb61b9703441b6fab26dc8a252eaf (diff) |
Debug file descriptors
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/opentracker.c b/opentracker.c index a6c57e7..374824f 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -35,6 +35,10 @@ static const size_t SUCCESS_HTTP_SIZE_OFF = 17; | |||
35 | /* To always have space for error messages ;) */ | 35 | /* To always have space for error messages ;) */ |
36 | static char static_scratch[8192]; | 36 | static char static_scratch[8192]; |
37 | 37 | ||
38 | #ifdef _DEBUG_FDS | ||
39 | static char fd_debug_space[0x10000]; | ||
40 | #endif | ||
41 | |||
38 | static void carp(const char* routine) { | 42 | static void carp(const char* routine) { |
39 | buffer_puts(buffer_2,routine); | 43 | buffer_puts(buffer_2,routine); |
40 | buffer_puts(buffer_2,": "); | 44 | buffer_puts(buffer_2,": "); |
@@ -70,10 +74,18 @@ void senddata(int64 s, struct http_data* h, char *buffer, size_t size ) { | |||
70 | if( h ) array_reset(&h->r); | 74 | if( h ) array_reset(&h->r); |
71 | written_size = write( s, buffer, size ); | 75 | written_size = write( s, buffer, size ); |
72 | if( ( written_size < 0 ) || ( written_size == size ) ) { | 76 | if( ( written_size < 0 ) || ( written_size == size ) ) { |
77 | #ifdef _DEBUG_FDS | ||
78 | if( !fd_debug_space[s] ) fprintf( stderr, "close on non-open fd\n" ); | ||
79 | fd_debug_space[s] = 0; | ||
80 | #endif | ||
73 | free(h); io_close( s ); | 81 | free(h); io_close( s ); |
74 | } else { | 82 | } else { |
75 | /* here we would take a copy of the buffer and remember it */ | 83 | /* here we would take a copy of the buffer and remember it */ |
76 | fprintf( stderr, "Should have handled this.\n" ); | 84 | fprintf( stderr, "Should have handled this.\n" ); |
85 | #ifdef _DEBUG_FDS | ||
86 | if( !fd_debug_space[s] ) fprintf( stderr, "close on non-open fd\n" ); | ||
87 | fd_debug_space[s] = 0; | ||
88 | #endif | ||
77 | free(h); io_close( s ); | 89 | free(h); io_close( s ); |
78 | } | 90 | } |
79 | } | 91 | } |
@@ -337,6 +349,10 @@ e404: | |||
337 | senddata( s, h, static_scratch + reply_off, reply_size ); | 349 | senddata( s, h, static_scratch + reply_off, reply_size ); |
338 | } else { | 350 | } else { |
339 | if( h ) array_reset(&h->r); | 351 | if( h ) array_reset(&h->r); |
352 | #ifdef _DEBUG_FDS | ||
353 | if( !fd_debug_space[s] ) fprintf( stderr, "close on non-open fd\n" ); | ||
354 | fd_debug_space[s] = 0; | ||
355 | #endif | ||
340 | free( h ); io_close( s ); | 356 | free( h ); io_close( s ); |
341 | } | 357 | } |
342 | } | 358 | } |
@@ -349,6 +365,15 @@ void graceful( int s ) { | |||
349 | } | 365 | } |
350 | } | 366 | } |
351 | 367 | ||
368 | #ifdef _DEBUG_FDS | ||
369 | void count_fds( int s ) { | ||
370 | int i, count = 0; | ||
371 | for( i=0; i<sizeof(fd_debug_space); ++i ) | ||
372 | if( fd_debug_space[i] ) ++count; | ||
373 | fprintf( stderr, "Open fds here: %i\n", count ); | ||
374 | } | ||
375 | #endif | ||
376 | |||
352 | void usage( char *name ) { | 377 | void usage( char *name ) { |
353 | fprintf( stderr, "Usage: %s [-i serverip] [-p serverport] [-d serverdirectory]" | 378 | fprintf( stderr, "Usage: %s [-i serverip] [-p serverport] [-d serverdirectory]" |
354 | #ifdef WANT_CLOSED_TRACKER | 379 | #ifdef WANT_CLOSED_TRACKER |
@@ -394,6 +419,10 @@ void handle_read( int64 clientsocket ) { | |||
394 | array_reset(&h->r); | 419 | array_reset(&h->r); |
395 | free(h); | 420 | free(h); |
396 | } | 421 | } |
422 | #ifdef _DEBUG_FDS | ||
423 | if( !fd_debug_space[clientsocket] ) fprintf( stderr, "close on non-open fd\n" ); | ||
424 | fd_debug_space[clientsocket] = 0; | ||
425 | #endif | ||
397 | io_close(clientsocket); | 426 | io_close(clientsocket); |
398 | return; | 427 | return; |
399 | } | 428 | } |
@@ -423,6 +452,11 @@ void handle_accept( int64 serversocket ) { | |||
423 | continue; | 452 | continue; |
424 | } | 453 | } |
425 | 454 | ||
455 | #ifdef _DEBUG_FDS | ||
456 | if( fd_debug_space[i] ) fprintf( stderr, "double use of fd: %i\n", (int)i ); | ||
457 | fd_debug_space[i] = 1; | ||
458 | #endif | ||
459 | |||
426 | io_wantread( i ); | 460 | io_wantread( i ); |
427 | 461 | ||
428 | byte_zero(h,sizeof(struct http_data)); | 462 | byte_zero(h,sizeof(struct http_data)); |
@@ -448,6 +482,10 @@ void handle_timeouted( ) { | |||
448 | array_reset( &h->r ); | 482 | array_reset( &h->r ); |
449 | free( h ); | 483 | free( h ); |
450 | } | 484 | } |
485 | #ifdef _DEBUG_FDS | ||
486 | if( !fd_debug_space[i] ) fprintf( stderr, "close on non-open fd\n" ); | ||
487 | fd_debug_space[i] = 0; | ||
488 | #endif | ||
451 | io_close(i); | 489 | io_close(i); |
452 | } | 490 | } |
453 | } | 491 | } |
@@ -521,7 +559,10 @@ int main( int argc, char **argv ) { | |||
521 | panic("io_fd"); | 559 | panic("io_fd"); |
522 | 560 | ||
523 | signal( SIGPIPE, SIG_IGN ); | 561 | signal( SIGPIPE, SIG_IGN ); |
524 | signal( SIGINT, graceful ); | 562 | signal( SIGINT, graceful ); |
563 | #ifdef _DEBUG_FDS | ||
564 | signal( SIGINFO, count_fds ); | ||
565 | #endif | ||
525 | if( init_logic( serverdir ) == -1 ) | 566 | if( init_logic( serverdir ) == -1 ) |
526 | panic("Logic not started"); | 567 | panic("Logic not started"); |
527 | 568 | ||