On Thu, 25 Mar 2010, Hauke Duden wrote:

Can you give me some guidance as to how the connection sharing algorithm works? This might help me to nail down the problem.

I.e. when exactly is a handle kept alive even though it is closed? Should this happen even if the handle is not attached to a multi handle anymore (but used to be)? When exactly is a connection marked as "shared"?

The connection pool is just a collection of connections kept within the multi handle. When a connection is not used by an easy handle anymore, it is put in the pool and held there. When an easy handle is about to do a transfer it checks if there's a connection in the pool that is fine to re-use.

The tricky part:

Due to some internal designs each connection needs an easy handle to be able to get used properly.

There are some protocols that want a series of "shutdown" commands before the TCP connection is disconnected (we call these commands "close actions" in the code) and so in order to close such a connection properly, it needs an easy handle.

Now, you add easy handles to a multi stack and you remove them again. Thus you could end up with connections in the pool, but no easy handles left. If one of those connections need "close actions", we're in trouble. To prevent that from happening, libcurl makes sure that there's always one easy handle kept around as long as there's one or more "close action" connections in the pool.

--

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

Reply via email to