| |
|
|
|
cURL Mailing List Monthly Index Single Mail
curl-library Mailing List Archives
RE: CURL loops infinitely when cable is pulled out.
From: Tom Donnelly <tom.donnelly_at_imagepick.com>
Date: Mon, 23 Apr 2007 11:16:22 -0700
Sonia - I realise it's not your fault, but your company is acting like a
Tom
-----Original Message-----
Hi Daniel,
/************************************************************
* RESUME on a HTTP page is a tricky business. First, let's just check
* 'range' isn't used, then set the range parameter and leave the resume
* it is to inform about this situation for later use. We will then
* "attempt" to resume, and if we're talking to a HTTP/1.1 (or later)
* server, we will get the document resumed. If we talk to a HTTP/1.0
* server, we just fail since we can't rewind the file writing from
* this function.
***********************************************************/
if(data->reqdata.resume_from) {
if(!data->reqdata.use_range) {
/* if it already was in use, we just skip this */
data->reqdata.range = aprintf("%" FORMAT_OFF_T "-",
if(!data->reqdata.range)
return CURLE_OUT_OF_MEMORY;
data->reqdata.rangestringalloc = TRUE; /* mark as allocated */
data->reqdata.use_range = 1; /* switch on range usage */
}
}
#endif
/*************************************************************
* Check the current list of connections to see if we can
* re-use an already existing one or if we have to create a
* new one.
*************************************************************/
/* get a cloned copy of the SSL config situation stored in the
connection struct */
if(!Curl_clone_ssl_config(&data->set.ssl, &conn->ssl_config))
return CURLE_OUT_OF_MEMORY;
/* reuse_fresh is TRUE if we are told to use a new connection by force,
we only acknowledge this option if this is not a re-used connection
already (which happens due to follow-location or during a HTTP
authentication phase). */
if(data->set.reuse_fresh && !data->state.this_is_a_follow)
reuse = FALSE;
else
reuse = ConnectionExists(data, conn, &conn_temp);
if(reuse) {
/*
* We already have a connection for this, we got the former connection
* in the conn_temp variable and thus we need to cleanup the one we
* just allocated before we can move along and use the previously
* existing one.
*/
struct connectdata *old_conn = conn;
if(old_conn->proxy.rawalloc)
free(old_conn->proxy.rawalloc);
/* free the SSL config struct from this connection struct as this was
allocated in vain and is targeted for destruction */
Curl_free_ssl_config(&conn->ssl_config);
conn = conn_temp; /* use this connection from now on */
conn->data = old_conn->data;
/* get the user+password information from the old_conn struct since it
* be new for this request even when we re-use an existing connection */
conn->bits.user_passwd = old_conn->bits.user_passwd;
if (conn->bits.user_passwd) {
/* use the new user namd and password though */
Curl_safefree(conn->user);
Curl_safefree(conn->passwd);
conn->user = old_conn->user;
conn->passwd = old_conn->passwd;
old_conn->user = NULL;
old_conn->passwd = NULL;
}
conn->bits.proxy_user_passwd = old_conn->bits.proxy_user_passwd;
if (conn->bits.proxy_user_passwd) {
/* use the new proxy user name and proxy password though */
Curl_safefree(conn->proxyuser);
Curl_safefree(conn->proxypasswd);
conn->proxyuser = old_conn->proxyuser;
conn->proxypasswd = old_conn->proxypasswd;
old_conn->proxyuser = NULL;
old_conn->proxypasswd = NULL;
}
/* host can change, when doing keepalive with a proxy ! */
if (conn->bits.proxy) {
free(conn->host.rawalloc);
conn->host=old_conn->host;
}
else
free(old_conn->host.rawalloc); /* free the newly allocated name buffer
/* get the newly set value, not the old one */
conn->bits.no_body = old_conn->bits.no_body;
/* re-use init */
conn->bits.reuse = TRUE; /* yes, we're re-using here */
Curl_safefree(old_conn->user);
Curl_safefree(old_conn->passwd);
Curl_safefree(old_conn->proxyuser);
Curl_safefree(old_conn->proxypasswd);
Curl_llist_destroy(old_conn->send_pipe, NULL);
Curl_llist_destroy(old_conn->recv_pipe, NULL);
free(old_conn); /* we don't need this anymore */
/*
* If we're doing a resumed transfer, we need to setup our stuff
* properly.
*/
data->reqdata.resume_from = data->set.set_resume_from;
if (data->reqdata.resume_from) {
if (data->reqdata.rangestringalloc == TRUE)
free(data->reqdata.range);
data->reqdata.range = aprintf("%" FORMAT_OFF_T "-",
data->reqdata.resume_from);
if(!data->reqdata.range)
return CURLE_OUT_OF_MEMORY;
/* tell ourselves to fetch this range */
data->reqdata.use_range = TRUE; /* enable range download */
data->reqdata.rangestringalloc = TRUE; /* mark range string allocated */
}
else if (data->set.set_range) {
/* There is a range, but is not a resume, useful for random ftp access
data->reqdata.range = strdup(data->set.set_range);
if(!data->reqdata.range)
return CURLE_OUT_OF_MEMORY;
data->reqdata.rangestringalloc = TRUE; /* mark range string allocated */
data->reqdata.use_range = TRUE; /* enable range download */
}
else
data->reqdata.use_range = FALSE; /* disable range download */
*in_connect = conn; /* return this instead! */
infof(data, "Re-using existing connection! (#%ld) with host %s\n",
conn->connectindex,
conn->proxy.name?conn->proxy.dispname:conn->host.dispname);
}
else {
/*
* This is a brand new connection, so let's store it in the connection
* cache of ours!
*/
< ConnectionStore(data, conn);
-> //Fix ssubrama - we have probably called Curl Disconnect
-> //Reset the entire resume from structure - to be safe.
-> data->reqdata.resume_from = data->set.set_resume_from;
-> if (data->reqdata.resume_from) {
-> if (data->reqdata.rangestringalloc == TRUE)
-> free(data->reqdata.range);
-> data->reqdata.range = aprintf("%" FORMAT_OFF_T "-",
-> data->reqdata.resume_from);
-> if(!data->reqdata.range)
-> return CURLE_OUT_OF_MEMORY;
->
-> /* tell ourselves to fetch this range */
-> data->reqdata.use_range = TRUE; /* enable range download */
-> data->reqdata.rangestringalloc = TRUE; /* mark range string allocated
-> }
-> else if (data->set.set_range) {
-> /* There is a range, but is not a resume, useful for random ftp
-> data->reqdata.range = strdup(data->set.set_range);
-> if(!data->reqdata.range)
-> return CURLE_OUT_OF_MEMORY;
-> data->reqdata.rangestringalloc = TRUE; /* mark range string allocated
-> data->reqdata.use_range = TRUE; /* enable range download */
-> }
-> else
-> data->reqdata.use_range = FALSE; /* disable range download */
-> ConnectionStore(data, conn);
}
/* Continue connectdata initialization here. */
/*
*
Thanks,
These mail archives are generated by hypermail. |
Page updated November 12, 2010.
web site info