cURL / Mailing Lists / curl-library / Single Mail

curl-library

Keepalive

From: Tim McClarren <timm_at_doppelganger.com>
Date: Mon, 17 Mar 2008 15:41:30 -0700

I am using libcurl for transport inside my application. I use a
multihandle associated with a single background thread to handle network
activity. easyhandles are added and removed from this multihandle to
service requests.

I have restructured the code a bit to attempt to reuse easy handles so
that keepalive will work. The sequence is like this:

1) create request
2) ask easyhandle pool for unused easyhandle for the host associated
with this request
3) initialize easyhandle
4) add easyhandle to multihandle
5) process
6) done
7) remove easyhandle from multihandle
8) callback into app to inform it of completion
9) return easyhandle to pool
10) delete request

So, if an easyhandle does not exist for the host which this URL points
to, I create one. Whenever a request finishes this easyhandle is
returned to the pool.

The behavior I'm seeing (using Sysinternals TCPView) is that libcurl is
not keeping this sockets open. They go to the "CLOSE_WAIT" state
sometime after completion (a few seconds). From there, any new requests
that are created which are going to connect to the same host cause a new
socket to open (I can tell because the source port is different). The
time between my requests to the same server are 30 seconds to one minute.

Is the behavior of how libcurl decides a particular easyhandle is
"reusable" documented somewhere? How do I determine how long libcurl is
going to keep a finished connection's socket "alive"? It seems as
though the local end of the connection is closing, and not the server side.

Thanks for any help!
Received on 2008-03-17