Mercurial > hg > nginx
annotate src/event/ngx_event_posted.h @ 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 | 3d4730eada9c |
children | 1ce3f01a4355 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
6 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
377
diff
changeset
|
7 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #ifndef _NGX_EVENT_POSTED_H_INCLUDED_ |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #define _NGX_EVENT_POSTED_H_INCLUDED_ |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 #include <ngx_config.h> |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 #include <ngx_core.h> |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 #include <ngx_event.h> |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
17 #define ngx_post_event(ev, q) \ |
563 | 18 \ |
6060
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
19 if (!(ev)->posted) { \ |
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
20 (ev)->posted = 1; \ |
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
21 ngx_queue_insert_tail(q, &(ev)->queue); \ |
563 | 22 \ |
6060
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
23 ngx_log_debug1(NGX_LOG_DEBUG_CORE, (ev)->log, 0, "post event %p", ev);\ |
563 | 24 \ |
25 } else { \ | |
6060
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
26 ngx_log_debug1(NGX_LOG_DEBUG_CORE, (ev)->log, 0, \ |
563 | 27 "update posted event %p", ev); \ |
28 } | |
29 | |
30 | |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
374
diff
changeset
|
31 #define ngx_delete_posted_event(ev) \ |
563 | 32 \ |
6060
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
33 (ev)->posted = 0; \ |
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
34 ngx_queue_remove(&(ev)->queue); \ |
563 | 35 \ |
6060
3d4730eada9c
Events: made posted events macros safe.
Valentin Bartenev <vbart@nginx.com>
parents:
5821
diff
changeset
|
36 ngx_log_debug1(NGX_LOG_DEBUG_CORE, (ev)->log, 0, \ |
563 | 37 "delete posted event %p", ev); |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
374
diff
changeset
|
38 |
373
018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
372
diff
changeset
|
39 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
40 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
41 void ngx_event_process_posted(ngx_cycle_t *cycle, ngx_queue_t *posted); |
563 | 42 |
43 | |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
44 extern ngx_queue_t ngx_posted_accept_events; |
7584
9d2ad2fb4423
SSL: available bytes handling (ticket #1431).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6060
diff
changeset
|
45 extern ngx_queue_t ngx_posted_next_events; |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
46 extern ngx_queue_t ngx_posted_events; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
47 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 #endif /* _NGX_EVENT_POSTED_H_INCLUDED_ */ |