comparison src/os/unix/ngx_readv_chain.c @ 50:72eb30262aac NGINX_0_1_25

nginx 0.1.25 *) Bugfix: nginx did run on Linux parisc. *) Feature: nginx now does not start under FreeBSD if the sysctl kern.ipc.somaxconn value is too big. *) Bugfix: if a request was internally redirected by the ngx_http_index_module module to the ngx_http_proxy_module or ngx_http_fastcgi_module modules, then the index file was not closed after request completion. *) Feature: the "proxy_pass" can be used in location with regular expression. *) Feature: the ngx_http_rewrite_filter_module module supports the condition like "if ($HTTP_USER_AGENT ~ MSIE)". *) Bugfix: nginx started too slow if the large number of addresses and text values were used in the "geo" directive. *) Change: a variable name must be declared as "$name" in the "geo" directive. The previous variant without "$" is still supported, but will be removed soon. *) Feature: the "%{VARIABLE}v" logging parameter. *) Feature: the "set $name value" directive. *) Bugfix: gcc 4.0 compatibility. *) Feature: the --with-openssl-opt=OPTIONS autoconfiguration directive.
author Igor Sysoev <http://sysoev.ru>
date Sat, 19 Mar 2005 00:00:00 +0300
parents 6f8b0dc0f8dd
children dad2fe8ecf08
comparison
equal deleted inserted replaced
49:93dabbc9efb9 50:72eb30262aac
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_event.h> 9 #include <ngx_event.h>
10 10
11 11
12 #define NGX_IOVS 16
13
14
12 #if (NGX_HAVE_KQUEUE) 15 #if (NGX_HAVE_KQUEUE)
13 16
14 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) 17 ssize_t
18 ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
15 { 19 {
16 u_char *prev; 20 u_char *prev;
17 ssize_t n, size; 21 ssize_t n, size;
18 ngx_err_t err; 22 ngx_err_t err;
19 ngx_array_t io; 23 ngx_array_t vec;
20 ngx_event_t *rev; 24 ngx_event_t *rev;
21 struct iovec *iov; 25 struct iovec *iov, iovs[NGX_IOVS];
22 26
23 rev = c->read; 27 rev = c->read;
24 28
25 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 29 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
26 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 30 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
51 55
52 prev = NULL; 56 prev = NULL;
53 iov = NULL; 57 iov = NULL;
54 size = 0; 58 size = 0;
55 59
56 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR); 60 vec.elts = iovs;
61 vec.nelts = 0;
62 vec.size = sizeof(struct iovec);
63 vec.nalloc = NGX_IOVS;
64 vec.pool = c->pool;
57 65
58 /* coalesce the neighbouring bufs */ 66 /* coalesce the neighbouring bufs */
59 67
60 while (chain) { 68 while (chain) {
61 if (prev == chain->buf->last) { 69 if (prev == chain->buf->last) {
62 iov->iov_len += chain->buf->end - chain->buf->last; 70 iov->iov_len += chain->buf->end - chain->buf->last;
63 71
64 } else { 72 } else {
65 ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); 73 iov = ngx_array_push(&vec);
74 if (iov == NULL) {
75 return NGX_ERROR;
76 }
77
66 iov->iov_base = (void *) chain->buf->last; 78 iov->iov_base = (void *) chain->buf->last;
67 iov->iov_len = chain->buf->end - chain->buf->last; 79 iov->iov_len = chain->buf->end - chain->buf->last;
68 } 80 }
69 81
70 size += chain->buf->end - chain->buf->last; 82 size += chain->buf->end - chain->buf->last;
71 prev = chain->buf->end; 83 prev = chain->buf->end;
72 chain = chain->next; 84 chain = chain->next;
73 } 85 }
74 86
75 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 87 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
76 "readv: %d, last:%d", io.nelts, iov->iov_len); 88 "readv: %d, last:%d", vec.nelts, iov->iov_len);
77 89
78 rev = c->read; 90 rev = c->read;
79 91
80 do { 92 do {
81 n = readv(c->fd, (struct iovec *) io.elts, io.nelts); 93 n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
82 94
83 if (n >= 0) { 95 if (n >= 0) {
84 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) { 96 if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
85 rev->available -= n; 97 rev->available -= n;
86 98
136 return n; 148 return n;
137 } 149 }
138 150
139 #else /* ! NGX_HAVE_KQUEUE */ 151 #else /* ! NGX_HAVE_KQUEUE */
140 152
141 ssize_t ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) 153 ssize_t
154 ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain)
142 { 155 {
143 u_char *prev; 156 u_char *prev;
144 ssize_t n, size; 157 ssize_t n, size;
145 ngx_err_t err; 158 ngx_err_t err;
146 ngx_array_t io; 159 ngx_array_t vec;
147 ngx_event_t *rev; 160 ngx_event_t *rev;
148 struct iovec *iov; 161 struct iovec *iov, iovs[NGX_IOVS];
149 162
150 prev = NULL; 163 prev = NULL;
151 iov = NULL; 164 iov = NULL;
152 size = 0; 165 size = 0;
153 166
154 ngx_init_array(io, c->pool, 10, sizeof(struct iovec), NGX_ERROR); 167 vec.elts = iovs;
168 vec.nelts = 0;
169 vec.size = sizeof(struct iovec);
170 vec.nalloc = NGX_IOVS;
171 vec.pool = c->pool;
155 172
156 /* coalesce the neighbouring bufs */ 173 /* coalesce the neighbouring bufs */
157 174
158 while (chain) { 175 while (chain) {
159 if (prev == chain->buf->last) { 176 if (prev == chain->buf->last) {
160 iov->iov_len += chain->buf->end - chain->buf->last; 177 iov->iov_len += chain->buf->end - chain->buf->last;
161 178
162 } else { 179 } else {
163 ngx_test_null(iov, ngx_push_array(&io), NGX_ERROR); 180 iov = ngx_array_push(&vec);
181 if (iov == NULL) {
182 return NGX_ERROR;
183 }
184
164 iov->iov_base = chain->buf->last; 185 iov->iov_base = chain->buf->last;
165 iov->iov_len = chain->buf->end - chain->buf->last; 186 iov->iov_len = chain->buf->end - chain->buf->last;
166 } 187 }
167 188
168 size += chain->buf->end - chain->buf->last; 189 size += chain->buf->end - chain->buf->last;
169 prev = chain->buf->end; 190 prev = chain->buf->end;
170 chain = chain->next; 191 chain = chain->next;
171 } 192 }
172 193
173 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, 194 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
174 "readv: %d:%d", io.nelts, iov->iov_len); 195 "readv: %d:%d", vec.nelts, iov->iov_len);
175 196
176 rev = c->read; 197 rev = c->read;
177 198
178 do { 199 do {
179 n = readv(c->fd, (struct iovec *) io.elts, io.nelts); 200 n = readv(c->fd, (struct iovec *) vec.elts, vec.nelts);
180 201
181 if (n == 0) { 202 if (n == 0) {
182 rev->ready = 0; 203 rev->ready = 0;
183 rev->eof = 1; 204 rev->eof = 1;
184 205