diff src/os/unix/ngx_darwin_sendfile_chain.c @ 5917:2c64b69daec5

Moved writev() handling code to a separate function. This reduces code duplication and unifies debug logging of the writev() syscall among various send chain functions.
author Valentin Bartenev <vbart@nginx.com>
date Wed, 13 Aug 2014 15:11:45 +0400
parents e044893b4587
children fddc6bed1e6e
line wrap: on
line diff
--- a/src/os/unix/ngx_darwin_sendfile_chain.c
+++ b/src/os/unix/ngx_darwin_sendfile_chain.c
@@ -33,6 +33,7 @@ ngx_darwin_sendfile_chain(ngx_connection
     int              rc;
     off_t            send, prev_send, sent;
     off_t            file_size;
+    ssize_t          n;
     ngx_uint_t       eintr;
     ngx_err_t        err;
     ngx_buf_t       *file;
@@ -172,33 +173,13 @@ ngx_darwin_sendfile_chain(ngx_connection
                            rc, file->file_pos, sent, file_size + header.size);
 
         } else {
-            rc = writev(c->fd, header.iovs, header.count);
-
-            ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
-                           "writev: %d of %uz", rc, header.size);
-
-            if (rc == -1) {
-                err = ngx_errno;
-
-                switch (err) {
-                case NGX_EAGAIN:
-                    break;
+            n = ngx_writev(c, &header);
 
-                case NGX_EINTR:
-                    eintr = 1;
-                    break;
-
-                default:
-                    wev->error = 1;
-                    ngx_connection_error(c, err, "writev() failed");
-                    return NGX_CHAIN_ERROR;
-                }
-
-                ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, err,
-                               "writev() not ready");
+            if (n == NGX_ERROR) {
+                return NGX_CHAIN_ERROR;
             }
 
-            sent = rc > 0 ? rc : 0;
+            sent = (n == NGX_AGAIN) ? 0 : n;
         }
 
         c->sent += sent;