Mercurial > hg > nginx
comparison src/os/unix/ngx_freebsd_sendfile_chain.c @ 4596:089cc5154c1e
IOV_MAX handling microoptimization.
We now stop on IOV_MAX iovec entries only if we are going to add new one,
i.e. next buffer can't be coalesced into last iovec.
This also fixes incorrect checks for trailer creation on FreeBSD and
Mac OS X, header.nelts was checked instead of trailer.nelts.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 17 Apr 2012 09:13:15 +0000 |
parents | 67653855682e |
children | ad137a80919f |
comparison
equal
deleted
inserted
replaced
4595:6cd5d4a279d6 | 4596:089cc5154c1e |
---|---|
105 /* create the header iovec and coalesce the neighbouring bufs */ | 105 /* create the header iovec and coalesce the neighbouring bufs */ |
106 | 106 |
107 prev = NULL; | 107 prev = NULL; |
108 iov = NULL; | 108 iov = NULL; |
109 | 109 |
110 for (cl = in; | 110 for (cl = in; cl && send < limit; cl = cl->next) { |
111 cl && header.nelts < IOV_MAX && send < limit; | 111 |
112 cl = cl->next) | |
113 { | |
114 if (ngx_buf_special(cl->buf)) { | 112 if (ngx_buf_special(cl->buf)) { |
115 continue; | 113 continue; |
116 } | 114 } |
117 | 115 |
118 if (!ngx_buf_in_memory_only(cl->buf)) { | 116 if (!ngx_buf_in_memory_only(cl->buf)) { |
127 | 125 |
128 if (prev == cl->buf->pos) { | 126 if (prev == cl->buf->pos) { |
129 iov->iov_len += (size_t) size; | 127 iov->iov_len += (size_t) size; |
130 | 128 |
131 } else { | 129 } else { |
130 if (header.nelts >= IOV_MAX){ | |
131 break; | |
132 } | |
133 | |
132 iov = ngx_array_push(&header); | 134 iov = ngx_array_push(&header); |
133 if (iov == NULL) { | 135 if (iov == NULL) { |
134 return NGX_CHAIN_ERROR; | 136 return NGX_CHAIN_ERROR; |
135 } | 137 } |
136 | 138 |
181 /* create the trailer iovec and coalesce the neighbouring bufs */ | 183 /* create the trailer iovec and coalesce the neighbouring bufs */ |
182 | 184 |
183 prev = NULL; | 185 prev = NULL; |
184 iov = NULL; | 186 iov = NULL; |
185 | 187 |
186 while (cl && header.nelts < IOV_MAX && send < limit) { | 188 while (cl && send < limit) { |
187 | 189 |
188 if (ngx_buf_special(cl->buf)) { | 190 if (ngx_buf_special(cl->buf)) { |
189 cl = cl->next; | 191 cl = cl->next; |
190 continue; | 192 continue; |
191 } | 193 } |
202 | 204 |
203 if (prev == cl->buf->pos) { | 205 if (prev == cl->buf->pos) { |
204 iov->iov_len += (size_t) size; | 206 iov->iov_len += (size_t) size; |
205 | 207 |
206 } else { | 208 } else { |
209 if (trailer.nelts >= IOV_MAX){ | |
210 break; | |
211 } | |
212 | |
207 iov = ngx_array_push(&trailer); | 213 iov = ngx_array_push(&trailer); |
208 if (iov == NULL) { | 214 if (iov == NULL) { |
209 return NGX_CHAIN_ERROR; | 215 return NGX_CHAIN_ERROR; |
210 } | 216 } |
211 | 217 |