curl / Mailing Lists / curl-library / Single Mail

curl-library

How to Set Keep Alive Option in CURL

From: Praveen Pvs <meetpraveenpvs_at_gmail.com>
Date: Mon, 2 Jan 2017 19:46:50 +0530

Hi,

*Problem* - We have observed that Hand shake between Client and Server is
taking long time for SSL handshake and would like to avoid performing
handshake too often by using Keep Alive option in CURL

We wanted to use Keep Alove Options in CURL so that it keeps the connection
with the server open and avoid performing SSL handshake too often since SSL
handshake is consuming time

CURL Version - 7.39.0

In the code we have enabled the following options:

rv = curl_easy_setopt(locHandle, CURLOPT_TCP_KEEPALIVE, 1L);

*if*(rv == CURLE_OK)

{

    *printf*("%s: TCP KEEP ALIVE ENABLED\n", __FUNCTION__);

}

/* enable TCP keep-idle for this transfer */

rv = curl_easy_setopt(locHandle, CURLOPT_TCP_KEEPIDLE, 120L);

*if*(rv == CURLE_OK)

{

    printf("%s: TCP KEEP IDLE set 45\n", __FUNCTION__);

}

/* interval time between keep-alive probes: 60 seconds */

rv = curl_easy_setopt(locHandle, CURLOPT_TCP_KEEPINTVL, 60L);

*if*(rv == CURLE_OK)

{
      *printf*("%s: TCP KEEP INTVL set 45\n", __FUNCTION__);
}

When we executed above code, we have received the CURLE_OK as the return
values for the curl_easy_setopt function.

After setting the above options this what we have observed -
We have sent in total three requests to the host(server).
For the first request which was sent at 10:43:03 connection was established
and handshake was done. For the second request which was sent at 10.:43:20
no handshake was done, directly data was being sent. The third request
which was sent at 10:46:38 again performed handshake and sent the packet.
According to keep alive feature it shouldn’t be performing again isn’t it ?
Have attached the wireshark communication traces between client and server.

Am I missing something here?

We want to avoid SSL handshake with the server as much as possible?

Another Question - Do we need to set both the options(
*CURLOPT_TCP_KEEPIDLE* and *CURLOPT_TCP_KEEPINTVL*)?

Thank you for your time and help!

Regards
Praveen

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

Received on 2017-01-02