Mercurial > hg > nginx
comparison src/os/unix/ngx_readv_chain.c @ 5882:ec81934727a1
Core: added limit to recv_chain().
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Tue, 28 Oct 2014 12:29:58 +0300 |
parents | a0a14319968b |
children | f01ab2dbcfdc |
comparison
equal
deleted
inserted
replaced
5881:ee9230cd4bda | 5882:ec81934727a1 |
---|---|
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_event.h> | 10 #include <ngx_event.h> |
11 | 11 |
12 | 12 |
13 ssize_t | 13 ssize_t |
14 ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain) | 14 ngx_readv_chain(ngx_connection_t *c, ngx_chain_t *chain, off_t limit) |
15 { | 15 { |
16 u_char *prev; | 16 u_char *prev; |
17 ssize_t n, size; | 17 ssize_t n, size; |
18 ngx_err_t err; | 18 ngx_err_t err; |
19 ngx_array_t vec; | 19 ngx_array_t vec; |
64 vec.pool = c->pool; | 64 vec.pool = c->pool; |
65 | 65 |
66 /* coalesce the neighbouring bufs */ | 66 /* coalesce the neighbouring bufs */ |
67 | 67 |
68 while (chain) { | 68 while (chain) { |
69 n = chain->buf->end - chain->buf->last; | |
70 | |
71 if (limit) { | |
72 if (size >= limit) { | |
73 break; | |
74 } | |
75 | |
76 if (size + n > limit) { | |
77 n = (ssize_t) (limit - size); | |
78 } | |
79 } | |
80 | |
69 if (prev == chain->buf->last) { | 81 if (prev == chain->buf->last) { |
70 iov->iov_len += chain->buf->end - chain->buf->last; | 82 iov->iov_len += n; |
71 | 83 |
72 } else { | 84 } else { |
73 if (vec.nelts >= IOV_MAX) { | 85 if (vec.nelts >= IOV_MAX) { |
74 break; | 86 break; |
75 } | 87 } |
78 if (iov == NULL) { | 90 if (iov == NULL) { |
79 return NGX_ERROR; | 91 return NGX_ERROR; |
80 } | 92 } |
81 | 93 |
82 iov->iov_base = (void *) chain->buf->last; | 94 iov->iov_base = (void *) chain->buf->last; |
83 iov->iov_len = chain->buf->end - chain->buf->last; | 95 iov->iov_len = n; |
84 } | 96 } |
85 | 97 |
86 size += chain->buf->end - chain->buf->last; | 98 size += n; |
87 prev = chain->buf->end; | 99 prev = chain->buf->end; |
88 chain = chain->next; | 100 chain = chain->next; |
89 } | 101 } |
90 | 102 |
91 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, | 103 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |