diff options
| author | erdgeist <> | 2009-01-16 02:26:50 +0000 |
|---|---|---|
| committer | erdgeist <> | 2009-01-16 02:26:50 +0000 |
| commit | f12fa4c36216e83246767a3cff8dbc86e7d7c6eb (patch) | |
| tree | 989508ccc92346c03ccc02d55a84344165c2ad8b /opentracker.c | |
| parent | 66c906d5d3c100e5fe1e6f088bd1ea17c5831894 (diff) | |
Use a self pipe to wake from io_wait when a thread finished his work.
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/opentracker.c b/opentracker.c index 970995a..8811a6e 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -38,6 +38,7 @@ time_t g_now_seconds; | |||
| 38 | char * g_redirecturl = NULL; | 38 | char * g_redirecturl = NULL; |
| 39 | uint32_t g_tracker_id; | 39 | uint32_t g_tracker_id; |
| 40 | volatile int g_opentracker_running = 1; | 40 | volatile int g_opentracker_running = 1; |
| 41 | int g_self_pipe[2]; | ||
| 41 | 42 | ||
| 42 | static char * g_serverdir = NULL; | 43 | static char * g_serverdir = NULL; |
| 43 | 44 | ||
| @@ -216,6 +217,8 @@ static void server_mainloop( ) { | |||
| 216 | handle_accept( sock ); | 217 | handle_accept( sock ); |
| 217 | else if( (intptr_t)cookie == FLAG_UDP ) | 218 | else if( (intptr_t)cookie == FLAG_UDP ) |
| 218 | handle_udp6( sock, &ws ); | 219 | handle_udp6( sock, &ws ); |
| 220 | else if( (intptr_t)cookie == FLAG_SELFPIPE ) { printf( "woke up\n" ); | ||
| 221 | io_tryread( sock, ws.inbuf, G_INBUF_SIZE ); } | ||
| 219 | else | 222 | else |
| 220 | handle_read( sock, &ws ); | 223 | handle_read( sock, &ws ); |
| 221 | } | 224 | } |
| @@ -500,6 +503,15 @@ while( scanon ) { | |||
| 500 | 503 | ||
| 501 | g_now_seconds = time( NULL ); | 504 | g_now_seconds = time( NULL ); |
| 502 | 505 | ||
| 506 | /* Create our self pipe which allows us to interrupt mainloops | ||
| 507 | io_wait in case some data is available to send out */ | ||
| 508 | if( pipe( g_self_pipe ) == -1 ) | ||
| 509 | panic( "selfpipe failed: " ); | ||
| 510 | if( !io_fd( g_self_pipe[0] ) ) | ||
| 511 | panic( "selfpipe io_fd failed: " ); | ||
| 512 | io_setcookie( g_self_pipe[0], (void*)FLAG_SELFPIPE ); | ||
| 513 | io_wantread( g_self_pipe[0] ); | ||
| 514 | |||
| 503 | /* Init all sub systems. This call may fail with an exit() */ | 515 | /* Init all sub systems. This call may fail with an exit() */ |
| 504 | trackerlogic_init( ); | 516 | trackerlogic_init( ); |
| 505 | 517 | ||
