Karl M added the CURLOPT_CONNECT_ONLY and CURLINFO_LASTSOCKET options that
an app can use to let libcurl only connect to a remote host and then extract the socket from libcurl. libcurl will then not attempt to do any transfer at all after the connect is done.
This commit is contained in:
25
lib/url.c
25
lib/url.c
@@ -352,6 +352,9 @@ CURLcode Curl_open(struct SessionHandle **curl)
|
||||
memset(data->state.connects, 0,
|
||||
sizeof(struct connectdata *)*data->state.numconnects);
|
||||
|
||||
/* most recent connection is not yet defined */
|
||||
data->state.lastconnect = -1;
|
||||
|
||||
/*
|
||||
* libcurl 7.10 introduced SSL verification *by default*! This needs to be
|
||||
* switched off unless wanted.
|
||||
@@ -432,6 +435,10 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
||||
are being removed! */
|
||||
for(i=newconnects; i< data->state.numconnects; i++)
|
||||
Curl_disconnect(data->state.connects[i]);
|
||||
|
||||
/* If the most recent connection is no longer valid, mark it invalid. */
|
||||
if(data->state.lastconnect <= newconnects)
|
||||
data->state.lastconnect = -1;
|
||||
}
|
||||
if(newconnects) {
|
||||
newptr= (struct connectdata **)
|
||||
@@ -453,8 +460,9 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
||||
/* zero makes NO cache at all */
|
||||
if(data->state.connects)
|
||||
free(data->state.connects);
|
||||
data->state.connects=NULL;
|
||||
data->state.numconnects=0;
|
||||
data->state.connects = NULL;
|
||||
data->state.numconnects = 0;
|
||||
data->state.lastconnect = -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1471,6 +1479,13 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
|
||||
data->set.ignorecl = va_arg(param, long)?TRUE:FALSE;
|
||||
break;
|
||||
|
||||
case CURLOPT_CONNECT_ONLY:
|
||||
/*
|
||||
* No data transfer, set up connection and let application use the socket
|
||||
*/
|
||||
data->set.connect_only = va_arg(param, long)?TRUE:FALSE;
|
||||
break;
|
||||
|
||||
default:
|
||||
/* unknown tag and its companion, just ignore: */
|
||||
result = CURLE_FAILED_INIT; /* correct this */
|
||||
@@ -3811,10 +3826,14 @@ CURLcode Curl_done(struct connectdata **connp,
|
||||
if(!result && res2)
|
||||
result = res2;
|
||||
}
|
||||
else
|
||||
else {
|
||||
/* remember the most recently used connection */
|
||||
data->state.lastconnect = conn->connectindex;
|
||||
|
||||
infof(data, "Connection #%ld to host %s left intact\n",
|
||||
conn->connectindex,
|
||||
conn->bits.httpproxy?conn->proxy.dispname:conn->host.dispname);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user