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.
Maxim Dounin
10 years ago
102 | 102 | prev = NULL; |
103 | 103 | iov = NULL; |
104 | 104 | |
105 | for (cl = in; | |
106 | cl && header.nelts < IOV_MAX && send < limit; | |
107 | cl = cl->next) | |
108 | { | |
105 | for (cl = in; cl && send < limit; cl = cl->next) { | |
106 | ||
109 | 107 | if (ngx_buf_special(cl->buf)) { |
110 | 108 | continue; |
111 | 109 | } |
124 | 122 | iov->iov_len += (size_t) size; |
125 | 123 | |
126 | 124 | } else { |
125 | if (header.nelts >= IOV_MAX) { | |
126 | break; | |
127 | } | |
128 | ||
127 | 129 | iov = ngx_array_push(&header); |
128 | 130 | if (iov == NULL) { |
129 | 131 | return NGX_CHAIN_ERROR; |
177 | 179 | prev = NULL; |
178 | 180 | iov = NULL; |
179 | 181 | |
180 | while (cl && header.nelts < IOV_MAX && send < limit) { | |
182 | while (cl && send < limit) { | |
181 | 183 | |
182 | 184 | if (ngx_buf_special(cl->buf)) { |
183 | 185 | cl = cl->next; |
198 | 200 | iov->iov_len += (size_t) size; |
199 | 201 | |
200 | 202 | } else { |
203 | if (trailer.nelts >= IOV_MAX) { | |
204 | break; | |
205 | } | |
206 | ||
201 | 207 | iov = ngx_array_push(&trailer); |
202 | 208 | if (iov == NULL) { |
203 | 209 | return NGX_CHAIN_ERROR; |
106 | 106 | prev = NULL; |
107 | 107 | iov = NULL; |
108 | 108 | |
109 | for (cl = in; | |
110 | cl && header.nelts < IOV_MAX && send < limit; | |
111 | cl = cl->next) | |
112 | { | |
109 | for (cl = in; cl && send < limit; cl = cl->next) { | |
110 | ||
113 | 111 | if (ngx_buf_special(cl->buf)) { |
114 | 112 | continue; |
115 | 113 | } |
128 | 126 | iov->iov_len += (size_t) size; |
129 | 127 | |
130 | 128 | } else { |
129 | if (header.nelts >= IOV_MAX){ | |
130 | break; | |
131 | } | |
132 | ||
131 | 133 | iov = ngx_array_push(&header); |
132 | 134 | if (iov == NULL) { |
133 | 135 | return NGX_CHAIN_ERROR; |
182 | 184 | prev = NULL; |
183 | 185 | iov = NULL; |
184 | 186 | |
185 | while (cl && header.nelts < IOV_MAX && send < limit) { | |
187 | while (cl && send < limit) { | |
186 | 188 | |
187 | 189 | if (ngx_buf_special(cl->buf)) { |
188 | 190 | cl = cl->next; |
203 | 205 | iov->iov_len += (size_t) size; |
204 | 206 | |
205 | 207 | } else { |
208 | if (trailer.nelts >= IOV_MAX){ | |
209 | break; | |
210 | } | |
211 | ||
206 | 212 | iov = ngx_array_push(&trailer); |
207 | 213 | if (iov == NULL) { |
208 | 214 | return NGX_CHAIN_ERROR; |
88 | 88 | |
89 | 89 | /* create the iovec and coalesce the neighbouring bufs */ |
90 | 90 | |
91 | for (cl = in; | |
92 | cl && header.nelts < IOV_MAX && send < limit; | |
93 | cl = cl->next) | |
94 | { | |
91 | for (cl = in; cl && send < limit; cl = cl->next) { | |
92 | ||
95 | 93 | if (ngx_buf_special(cl->buf)) { |
96 | 94 | continue; |
97 | 95 | } |
131 | 129 | iov->iov_len += (size_t) size; |
132 | 130 | |
133 | 131 | } else { |
132 | if (header.nelts >= IOV_MAX) { | |
133 | break; | |
134 | } | |
135 | ||
134 | 136 | iov = ngx_array_push(&header); |
135 | 137 | if (iov == NULL) { |
136 | 138 | return NGX_CHAIN_ERROR; |
93 | 93 | |
94 | 94 | /* create the sendfilevec and coalesce the neighbouring bufs */ |
95 | 95 | |
96 | for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next) | |
97 | { | |
96 | for (cl = in; cl && send < limit; cl = cl->next) { | |
97 | ||
98 | 98 | if (ngx_buf_special(cl->buf)) { |
99 | 99 | continue; |
100 | 100 | } |
112 | 112 | sfv->sfv_len += (size_t) size; |
113 | 113 | |
114 | 114 | } else { |
115 | if (vec.nelts >= IOV_MAX) { | |
116 | break; | |
117 | } | |
118 | ||
115 | 119 | sfv = ngx_array_push(&vec); |
116 | 120 | if (sfv == NULL) { |
117 | 121 | return NGX_CHAIN_ERROR; |
146 | 150 | sfv->sfv_len += (size_t) size; |
147 | 151 | |
148 | 152 | } else { |
153 | if (vec.nelts >= IOV_MAX) { | |
154 | break; | |
155 | } | |
156 | ||
149 | 157 | sfv = ngx_array_push(&vec); |
150 | 158 | if (sfv == NULL) { |
151 | 159 | return NGX_CHAIN_ERROR; |
70 | 70 | |
71 | 71 | /* create the iovec and coalesce the neighbouring bufs */ |
72 | 72 | |
73 | for (cl = in; cl && vec.nelts < IOV_MAX && send < limit; cl = cl->next) | |
74 | { | |
73 | for (cl = in; cl && send < limit; cl = cl->next) { | |
74 | ||
75 | 75 | if (ngx_buf_special(cl->buf)) { |
76 | 76 | continue; |
77 | 77 | } |
92 | 92 | iov->iov_len += size; |
93 | 93 | |
94 | 94 | } else { |
95 | if (vec.nelts >= IOV_MAX) { | |
96 | break; | |
97 | } | |
98 | ||
95 | 99 | iov = ngx_array_push(&vec); |
96 | 100 | if (iov == NULL) { |
97 | 101 | return NGX_CHAIN_ERROR; |