cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: curl_multi_perform() and curl_multi_add_handle

From: Emil Romanus <sdac.bithack_at_gmail.com>
Date: Mon, 14 May 2007 21:38:47 +0200

2007/5/14, Milan KÝŠpek <Hellbard_at_seznam.cz>:
>
> Hi I have one problem.
>
> I am workning on HTTP client. It sends requests to many servers, but it
> can send 100 request to one server too. So I do it this way. When I get
> request, a lookup if I have connection (curl_multi_handle) to this server.
> If not, I start new thread and in this thread I create new easy_curl, new
> multi_curl and add easy to multi and than I use select() on this multi,
> until it ends. When I lookup, that I have connection to this server, I
> create some data structure and give pointer of it to thread, that serves the
> right multi_handle. In select() loop I ask if I have some data on input.
> When there is something I generate new easy handle and add it to multi.
>
> Now the problem: Now the problem, I have request to local host, I start
> new thread, create easy and multi handle, add easy handle to multi and under
> select I call perform.

You should probably call curl_multi_perform() while it returns
CURLM_CALL_MULTI_PERFORM, and then move on by calling select() on the file
descriptors returned by libcurl. Not the reverse.

Than I get new request to same server. I create data structure and gives
> pointer of it to the thread. In select loop, It determines that it has new
> data there. It creates from it new easy_handle and add it to the multi.

I'm not sure I understand you correctly, why are you adding an easy handle
to your multi handle after you have determined it's got new data to receive
on a running one? I believe what you are supposed to do is continue calling
curl_multi_perform().

  If the first request is still performing, it takes the secon request too
> and perform it. But when I do this, when the first request was already
> performed, it takes the second request and do nothing.
>
> Why?? Is it because the server close the connection?? Can I reconect it
> somehow?? Or do I something other wrong? Please respond

If the server closes your connection, libcurl will open a new one upon a new
request. If you are interested in pipelining requests, you may enable the
CURLMOPT_PIPELINING option (by setting it to a non-zero value) through
curl_multi_setopt() if you are running a libcurl version above 7.16.0.

Thanks for your advice
> Milan Krapek
>
Received on 2007-05-14