Moved file writev() handling code to a separate function.

No functional changes.
This commit is contained in:
Valentin Bartenev 2015-11-17 19:01:41 +03:00
parent a9e62b625b
commit 906c4462f8

View File

@ -14,6 +14,9 @@
static void ngx_thread_read_handler(void *data, ngx_log_t *log);
#endif
static ssize_t ngx_writev_file(ngx_file_t *file, ngx_array_t *vec, size_t size,
off_t offset);
#if (NGX_HAVE_FILE_AIO)
@ -282,7 +285,6 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
u_char *prev;
size_t size;
ssize_t total, n;
ngx_err_t err;
ngx_array_t vec;
struct iovec *iov, iovs[NGX_IOVS];
@ -344,6 +346,27 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
return total + n;
}
n = ngx_writev_file(file, &vec, size, offset);
if (n == NGX_ERROR) {
return n;
}
offset += n;
total += n;
} while (cl);
return total;
}
static ssize_t
ngx_writev_file(ngx_file_t *file, ngx_array_t *vec, size_t size, off_t offset)
{
ssize_t n;
ngx_err_t err;
if (file->sys_offset != offset) {
if (lseek(file->fd, offset, SEEK_SET) == -1) {
ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
@ -356,7 +379,7 @@ ngx_write_chain_to_file(ngx_file_t *file, ngx_chain_t *cl, off_t offset,
eintr:
n = writev(file->fd, vec.elts, vec.nelts);
n = writev(file->fd, vec->elts, vec->nelts);
if (n == -1) {
err = ngx_errno;
@ -384,12 +407,8 @@ eintr:
file->sys_offset += n;
file->offset += n;
offset += n;
total += n;
} while (cl);
return total;
return n;
}