Mercurial > hg > nginx
annotate src/os/unix/ngx_recv.c @ 9320:cf73b65983c2 default tip
release-1.27.3 tag
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 13 Aug 2024 17:26:33 +0300 |
parents | 5119c8150478 |
children |
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:
375
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:
375
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:
375
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:
375
diff
changeset
|
6 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
96
diff
changeset
|
10 #include <ngx_event.h> |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
11 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
1680 | 13 ssize_t |
14 ngx_unix_recv(ngx_connection_t *c, u_char *buf, size_t size) | |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 { |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 ssize_t n; |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
17 ngx_err_t err; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
18 ngx_event_t *rev; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
19 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
20 rev = c->read; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 |
6507
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
22 #if (NGX_HAVE_KQUEUE) |
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
23 |
455 | 24 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
25 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
26 "recv: eof:%d, avail:%d, err:%d", |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
328
diff
changeset
|
27 rev->pending_eof, rev->available, rev->kq_errno); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
29 if (rev->available == 0) { |
587 | 30 if (rev->pending_eof) { |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
31 rev->ready = 0; |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
32 rev->eof = 1; |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
33 |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
34 if (rev->kq_errno) { |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
35 rev->error = 1; |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
36 ngx_set_socket_errno(rev->kq_errno); |
218
05592fd7a436
nginx-0.0.1-2004-01-05-23:55:48 import
Igor Sysoev <igor@sysoev.ru>
parents:
188
diff
changeset
|
37 |
537 | 38 return ngx_connection_error(c, rev->kq_errno, |
39 "kevent() reported about an closed connection"); | |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
40 } |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
41 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
42 return 0; |
587 | 43 |
44 } else { | |
1875
c11d96cbad75
reset ready flag if no data is available,
Igor Sysoev <igor@sysoev.ru>
parents:
1681
diff
changeset
|
45 rev->ready = 0; |
587 | 46 return NGX_AGAIN; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
47 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
49 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 |
6507
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
51 #endif |
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
52 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
53 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
54 |
8018
5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball <marcus.ball@live.com>
parents:
7583
diff
changeset
|
55 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) |
5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball <marcus.ball@live.com>
parents:
7583
diff
changeset
|
56 && ngx_use_epoll_rdhup) |
5119c8150478
Fixed runtime handling of systems without EPOLLRDHUP support.
Marcus Ball <marcus.ball@live.com>
parents:
7583
diff
changeset
|
57 { |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
58 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
59 "recv: eof:%d, avail:%d", |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
60 rev->pending_eof, rev->available); |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
61 |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
62 if (rev->available == 0 && !rev->pending_eof) { |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
63 rev->ready = 0; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
64 return NGX_AGAIN; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
65 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
66 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
67 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
68 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
69 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
70 do { |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
71 n = recv(c->fd, buf, size, 0); |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
72 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
73 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
6480 | 74 "recv: fd:%d %z of %uz", c->fd, n, size); |
93
738fe44c70d5
nginx-0.0.1-2003-05-21-17:28:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
91
diff
changeset
|
75 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
76 if (n == 0) { |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
77 rev->ready = 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
78 rev->eof = 1; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
79 |
6507
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
80 #if (NGX_HAVE_KQUEUE) |
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
81 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
82 /* |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
83 * on FreeBSD recv() may return 0 on closed socket |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
84 * even if kqueue reported about available data |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
85 */ |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
86 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
87 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
88 rev->available = 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
89 } |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
90 |
6507
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
91 #endif |
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
92 |
6506
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
93 return 0; |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
94 } |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
95 |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
96 if (n > 0) { |
dc1ae0056a1e
Fixed small inconsistency in handling EOF among receive functions.
Valentin Bartenev <vbart@nginx.com>
parents:
6480
diff
changeset
|
97 |
6507
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
98 #if (NGX_HAVE_KQUEUE) |
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
99 |
455 | 100 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
101 rev->available -= n; |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
102 |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
103 /* |
583 | 104 * rev->available may be negative here because some additional |
587 | 105 * bytes may be received between kevent() and recv() |
163
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
106 */ |
fb61ba77beba
nginx-0.0.1-2003-10-28-18:45:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
148
diff
changeset
|
107 |
144
ef8c87afcfc5
nginx-0.0.1-2003-10-12-20:49:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
108 if (rev->available <= 0) { |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
328
diff
changeset
|
109 if (!rev->pending_eof) { |
148
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
110 rev->ready = 0; |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
111 } |
5afee0074707
nginx-0.0.1-2003-10-17-00:19:16 import
Igor Sysoev <igor@sysoev.ru>
parents:
144
diff
changeset
|
112 |
6508
151fd02a4317
Simplified ngx_unix_recv() and ngx_readv_chain().
Ruslan Ermilov <ru@nginx.com>
parents:
6507
diff
changeset
|
113 rev->available = 0; |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
114 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
115 |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
116 return n; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
117 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
118 |
6507
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
119 #endif |
8ee94ecd3a50
Merged implementations of ngx_unix_recv().
Valentin Bartenev <vbart@nginx.com>
parents:
6506
diff
changeset
|
120 |
7583
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
121 #if (NGX_HAVE_FIONREAD) |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
122 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
123 if (rev->available >= 0) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
124 rev->available -= n; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
125 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
126 /* |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
127 * negative rev->available means some additional bytes |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
128 * were received between kernel notification and recv(), |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
129 * and therefore ev->ready can be safely reset even for |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
130 * edge-triggered event methods |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
131 */ |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
132 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
133 if (rev->available < 0) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
134 rev->available = 0; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
135 rev->ready = 0; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
136 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
137 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
138 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
139 "recv: avail:%d", rev->available); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
140 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
141 } else if ((size_t) n == size) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
142 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
143 if (ngx_socket_nread(c->fd, &rev->available) == -1) { |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
144 n = ngx_connection_error(c, ngx_socket_errno, |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
145 ngx_socket_nread_n " failed"); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
146 break; |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
147 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
148 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
149 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
150 "recv: avail:%d", rev->available); |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
151 } |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
152 |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
153 #endif |
efd71d49bde0
Events: available bytes calculation via ioctl(FIONREAD).
Maxim Dounin <mdounin@mdounin.ru>
parents:
6536
diff
changeset
|
154 |
6536
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
155 #if (NGX_HAVE_EPOLLRDHUP) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
156 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
157 if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
158 && ngx_use_epoll_rdhup) |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
159 { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
160 if ((size_t) n < size) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
161 if (!rev->pending_eof) { |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
162 rev->ready = 0; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
163 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
164 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
165 rev->available = 0; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
166 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
167 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
168 return n; |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
169 } |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
170 |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
171 #endif |
f7849bfb6d21
Improved EPOLLRDHUP handling.
Valentin Bartenev <vbart@nginx.com>
parents:
6508
diff
changeset
|
172 |
5267
13c006f0c40e
Events: honor NGX_USE_GREEDY_EVENT when kqueue support is enabled.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
173 if ((size_t) n < size |
13c006f0c40e
Events: honor NGX_USE_GREEDY_EVENT when kqueue support is enabled.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
174 && !(ngx_event_flags & NGX_USE_GREEDY_EVENT)) |
13c006f0c40e
Events: honor NGX_USE_GREEDY_EVENT when kqueue support is enabled.
Valentin Bartenev <vbart@nginx.com>
parents:
4412
diff
changeset
|
175 { |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
176 rev->ready = 0; |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
177 } |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
178 |
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
93
diff
changeset
|
179 return n; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
180 } |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
181 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
182 err = ngx_socket_errno; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
183 |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
184 if (err == NGX_EAGAIN || err == NGX_EINTR) { |
257
70e1c7d2b83d
nginx-0.0.2-2004-02-11-20:08:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
256
diff
changeset
|
185 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err, |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
186 "recv() not ready"); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
187 n = NGX_AGAIN; |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
188 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
189 } else { |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
190 n = ngx_connection_error(c, err, "recv() failed"); |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
191 break; |
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
192 } |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
193 |
253
b6793bc5034b
nginx-0.0.2-2004-02-09-10:46:43 import
Igor Sysoev <igor@sysoev.ru>
parents:
218
diff
changeset
|
194 } while (err == NGX_EINTR); |
188
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
195 |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
196 rev->ready = 0; |
0061d1f0908d
nginx-0.0.1-2003-11-18-11:04:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
184
diff
changeset
|
197 |
3642 | 198 if (n == NGX_ERROR) { |
184
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
199 rev->error = 1; |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
200 } |
1bf718ce0dde
nginx-0.0.1-2003-11-14-10:20:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
163
diff
changeset
|
201 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
202 return n; |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
203 } |