[nginx] Moved file writev() handling code to a separate function.
Valentin Bartenev
vbart at nginx.com
Tue Nov 17 16:02:21 UTC 2015
details: http://hg.nginx.org/nginx/rev/be6af0906a4d
branches:
changeset: 6300:be6af0906a4d
user: Valentin Bartenev <vbart at nginx.com>
date: Tue Nov 17 19:01:41 2015 +0300
description:
Moved file writev() handling code to a separate function.
No functional changes.
diffstat:
src/os/unix/ngx_files.c | 95 +++++++++++++++++++++++++++++-------------------
1 files changed, 57 insertions(+), 38 deletions(-)
diffs (129 lines):
diff -r 5170c3040ce1 -r be6af0906a4d src/os/unix/ngx_files.c
--- a/src/os/unix/ngx_files.c Tue Nov 17 19:01:41 2015 +0300
+++ b/src/os/unix/ngx_files.c Tue Nov 17 19:01:41 2015 +0300
@@ -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
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,46 +346,12 @@ ngx_write_chain_to_file(ngx_file_t *file
return total + n;
}
- if (file->sys_offset != offset) {
- if (lseek(file->fd, offset, SEEK_SET) == -1) {
- ngx_log_error(NGX_LOG_CRIT, file->log, ngx_errno,
- "lseek() \"%s\" failed", file->name.data);
- return NGX_ERROR;
- }
+ n = ngx_writev_file(file, &vec, size, offset);
- file->sys_offset = offset;
+ if (n == NGX_ERROR) {
+ return n;
}
-eintr:
-
- n = writev(file->fd, vec.elts, vec.nelts);
-
- if (n == -1) {
- err = ngx_errno;
-
- if (err == NGX_EINTR) {
- ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
- "writev() was interrupted");
- goto eintr;
- }
-
- ngx_log_error(NGX_LOG_CRIT, file->log, err,
- "writev() \"%s\" failed", file->name.data);
- return NGX_ERROR;
- }
-
- if ((size_t) n != size) {
- ngx_log_error(NGX_LOG_CRIT, file->log, 0,
- "writev() \"%s\" has written only %z of %uz",
- file->name.data, n, size);
- return NGX_ERROR;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
- "writev: %d, %z", file->fd, n);
-
- file->sys_offset += n;
- file->offset += n;
offset += n;
total += n;
@@ -393,6 +361,57 @@ eintr:
}
+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,
+ "lseek() \"%s\" failed", file->name.data);
+ return NGX_ERROR;
+ }
+
+ file->sys_offset = offset;
+ }
+
+eintr:
+
+ n = writev(file->fd, vec->elts, vec->nelts);
+
+ if (n == -1) {
+ err = ngx_errno;
+
+ if (err == NGX_EINTR) {
+ ngx_log_debug0(NGX_LOG_DEBUG_CORE, file->log, err,
+ "writev() was interrupted");
+ goto eintr;
+ }
+
+ ngx_log_error(NGX_LOG_CRIT, file->log, err,
+ "writev() \"%s\" failed", file->name.data);
+ return NGX_ERROR;
+ }
+
+ if ((size_t) n != size) {
+ ngx_log_error(NGX_LOG_CRIT, file->log, 0,
+ "writev() \"%s\" has written only %z of %uz",
+ file->name.data, n, size);
+ return NGX_ERROR;
+ }
+
+ ngx_log_debug2(NGX_LOG_DEBUG_CORE, file->log, 0,
+ "writev: %d, %z", file->fd, n);
+
+ file->sys_offset += n;
+ file->offset += n;
+
+ return n;
+}
+
+
ngx_int_t
ngx_set_file_time(u_char *name, ngx_fd_t fd, time_t s)
{
More information about the nginx-devel
mailing list