cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Http post going in a different tcp connection

From: Carlo Wood <carlo_at_alinoe.com>
Date: Thu, 27 Nov 2014 17:40:29 +0100

On Wed, 26 Nov 2014 13:12:53 +0000
Sriram <sriram.ec_at_gmail.com> wrote:

> Hello,
>
>
> I have written the below piece of code to send http post request
> using curl apis.
>
> In the failure case, same post request is sent again. Three retries
> are done, being considering server as not responsive.
>
> Once I call curl_easy_perform(), it will wait for the response from
> server for about http_timeout secs and FIN is sent from the client.
>
> Later again I call curl apis to prepare handle and doing
> curl_easy_perform.
>
> Now a new tcp connection is opened.
>
>
> Is it possible that I can reuse the same tcp connection to perform
> Http post once it is failed ?

Hi Sriram,

no that is not possible. If a timeout happens on a connection
then the connection is "unclean"; it cannot be known if or what
the server will send on that connection next therefore it must
be closed. So, what you observed seems to be the correct behavior.

>
>
>
> Below is the code snippet.
>
>
>
>
>
> void function()
>
> {
>
> static int init = 0;
>
> if (init == 0)
>
> {
>
> init = 1;
>
> curl_global_init(CURL_GLOBAL_ALL);
>
> }
>
>
>
> CURL *curl = curl_easy_init();
>
>
>
> struct curl_slist *slist=NULL;
>
> slist = curl_slist_append(slist, "Content-Type: application/text");
>
> slist = curl_slist_append(slist, "Cache-control: no-cache");
>
> slist = curl_slist_append(slist, "Expect:");
>
> curl_easy_setopt(curl, CURLOPT_HTTPHEADER, slist);
>
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
>
> if (ctx->sourceAddress != NULL)
>
> curl_easy_setopt(curl, CURLOPT_INTERFACE, ctx->sourceAddress);
>
>
>
> curl_easy_setopt(curl, CURLOPT_URL, ctx->serverName);
>
> curl_easy_setopt(curl, CURLOPT_PORT, ctx->serverPort);
>
>
>
> curl_easy_setopt(curl, CURLOPT_PROTOCOLS, CURLPROTO_HTTP |
> CURLPROTO_HTTPS);
>
> curl_easy_setopt(curl, CURLOPT_URL, url);
>
>
>
> curl_easy_setopt(curl, CURLOPT_TIMEOUT, ctx->HttpTimeOut);
>
> curl_easy_setopt(curl, CURLOPT_FORBID_REUSE, 0);
>
> res = curl_easy_perform(curl);
>
>
>
> if(res != CURL_OK)
>
> {
>
> /* retry the above code for three times before considering the server
> as unresponsive*/
>
> }
>
>
>
> } /* End of void function() */
>
>
>
> Please let me know if I am missing anything.
>
>
>
> Your help in this regard is appreciated.
>
>
>
> Regards,
> Sriram

-- 
Carlo Wood <carlo_at_alinoe.com>
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2014-11-27