apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yla...@apache.org
Subject svn commit: r1789249 - /apr/apr/trunk/network_io/unix/sendrecv.c
Date Tue, 28 Mar 2017 21:56:28 GMT
Author: ylavic
Date: Tue Mar 28 21:56:28 2017
New Revision: 1789249

URL: http://svn.apache.org/viewvc?rev=1789249&view=rev
Log:
apr_socket_sendfile: don't reset APR_TCP_NOPUSH if we didn't set it.


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=1789249&r1=1789248&r2=1789249&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sendrecv.c (original)
+++ apr/apr/trunk/network_io/unix/sendrecv.c Tue Mar 28 21:56:28 2017
@@ -264,6 +264,7 @@ apr_status_t apr_socket_sendfile(apr_soc
                                  apr_size_t *len, apr_int32_t flags)
 {
     int rv, nbytes = 0, total_hdrbytes, i;
+    int nopush_set = 0;
     apr_status_t arv;
 
 #if APR_HAS_LARGE_FILES && defined(HAVE_SENDFILE64)
@@ -296,15 +297,18 @@ apr_status_t apr_socket_sendfile(apr_soc
     if (!hdtr) {
         hdtr = &no_hdtr;
     }
-
-    if (hdtr->numheaders > 0) {
-        apr_size_t hdrbytes;
-
+    else if ((hdtr->numheaders > 0 || hdtr->numtrailers > 0)
+             && !apr_is_option_set(sock, APR_TCP_NOPUSH)) {
         /* cork before writing headers */
         rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);
         if (rv != APR_SUCCESS) {
             return rv;
         }
+        nopush_set = 1;
+    }
+
+    if (hdtr->numheaders > 0) {
+        apr_size_t hdrbytes;
 
         /* Now write the headers */
         arv = apr_socket_sendv(sock, hdtr->headers, hdtr->numheaders,
@@ -325,7 +329,10 @@ apr_status_t apr_socket_sendfile(apr_soc
         }
         if (hdrbytes < total_hdrbytes) {
             *len = hdrbytes;
-            return apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+            if (nopush_set) {
+                return apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+            }
+            return APR_SUCCESS;
         }
     }
 
@@ -362,7 +369,9 @@ do_select:
     if (rv == -1) {
         *len = nbytes;
         rv = errno;
-        apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+        if (nopush_set) {
+            apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+        }
         return rv;
     }
 
@@ -370,7 +379,12 @@ do_select:
 
     if (rv < *len) {
         *len = nbytes;
-        arv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+        if (nopush_set) {
+            arv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+        }
+        else {
+            arv = APR_SUCCESS;
+        }
         if (rv > 0) {
                 
             /* If this was a partial write, return now with the 
@@ -398,16 +412,16 @@ do_select:
         arv = apr_socket_sendv(sock, hdtr->trailers, hdtr->numtrailers, 
                                &trbytes);
         nbytes += trbytes;
+        if (nopush_set) {
+            apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
+        }
         if (arv != APR_SUCCESS) {
             *len = nbytes;
             rv = errno;
-            apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
             return rv;
         }
     }
 
-    apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
-    
     (*len) = nbytes;
     return rv < 0 ? errno : APR_SUCCESS;
 }



Mime
View raw message