mirror of
https://github.com/nginx/nginx.git
synced 2026-11-19 22:56:26 +00:00
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.
This commit is contained in:
parent
3a8f4c1141
commit
b993b9ded7
1 changed files with 14 additions and 4 deletions
|
|
@ -153,7 +153,7 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
|
|||
{
|
||||
u_char *prev;
|
||||
size_t size;
|
||||
ssize_t n;
|
||||
ssize_t total, n;
|
||||
ngx_array_t vec;
|
||||
struct iovec *iov, iovs[NGX_IOVS];
|
||||
|
||||
|
|
@ -165,6 +165,8 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
|
|||
offset);
|
||||
}
|
||||
|
||||
total = 0;
|
||||
|
||||
vec.elts = iovs;
|
||||
vec.size = sizeof(struct iovec);
|
||||
vec.nalloc = NGX_IOVS;
|
||||
|
|
@ -202,8 +204,15 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
|
|||
|
||||
if (vec.nelts == 1) {
|
||||
iov = vec.elts;
|
||||
return ngx_write_file(file, (u_char *) iov[0].iov_base,
|
||||
iov[0].iov_len, offset);
|
||||
|
||||
n = ngx_write_file(file, (u_char *) iov[0].iov_base,
|
||||
iov[0].iov_len, offset);
|
||||
|
||||
if (n == NGX_ERROR) {
|
||||
return n;
|
||||
}
|
||||
|
||||
return total + n;
|
||||
}
|
||||
|
||||
if (file->sys_offset != offset) {
|
||||
|
|
@ -233,10 +242,11 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
|
|||
|
||||
file->sys_offset += n;
|
||||
file->offset += n;
|
||||
total += n;
|
||||
|
||||
} while (cl);
|
||||
|
||||
return n;
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue