summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--README4
-rw-r--r--opentracker.c39
-rw-r--r--testsuite.sh2
4 files changed, 40 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index 94b8e05..74c5db5 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ CC?=gcc
2FEATURES=#-D_DEBUG_FDS -DWANT_IP_FROM_QUERY_STRING -DWANT_BLACKLIST -DWANT_CLOSED_TRACKER 2FEATURES=#-D_DEBUG_FDS -DWANT_IP_FROM_QUERY_STRING -DWANT_BLACKLIST -DWANT_CLOSED_TRACKER
3#DEBUG_OPTS=-g -ggdb -pg # -fprofile-arcs -ftest-coverage 3#DEBUG_OPTS=-g -ggdb -pg # -fprofile-arcs -ftest-coverage
4DEBUG_OPTS=-s -Os 4DEBUG_OPTS=-s -Os
5CFLAGS+=-I../libowfat -Wall -pipe -m64 # -pedantic -ansi 5CFLAGS+=-I../libowfat -Wall -pipe # -pedantic -ansi
6LDFLAGS+=-L../libowfat/ -lowfat -lm 6LDFLAGS+=-L../libowfat/ -lowfat -lm
7 7
8HEADERS=trackerlogic.h scan_urlencoded_query.h 8HEADERS=trackerlogic.h scan_urlencoded_query.h
diff --git a/README b/README
index c90db43..1890400 100644
--- a/README
+++ b/README
@@ -26,3 +26,7 @@ sysctl kern.ipc.somaxconn=1024
26sysctl kern.ipc.nmbclusters=32768 26sysctl kern.ipc.nmbclusters=32768
27sysctl net.inet.tcp.msl=10000 27sysctl net.inet.tcp.msl=10000
28sysctl kern.maxfiles=10240 28sysctl kern.maxfiles=10240
29
30License information:
31
32Although the libowfat library is under GPL, Felix von Leitner aggreed that the compiled binary may be distributed under the same beer ware license as the source code for opentracker. However, we like to hear from happy customers.
diff --git a/opentracker.c b/opentracker.c
index 374824f..6ff9da3 100644
--- a/opentracker.c
+++ b/opentracker.c
@@ -5,6 +5,7 @@
5 5
6#include "socket.h" 6#include "socket.h"
7#include "io.h" 7#include "io.h"
8#include "iob.h"
8#include "buffer.h" 9#include "buffer.h"
9#include "array.h" 10#include "array.h"
10#include "byte.h" 11#include "byte.h"
@@ -52,7 +53,10 @@ static void panic(const char* routine) {
52} 53}
53 54
54struct http_data { 55struct http_data {
55 array r; 56 union {
57 array r;
58 io_batch batch;
59 };
56 unsigned char ip[4]; 60 unsigned char ip[4];
57}; 61};
58 62
@@ -81,12 +85,24 @@ void senddata(int64 s, struct http_data* h, char *buffer, size_t size ) {
81 free(h); io_close( s ); 85 free(h); io_close( s );
82 } else { 86 } else {
83 /* here we would take a copy of the buffer and remember it */ 87 /* here we would take a copy of the buffer and remember it */
84 fprintf( stderr, "Should have handled this.\n" ); 88 char * outbuf = malloc( size - written_size );
89 tai6464 t;
90
91 if( !outbuf ) {
85#ifdef _DEBUG_FDS 92#ifdef _DEBUG_FDS
86 if( !fd_debug_space[s] ) fprintf( stderr, "close on non-open fd\n" ); 93 if( !fd_debug_space[s] ) fprintf( stderr, "close on non-open fd\n" );
87 fd_debug_space[s] = 0; 94 fd_debug_space[s] = 0;
88#endif 95#endif
89 free(h); io_close( s ); 96 free(h); io_close( s );
97 return;
98 }
99
100 iob_reset( &h->batch );
101 memmove( outbuf, buffer + written_size, size - written_size );
102 iob_addbuf_free( &h->batch, outbuf, size - written_size );
103
104 // writeable sockets just have a tcp timeout
105 taia_uint(&t,0); io_timeout( s, t );
90 } 106 }
91} 107}
92 108
@@ -437,6 +453,16 @@ void handle_read( int64 clientsocket ) {
437 httpresponse(clientsocket,h); 453 httpresponse(clientsocket,h);
438} 454}
439 455
456void handle_write( int64 clientsocket ) {
457 struct http_data* h=io_getcookie(clientsocket);
458 if( !h ) return;
459 if( iob_send( clientsocket, &h->batch ) <= 0 ) {
460 iob_reset( &h->batch );
461 io_close( clientsocket );
462 free( h );
463 }
464}
465
440void handle_accept( int64 serversocket ) { 466void handle_accept( int64 serversocket ) {
441 struct http_data* h; 467 struct http_data* h;
442 unsigned char ip[4]; 468 unsigned char ip[4];
@@ -510,6 +536,9 @@ void server_mainloop( int64 serversocket ) {
510 handle_read( i ); 536 handle_read( i );
511 } 537 }
512 538
539 while( ( i = io_canwrite() ) != -1 )
540 handle_write( i );
541
513 taia_now(&t); 542 taia_now(&t);
514 if( taia_less( &next_timeout_check, &t ) ) { 543 if( taia_less( &next_timeout_check, &t ) ) {
515 handle_timeouted( ); 544 handle_timeouted( );
diff --git a/testsuite.sh b/testsuite.sh
index e5bc7a4..6baeabb 100644
--- a/testsuite.sh
+++ b/testsuite.sh
@@ -6,7 +6,7 @@ ip=10.1.1.$(( $RANDOM & 0xff ))&port=$(( $RANDOM & 0xff )) HTTP/1.0\n"
6 6
7# echo -e $request_string 7# echo -e $request_string
8# echo 8# echo
9 echo -e $request_string | nc 127.0.0.1 6969 >/dev/null 9 echo -e $request_string | nc 127.0.0.1 6969 >/dev/null &
10# echo 10# echo
11 11
12done 12done