apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject svn commit: r652690 - /apr/apr/trunk/network_io/unix/sendrecv.c
Date Thu, 01 May 2008 22:22:23 GMT
Author: wrowe
Date: Thu May  1 15:22:22 2008
New Revision: 652690

URL: http://svn.apache.org/viewvc?rev=652690&view=rev
Log:
Reflow the OS/X sendfile implementation to proceed from writev(hd..iovec)
to the sendfile/tr..iovec series, tallying these correctly.

Submitted by: Geoff Greer <angryparsley mipsisrisc.com> and wrowe



Modified:
    apr/apr/trunk/network_io/unix/sendrecv.c

Modified: apr/apr/trunk/network_io/unix/sendrecv.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sendrecv.c?rev=652690&r1=652689&r2=652690&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sendrecv.c (original)
+++ apr/apr/trunk/network_io/unix/sendrecv.c Thu May  1 15:22:22 2008
@@ -413,7 +413,8 @@
     apr_off_t nbytes = 0;
     apr_off_t bytes_to_send = *len;
     apr_size_t header_bytes_written = 0;
-    int rv;
+    int rv = 0;
+    int sent_headers = 0;
 
     /* Ignore flags for now. */
     flags = 0;
@@ -436,17 +437,24 @@
                 return arv;
             }
         }
-        
-        if (hdtr->numheaders) {
-            rv = writev(sock->socketdes,
-                        hdtr->headers,
-                        hdtr->numheaders);
-            if (rv > 0) {
-                header_bytes_written = rv;
-                rv = 0;
+
+        if (!sent_headers) {
+            if (hdtr->numheaders) {
+                rv = writev(sock->socketdes,
+                            hdtr->headers,
+                            hdtr->numheaders);
+                if (rv > 0) {
+                    header_bytes_written = rv;
+                    sent_headers = 1;
+                    rv = 0;
+                }
+            }
+            else {
+                sent_headers = 1;
             }
         }
-        else if (bytes_to_send) {
+
+        if (bytes_to_send && sent_headers) {
             /* We won't dare call sendfile() if we don't have
              * header or file bytes to send because nbytes == 0
              * means send the remaining file to EOF.
@@ -464,12 +472,13 @@
                 if (errno == EAGAIN) {
                     if (sock->timeout > 0) {
                         sock->options |= APR_INCOMPLETE_WRITE;
+                        rv = 0;
                     }
                     /* BSD's sendfile can return -1/EAGAIN even if it
                      * sent bytes.  Sanitize the result so we get normal EAGAIN
                      * semantics w.r.t. bytes sent.
                      */
-                    if (nbytes) {
+                    else if (nbytes) {
                         /* normal exit for a big file & non-blocking io */
                         (*len) = nbytes + header_bytes_written;
                         return APR_SUCCESS;
@@ -486,19 +495,17 @@
                 }
             }
         }
-        else {
+
+        if (sent_headers && !bytes_to_send) {
             /* just trailer bytes... use writev()
              */
             rv = writev(sock->socketdes,
                         hdtr->trailers,
                         hdtr->numtrailers);
             if (rv > 0) {
-                nbytes = rv;
+                nbytes += rv;
                 rv = 0;
             }
-            else {
-                nbytes = 0;
-            }
         }
         if ((rv == -1) && (errno == EAGAIN) 
                        && (sock->timeout > 0)) {



Mime
View raw message