diff options
author | Yann Ylavic <ylavic@apache.org> | 2017-03-28 21:56:28 +0000 |
---|---|---|
committer | Yann Ylavic <ylavic@apache.org> | 2017-03-28 21:56:28 +0000 |
commit | 476c29ad9943a50ecff87fa2f9a7a82eaa9b98c4 (patch) | |
tree | c79d03e4b50a5e9f4c317c13e7297ccf1bcce80c /network_io/unix/sendrecv.c | |
parent | 8175eb5317d2f54efe5159abbced9e1c2ee06075 (diff) | |
download | apr-476c29ad9943a50ecff87fa2f9a7a82eaa9b98c4.tar.gz |
apr_socket_sendfile: don't reset APR_TCP_NOPUSH if we didn't set it.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1789249 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'network_io/unix/sendrecv.c')
-rw-r--r-- | network_io/unix/sendrecv.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/network_io/unix/sendrecv.c b/network_io/unix/sendrecv.c index 233bbb301..6da7457aa 100644 --- a/network_io/unix/sendrecv.c +++ b/network_io/unix/sendrecv.c @@ -264,6 +264,7 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file, 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_socket_t *sock, apr_file_t *file, 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_socket_t *sock, apr_file_t *file, } 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; } |