diff options
| author | Dirk Engling <erdgeist@erdgeist.org> | 2024-04-13 00:47:29 +0200 |
|---|---|---|
| committer | Dirk Engling <erdgeist@erdgeist.org> | 2024-04-13 00:47:29 +0200 |
| commit | 1a70d9f9ef81ac1b5e843ac71f3538f7845e03ae (patch) | |
| tree | 20a20077503c01dc024e88a6a8d82bf89faf22fd /opentracker.c | |
| parent | 301faeb10c5994a6fd31adc5f0b4f8f2b5c23502 (diff) | |
First shot on chunked transfers
Diffstat (limited to 'opentracker.c')
| -rw-r--r-- | opentracker.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/opentracker.c b/opentracker.c index 7c67f26..73a3ff3 100644 --- a/opentracker.c +++ b/opentracker.c | |||
| @@ -79,6 +79,7 @@ static void defaul_signal_handlers( void ) { | |||
| 79 | sigaddset (&signal_mask, SIGPIPE); | 79 | sigaddset (&signal_mask, SIGPIPE); |
| 80 | sigaddset (&signal_mask, SIGHUP); | 80 | sigaddset (&signal_mask, SIGHUP); |
| 81 | sigaddset (&signal_mask, SIGINT); | 81 | sigaddset (&signal_mask, SIGINT); |
| 82 | sigaddset (&signal_mask, SIGALRM); | ||
| 82 | pthread_sigmask (SIG_BLOCK, &signal_mask, NULL); | 83 | pthread_sigmask (SIG_BLOCK, &signal_mask, NULL); |
| 83 | } | 84 | } |
| 84 | 85 | ||
| @@ -90,7 +91,7 @@ static void install_signal_handlers( void ) { | |||
| 90 | sa.sa_handler = signal_handler; | 91 | sa.sa_handler = signal_handler; |
| 91 | sigemptyset(&sa.sa_mask); | 92 | sigemptyset(&sa.sa_mask); |
| 92 | sa.sa_flags = SA_RESTART; | 93 | sa.sa_flags = SA_RESTART; |
| 93 | if ((sigaction(SIGINT, &sa, NULL) == -1)) | 94 | if ((sigaction(SIGINT, &sa, NULL) == -1) || (sigaction(SIGALRM, &sa, NULL) == -1) ) |
| 94 | panic( "install_signal_handlers" ); | 95 | panic( "install_signal_handlers" ); |
| 95 | 96 | ||
| 96 | sigaddset (&signal_mask, SIGINT); | 97 | sigaddset (&signal_mask, SIGINT); |
| @@ -208,15 +209,23 @@ static void handle_read( const int64 sock, struct ot_workstruct *ws ) { | |||
| 208 | static void handle_write( const int64 sock ) { | 209 | static void handle_write( const int64 sock ) { |
| 209 | struct http_data* cookie=io_getcookie( sock ); | 210 | struct http_data* cookie=io_getcookie( sock ); |
| 210 | size_t i; | 211 | size_t i; |
| 212 | int chunked = 0; | ||
| 211 | 213 | ||
| 212 | /* Look for the first io_batch still containing bytes to write */ | 214 | /* Look for the first io_batch still containing bytes to write */ |
| 213 | if( cookie ) | 215 | if( cookie ) { |
| 214 | for( i = 0; i < cookie->batches; ++i ) | 216 | if( cookie->flag & STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER ) |
| 217 | chunked = 1; | ||
| 218 | |||
| 219 | for( i = 0; i < cookie->batches; ++i ) { | ||
| 220 | fprintf(stderr, "handle_write inspects batch %d of %d (bytes left: %d)\n", i, cookie->batches, cookie->batch[i].bytesleft); | ||
| 215 | if( cookie->batch[i].bytesleft ) { | 221 | if( cookie->batch[i].bytesleft ) { |
| 216 | int64 res = iob_send( sock, cookie->batch + i ); | 222 | int64 res = iob_send( sock, cookie->batch + i ); |
| 217 | 223 | ||
| 218 | if( res == -3 ) | 224 | fprintf(stderr, "handle_write yields res %lld when trying to iob_send\n", res); |
| 219 | break; | 225 | if( res == -3 ) { |
| 226 | handle_dead( sock ); | ||
| 227 | return; | ||
| 228 | } | ||
| 220 | 229 | ||
| 221 | if( !cookie->batch[i].bytesleft ) | 230 | if( !cookie->batch[i].bytesleft ) |
| 222 | continue; | 231 | continue; |
| @@ -224,8 +233,17 @@ static void handle_write( const int64 sock ) { | |||
| 224 | if( res == -1 || res > 0 || i < cookie->batches - 1 ) | 233 | if( res == -1 || res > 0 || i < cookie->batches - 1 ) |
| 225 | return; | 234 | return; |
| 226 | } | 235 | } |
| 236 | } | ||
| 237 | } | ||
| 227 | 238 | ||
| 228 | handle_dead( sock ); | 239 | /* In a chunked transfer after all batches accumulated have been sent, wait for the next one */ |
| 240 | if( chunked ) { | ||
| 241 | //fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => dont want write on sock %lld\n", sock); | ||
| 242 | //io_dontwantwrite( sock ); | ||
| 243 | } else { | ||
| 244 | fprintf( stderr, "handle_write is STRUCT_HTTP_FLAG_CHUNKED_IN_TRANSFER => handle dead on sock %lld\n", sock); | ||
| 245 | handle_dead( sock ); | ||
| 246 | } | ||
| 229 | } | 247 | } |
| 230 | 248 | ||
| 231 | static void handle_accept( const int64 serversocket ) { | 249 | static void handle_accept( const int64 serversocket ) { |
| @@ -266,7 +284,7 @@ static void * server_mainloop( void * args ) { | |||
| 266 | struct ot_workstruct ws; | 284 | struct ot_workstruct ws; |
| 267 | time_t next_timeout_check = g_now_seconds + OT_CLIENT_TIMEOUT_CHECKINTERVAL; | 285 | time_t next_timeout_check = g_now_seconds + OT_CLIENT_TIMEOUT_CHECKINTERVAL; |
| 268 | struct iovec *iovector; | 286 | struct iovec *iovector; |
| 269 | int iovec_entries; | 287 | int iovec_entries, is_partial; |
| 270 | 288 | ||
| 271 | (void)args; | 289 | (void)args; |
| 272 | 290 | ||
| @@ -305,8 +323,8 @@ static void * server_mainloop( void * args ) { | |||
| 305 | handle_read( sock, &ws ); | 323 | handle_read( sock, &ws ); |
| 306 | } | 324 | } |
| 307 | 325 | ||
| 308 | while( ( sock = mutex_workqueue_popresult( &iovec_entries, &iovector ) ) != -1 ) | 326 | while( ( sock = mutex_workqueue_popresult( &iovec_entries, &iovector, &is_partial ) ) != -1 ) |
| 309 | http_sendiovecdata( sock, &ws, iovec_entries, iovector ); | 327 | http_sendiovecdata( sock, &ws, iovec_entries, iovector, is_partial ); |
| 310 | 328 | ||
| 311 | while( ( sock = io_canwrite( ) ) != -1 ) | 329 | while( ( sock = io_canwrite( ) ) != -1 ) |
| 312 | handle_write( sock ); | 330 | handle_write( sock ); |
| @@ -318,9 +336,6 @@ static void * server_mainloop( void * args ) { | |||
| 318 | } | 336 | } |
| 319 | 337 | ||
| 320 | livesync_ticker(); | 338 | livesync_ticker(); |
| 321 | |||
| 322 | /* Enforce setting the clock */ | ||
| 323 | signal_handler( SIGALRM ); | ||
| 324 | } | 339 | } |
| 325 | return 0; | 340 | return 0; |
| 326 | } | 341 | } |
