diff options
author | erdgeist <> | 2007-01-08 05:18:53 +0000 |
---|---|---|
committer | erdgeist <> | 2007-01-08 05:18:53 +0000 |
commit | ac8e26f99bee3a390cf01b0ac7298cb5c5c8e0d8 (patch) | |
tree | bb4aa5f89ed00a1f28cb31b5f852368bbc0f0662 /opentracker.c | |
parent | 1d66041fd595a73434bb9c803180b941de82e33f (diff) |
Some code spacifying. Added actually checking timeouts.
Diffstat (limited to 'opentracker.c')
-rw-r--r-- | opentracker.c | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/opentracker.c b/opentracker.c index 58704bb..5bccab9 100644 --- a/opentracker.c +++ b/opentracker.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "scan_urlencoded_query.h" | 27 | #include "scan_urlencoded_query.h" |
28 | 28 | ||
29 | unsigned long const OT_CLIENT_TIMEOUT = 15; | 29 | unsigned long const OT_CLIENT_TIMEOUT = 15; |
30 | unsigned long const OT_CLIENT_TIMEOUT_CHECKINTERVAL = 5; | ||
30 | 31 | ||
31 | static unsigned int ot_overall_connections = 0; | 32 | static unsigned int ot_overall_connections = 0; |
32 | static time_t ot_start_time; | 33 | static time_t ot_start_time; |
@@ -343,7 +344,7 @@ void help( char *name ) { | |||
343 | 344 | ||
344 | int main( int argc, char **argv ) { | 345 | int main( int argc, char **argv ) { |
345 | int s=socket_tcp4(); | 346 | int s=socket_tcp4(); |
346 | tai6464 t; | 347 | tai6464 t, next_timeout_check; |
347 | unsigned long ip; | 348 | unsigned long ip; |
348 | char *serverip = NULL; | 349 | char *serverip = NULL; |
349 | char *serverdir = "."; | 350 | char *serverdir = "."; |
@@ -384,17 +385,33 @@ allparsed: | |||
384 | if( init_logic( serverdir ) == -1 ) | 385 | if( init_logic( serverdir ) == -1 ) |
385 | panic("Logic not started"); | 386 | panic("Logic not started"); |
386 | 387 | ||
387 | io_wantread(s); | 388 | io_wantread( s ); |
389 | taia_now( &next_timeout_check ); | ||
390 | taia_addsec( &next_timeout_check, &next_timeout_check, OT_CLIENT_TIMEOUT_CHECKINTERVAL ); | ||
388 | 391 | ||
389 | for (;;) { | 392 | for (;;) { |
390 | int64 i; | 393 | int64 i; |
391 | io_wait(); | 394 | io_wait(); |
392 | 395 | ||
393 | while ((i=io_canread())!=-1) { | 396 | taia_now(&t); |
394 | if (i==s) { // ist es der serversocket? | 397 | if( taia_less( &next_timeout_check, &t ) ) { |
398 | while( ( i = io_timeouted() ) != -1 ) { | ||
399 | struct http_data* h=io_getcookie(i); | ||
400 | if( h ) { | ||
401 | array_reset( &h->r ); | ||
402 | free( h ); | ||
403 | } | ||
404 | io_close(i); | ||
405 | } | ||
406 | taia_now(&next_timeout_check); | ||
407 | taia_addsec(&next_timeout_check,&next_timeout_check,OT_CLIENT_TIMEOUT_CHECKINTERVAL); | ||
408 | } | ||
409 | |||
410 | while( ( i = io_canread() ) != -1 ) { | ||
411 | if( i == s ) { // ist es der serversocket? | ||
395 | int n; | 412 | int n; |
396 | while ((n=socket_accept4(s,(void*)&ip,&port))!=-1) { | 413 | while( ( n = socket_accept4( s, (void*)&ip, &port) ) != -1 ) { |
397 | if (io_fd(n)) { | 414 | if( io_fd( n ) ) { |
398 | struct http_data* h=(struct http_data*)malloc(sizeof(struct http_data)); | 415 | struct http_data* h=(struct http_data*)malloc(sizeof(struct http_data)); |
399 | io_wantread(n); | 416 | io_wantread(n); |
400 | 417 | ||