comparison src/os/unix/ngx_files.c @ 646:615b5ea36fc0 NGINX_1_1_7

nginx 1.1.7 *) Feature: support of several resolvers in the "resolver" directive. Thanks to Kirill A. Korinskiy. *) Bugfix: a segmentation fault occurred on start or while reconfiguration if the "ssl" directive was used at http level and there was no "ssl_certificate" defined. *) Bugfix: reduced memory consumption while proxying of big files if they were buffered to disk. *) Bugfix: a segmentation fault might occur in a worker process if "proxy_http_version 1.1" directive was used. *) Bugfix: in the "expires @time" directive.
author Igor Sysoev <http://sysoev.ru>
date Mon, 31 Oct 2011 00:00:00 +0400
parents bb20316269e4
children 4d05413aebad
comparison
equal deleted inserted replaced
645:e461dead01e9 646:615b5ea36fc0
151 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset, 151 ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
152 ngx_pool_t *pool) 152 ngx_pool_t *pool)
153 { 153 {
154 u_char *prev; 154 u_char *prev;
155 size_t size; 155 size_t size;
156 ssize_t n; 156 ssize_t total, n;
157 ngx_array_t vec; 157 ngx_array_t vec;
158 struct iovec *iov, iovs[NGX_IOVS]; 158 struct iovec *iov, iovs[NGX_IOVS];
159 159
160 /* use pwrite() if there is the only buf in a chain */ 160 /* use pwrite() if there is the only buf in a chain */
161 161
162 if (cl->next == NULL) { 162 if (cl->next == NULL) {
163 return ngx_write_file(file, cl->buf->pos, 163 return ngx_write_file(file, cl->buf->pos,
164 (size_t) (cl->buf->last - cl->buf->pos), 164 (size_t) (cl->buf->last - cl->buf->pos),
165 offset); 165 offset);
166 } 166 }
167
168 total = 0;
167 169
168 vec.elts = iovs; 170 vec.elts = iovs;
169 vec.size = sizeof(struct iovec); 171 vec.size = sizeof(struct iovec);
170 vec.nalloc = NGX_IOVS; 172 vec.nalloc = NGX_IOVS;
171 vec.pool = pool; 173 vec.pool = pool;
200 202
201 /* use pwrite() if there is the only iovec buffer */ 203 /* use pwrite() if there is the only iovec buffer */
202 204
203 if (vec.nelts == 1) { 205 if (vec.nelts == 1) {
204 iov = vec.elts; 206 iov = vec.elts;
205 return ngx_write_file(file, (u_char *) iov[0].iov_base, 207
206 iov[0].iov_len, offset); 208 n = ngx_write_file(file, (u_char *) iov[0].iov_base,
209 iov[0].iov_len, offset);
210
211 if (n == NGX_ERROR) {
212 return n;
213 }
214
215 return total + n;
207 } 216 }
208 217
209 if (file->sys_offset != offset) { 218 if (file->sys_offset != offset) {
210 if (lseek(file->fd, offset, SEEK_SET) == -1) { 219 if (lseek(file->fd, offset, SEEK_SET) == -1) {
211 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno, 220 ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
231 return NGX_ERROR; 240 return NGX_ERROR;
232 } 241 }
233 242
234 file->sys_offset += n; 243 file->sys_offset += n;
235 file->offset += n; 244 file->offset += n;
245 total += n;
236 246
237 } while (cl); 247 } while (cl);
238 248
239 return n; 249 return total;
240 } 250 }
241 251
242 252
243 ngx_int_t 253 ngx_int_t
244 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s) 254 ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)