comparison src/event/ngx_event.c @ 7584:9d2ad2fb4423

SSL: available bytes handling (ticket #1431). Added code to track number of bytes available in the socket. This makes it possible to avoid looping for a long time while working with fast enough peer when data are added to the socket buffer faster than we are able to read and process data. When kernel does not provide number of bytes available, it is retrieved using ioctl(FIONREAD) as long as a buffer is filled by SSL_read(). It is assumed that number of bytes returned by SSL_read() is close to the number of bytes read from the socket, as we do not use SSL compression. But even if it is not true for some reason, this is not important, as we post an additional reading event anyway. Note that data can be buffered at SSL layer, and it is not possible to simply stop reading at some point and wait till the event will be reported by the kernel again. This can be only done when there are no data in SSL buffers, and there is no good way to find out if it's the case. Instead of trying to figure out if SSL buffers are empty, this patch introduces events posted for the next event loop iteration - such events will be processed only on the next event loop iteration, after going into the kernel and retrieving additional events. This seems to be simple and reliable approach.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 17 Oct 2019 16:02:24 +0300
parents 8f152ca81f5f
children 1ce3f01a4355
comparison
equal deleted inserted replaced
7583:efd71d49bde0 7584:9d2ad2fb4423
235 } 235 }
236 } 236 }
237 } 237 }
238 } 238 }
239 239
240 if (!ngx_queue_empty(&ngx_posted_next_events)) {
241 ngx_queue_add(&ngx_posted_events, &ngx_posted_next_events);
242 ngx_queue_init(&ngx_posted_next_events);
243 timer = 0;
244 }
245
240 delta = ngx_current_msec; 246 delta = ngx_current_msec;
241 247
242 (void) ngx_process_events(cycle, timer, flags); 248 (void) ngx_process_events(cycle, timer, flags);
243 249
244 delta = ngx_current_msec - delta; 250 delta = ngx_current_msec - delta;
637 ngx_use_accept_mutex = 0; 643 ngx_use_accept_mutex = 0;
638 644
639 #endif 645 #endif
640 646
641 ngx_queue_init(&ngx_posted_accept_events); 647 ngx_queue_init(&ngx_posted_accept_events);
648 ngx_queue_init(&ngx_posted_next_events);
642 ngx_queue_init(&ngx_posted_events); 649 ngx_queue_init(&ngx_posted_events);
643 650
644 if (ngx_event_timer_init(cycle->log) == NGX_ERROR) { 651 if (ngx_event_timer_init(cycle->log) == NGX_ERROR) {
645 return NGX_ERROR; 652 return NGX_ERROR;
646 } 653 }