curl / Mailing Lists / curl-library / Single Mail


Re: How to Set Keep Alive Option in CURL

From: Ray Satiro via curl-library <>
Date: Mon, 2 Jan 2017 14:03:22 -0500

On 1/2/2017 9:16 AM, Praveen Pvs wrote:
> 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

Please do not send the same question to both lists, send it to the one
most appropriate. For example in this case it's curl-library since
you're speaking of libcurl and not the curl tool.

Even if you use TCP keep-alive to get some earlier notice on potentially
dead connections that doesn't put the server under any obligation to
keep the connection, and it may close it if another transfer doesn't
take place in a certain amount of time. For example, will
close the connection after 3 minutes even if you use keep alive. Google
IIRC closes after a similar amount of time.

You don't have to set keepidle (default: 60) or keepintvl (default: 60).
Those default values have been the same since the options were added,
and I've just added that information to the documentation. As it says
though "Not all operating systems support [these options]".

You could monitor in Wireshark to confirm the keepalives are sent at the
interval you requested. You should see a lot of black background/ red
foreground type entries like
[TCP Keep-Alive]
[TCP Keep-Alive ACK]
Check the timestamps to determine if the frequency is correct. If the
server is closing the connection you should also see [FIN, ACK] or an RST

List admin:
Received on 2017-01-02