curl / Mailing Lists / curl-library / Single Mail

curl-library

Re: How to Set Keep Alive Option in CURL

From: Praveen Pvs <meetpraveenpvs_at_gmail.com>
Date: Wed, 1 Feb 2017 09:45:44 +0530

On Wed, Jan 4, 2017 at 10:03 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:

> On Wed, 4 Jan 2017, Praveen Pvs wrote:
>
> if we use keep alive options also host could still close the connection
>> which is happening in my case.
>>
>
> Absolutely. No keep alive options will help much in your case.
>
> Adding to the question on top of this: In this link
>> https://tools.ietf.org/id/draft-thomson-hybi-http-timeout-
>> 01.html#rfc.section.2
>>
>
> That's a draft for a header specification that never went into the HTTP
> spec. Read RFC 7230 for understanding how HTTP 1.1 works.
>
> Below is the header generated by curl after enabling keep-alive. Why am I
>> not seeing connection type and keepalive timeout in the headers ?
>>
>
> Because HTTP 1.1 has no such headers. Persistent connections are by
> default and connections will be kept alive by the server for a while after
> use, but it isn't normally advertised by the server. Clients and browsers
> also tend to keep connections alive for N seconds after use.
>
> Thank you Daniel for your inputs. It helped us. We had length discussion
with our server folks and they confirmed that they indeed the close the
connection with the client if they dont see any HTTP request for more than
60 secs. So in that case TCP level keep alive options would not help since
they want to see HTTP request to keep the connection alive.

We have done some more study to understand the time taken by the SSL
handshake.

We observe that there is delay of one second from the time of Client sent
ACK to the Server SYN ACK and the Client hello. Its been consistent
throughout our tests.

Any reason why there is gap of one sec between Client received ACK and it
sent Hello to the server?

Then we have tried with the raw open SSL library calls and we observe that
 its not happening with that.

I am attaching the wireshark traces in both cases(one experiment with CURL
library and another with raw open SSL calls).

Link to Wireshark trace of our application integrated with CURL library -
Test_With_CURL_Library.zip
<https://dropbox.verifone.com/pickup/wRxofcAu4DlHqNU5A1yqLBC-O2kIAL_ba3i6pRNu/Test_With_CURL_Library.zip>

Please filter ip.dst == 208.72.254.252 and ip.src == 10.120.9.122 on the
wireshark traces to know the communication between the our Terminal and
Server.

I am attaching the sample code with Raw Openssl calls which we have used to
test.

Below are the different options which we are setting in our application:

/* initialize the curl handler */

handle = curl_easy_init();

/* Set the server URL */

curl_easy_setopt(handle, CURLOPT_URL, hostDef.url);

              /* Set the connection timeout */

              curl_easy_setopt(handle, CURLOPT_CONNECTTIMEOUT, hostDef.
conTimeOut);

              /* Set the other common features */

              headers = curl_slist_append(headers, "User-Agent:SCA
v2.19.X");

headers = curl_slist_append(headers, "Content-Type:text/xml");

curl_easy_setopt(handle, CURLOPT_NOSIGNAL, 1L);

              /* Set the HTTP post option */

curl_easy_setopt(handle, CURLOPT_POST, 1L);

              /* Add the headers */

curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);

*#ifdef* DEBUG

              /* Add the debug function */

              curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, curlDbgFunc);

*#endif*

              curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 1L);

curl_easy_setopt(handle, CURLOPT_SSL_VERIFYHOST, 2L);

              /* Set the CA certificate */

curl_easy_setopt(handle, CURLOPT_CAINFO, CA_CERT_FILE);

       /* Set the write function */

       curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, saveResponse);

       /* Set the detection as TRUE for HTTP errors */

       curl_easy_setopt(handle, CURLOPT_FAILONERROR, *PAAS_TRUE*);

              /* To request using TLS for the transfer */

curl_easy_setopt(handle, CURLOPT_USE_SSL, CURLUSESSL_NONE);

              /* Set some curl library options before sending the data */

curl_easy_setopt(handle, CURLOPT_WRITEDATA, (*void* *) pstRespData);

              curl_easy_setopt(handle, CURLOPT_POSTFIELDS, (*void* *) req);

              curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, reqSize);

curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, szCurlErrBuf);

curl_easy_perform(handle);

Could you please review and let me know if we are missing something.

Thank you for your help and time.

> --
>
> / daniel.haxx.se
>
> -------------------------------------------------------------------
> List admin: https://cool.haxx.se/list/listinfo/curl-library
> Etiquette: https://curl.haxx.se/mail/etiquette.html
>

-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html

Received on 2017-02-01