Skip to content

Commit

Permalink
apr_socket_sendfile: don't reset APR_TCP_NOPUSH if we didn't set it.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1789249 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
ylavic committed Mar 28, 2017
1 parent 1e229b4 commit 1bec3f7
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions network_io/unix/sendrecv.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -362,15 +369,22 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
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;
}

nbytes += rv;

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
Expand Down Expand Up @@ -398,16 +412,16 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
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;
}
Expand Down

0 comments on commit 1bec3f7

Please sign in to comment.