cURL / Mailing Lists / curl-library / Single Mail

curl-library

How to perform asynchronous requests in a multi interface when these are not to be done at the same curl_multi_perform

From: Alessandra Serrau <aserrau_at_reilabs.com>
Date: Fri, 12 Jun 2009 14:23:19 +0200

Hi,
I need to get webpages not all at the same time.
That is, I can't add all the requests (one for each easy interface) to a
multi interface with curl_multi_add method and then execute a code such as
the following:

  int still_running;

  while(CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multi_handle,
&still_running));
  while(still_running)
  {
    struct timeval timeout;
    int rc; /* select() return code */
    CURLMcode res;

    fd_set fdread;
    fd_set fdwrite;
    fd_set fdexcep;
    int maxfd;

    FD_ZERO(&fdread);
    FD_ZERO(&fdwrite);
    FD_ZERO(&fdexcep);

    /* set a suitable timeout to play around with */
    timeout.tv_sec = 1;
    timeout.tv_usec = 0;

    /* get file descriptors from the transfers */
    res = curl_multi_fdset(m_Handle, &fdread, &fdwrite, &fdexcep, &maxfd);

    rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);

    switch(rc)
    {
    case -1:
      /* select error */
      break;
    case 0:
      //cout << "timeout!\n";
    default:
      /* timeout or readable/writable sockets */
      //cout << "perform!\n";
      while(CURLM_CALL_MULTI_PERFORM == curl_multi_perform(multiHandle,
&still_running));
      break;
    }
  }//end while(still_running)

If I good understood, this code allow to have the responses of the added
requests asynchronously, but if I want to add new requests during this loop,
I must wait the end of while(still_running) , after add new requests and
call another time this kind of code.

There is a way to add and then perform other new requests before all just
added requests have a response?

Thank you in advance for response.

Alessandra
Received on 2009-06-12