curl-library
Re: curl_multi_perform problem in multi threaded aplication
Date: Thu, 3 May 2007 14:16:20 +0200 (CEST)
On Thu, 3 May 2007, Milan K?ápek wrote:
> If I get new request to server from some thread, I lookup in my storage map,
> if there is any multi_handle that serves connection to this server. If not,
> I create new easy_handle, new multi_handle and add it to my storage map, add
> easy_handle to multi, start new thread and in it I call curl_multi_perform.
> If the multi_handle exists I only add new easy_handle to existing
> multi_handle.
Your method is quite an overkill for libcurl use. At least since 7.16.0.
libcurl itself has a connection cache that is kept in the multi handle so it
keeps connections alive after use and easy handles can pick and re-use one of
them in the cache when you want a transfer done. The connection cache is
separate from the easy handles, so you can create a brand new easy handle but
still re-use a connection used by a previous handle that you've closed.
> Well and it does not work. Is It because I create the handles in one thread
> and perform it in another? Or is there any other mistake?
You can bounce around the handles in as many threads as you like but you MUST
NEVER EVER use them in more than one thread simultaneously.
-- Commercial curl and libcurl Technical Support: http://haxx.se/curl.htmlReceived on 2007-05-03