Advertisement
Guest User

Untitled

a guest
Feb 16th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1.     do
  2.     {
  3.         if (m_forceToStop)
  4.         {
  5.             return;
  6.         }
  7.         timeval timeout;
  8.  
  9.         fd_set fdread;
  10.         fd_set fdwrite;
  11.         fd_set fdexcep;
  12.         int maxfd = -1;
  13.  
  14.         long curl_timeo = -1;
  15.  
  16.         FD_ZERO(&fdread);
  17.         FD_ZERO(&fdwrite);
  18.         FD_ZERO(&fdexcep);
  19.  
  20.         /* set a suitable timeout to play around with */
  21.         timeout.tv_sec = 1;
  22.         timeout.tv_usec = 0;
  23.  
  24.         curl_multi_timeout(multi_handle, &curl_timeo);
  25.         if(curl_timeo >= 0)
  26.         {
  27.             timeout.tv_sec = curl_timeo / 1000;
  28.             if(timeout.tv_sec > 1)
  29.             {
  30.                 timeout.tv_sec = 1;
  31.             }
  32.             else
  33.             {
  34.                 timeout.tv_usec = (curl_timeo % 1000) * 1000;
  35.             }
  36.         }
  37.  
  38.         /* get file descriptors from the transfers */
  39.         curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
  40.  
  41.         /* In a real-world program you OF COURSE check the return code of the
  42.         function calls.  On success, the value of maxfd is guaranteed to be
  43.         greater or equal than -1.  We call select(maxfd + 1, ...), specially in
  44.         case of (maxfd == -1), we call select(0, ...), which is basically equal
  45.         to sleep. */
  46.  
  47.         int rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
  48.         curl_multi_perform(multi_handle, &still_running);
  49.         switch(rc)
  50.         {
  51.         case -1: /* select() error */
  52.             {
  53.                 break;
  54.             }
  55.         case 0: /* timeout */
  56.             {
  57.                 break;
  58.             }
  59.         default: /* action */
  60.             {
  61.                 curl_multi_perform(multi_handle, &still_running);
  62.                 break;
  63.             }
  64.         }
  65.     } while(still_running);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement