Mercurial > hg > nginx
comparison src/os/unix/ngx_files.c @ 4351:d1d34de1a419 stable-1.0
Merge of r4221, r4222:
Fixed unix ngx_write_chain_to_file() to return total bytes written.
Previously result of last iteration's writev() was returned. This was
unnoticed as return value was only used if chain contained only one or
two buffers.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 13 Dec 2011 18:59:18 +0000 |
parents | cf80c0b0109a |
children | cdb2e95bd3d0 |
comparison
equal
deleted
inserted
replaced
4350:ea0f2e1f84d4 | 4351:d1d34de1a419 |
---|---|
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) |