Skip to content

Commit

Permalink
ConnectionExists: with *PIPEWAIT, wait for connections
Browse files Browse the repository at this point in the history
Try harder to prevent libcurl from opening up an additional socket when
CURLOPT_PIPEWAIT is set. Accomplished by letting ongoing TCP and TLS
handshakes complete first before the decision is made.

Closes curl#575
  • Loading branch information
Andersbakken authored and bagder committed Dec 23, 2015
1 parent 04cb909 commit a464f33
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/url.c
Original file line number Diff line number Diff line change
Expand Up @@ -3140,6 +3140,7 @@ ConnectionExists(struct SessionHandle *data,
{
struct connectdata *check;
struct connectdata *chosen = 0;
bool foundPendingCandidate = FALSE;
bool canPipeline = IsPipeliningPossible(data, needle);
#ifdef USE_NTLM
bool wantNTLMhttp = ((data->state.authhost.want & CURLAUTH_NTLM) ||
Expand Down Expand Up @@ -3239,6 +3240,8 @@ ConnectionExists(struct SessionHandle *data,

if((check->sock[FIRSTSOCKET] == CURL_SOCKET_BAD) ||
check->bits.close) {
if(!check->bits.close)
foundPendingCandidate = TRUE;
/* Don't pick a connection that hasn't connected yet or that is going
to get closed. */
infof(data, "Connection #%ld isn't open enough, can't reuse\n",
Expand Down Expand Up @@ -3339,6 +3342,7 @@ ConnectionExists(struct SessionHandle *data,
continue;
}
else if(check->ssl[FIRSTSOCKET].state != ssl_connection_complete) {
foundPendingCandidate = TRUE;
DEBUGF(infof(data,
"Connection #%ld has not started SSL connect, "
"can't reuse\n",
Expand Down Expand Up @@ -3447,6 +3451,12 @@ ConnectionExists(struct SessionHandle *data,
return TRUE; /* yes, we found one to use! */
}

if(foundPendingCandidate && data->set.pipewait) {
infof(data,
"Found pending candidate for reuse and CURLOPT_PIPEWAIT is set");
*waitpipe = TRUE;
}

return FALSE; /* no matching connecting exists */
}

Expand Down

0 comments on commit a464f33

Please sign in to comment.