cURL / Mailing Lists / curl-library / Single Mail

curl-library

Question on how I should use curl_multi_perform

From: CP YEH <ntdev74_at_gmail.com>
Date: Thu, 14 Jan 2010 10:35:31 -0500

Hi,

I have a question on how I should use curl_multi_perform().
I copied the code from the web to use multi form as follows. Every now
and then I noticed that my application sort of hangs so when I straced
it, I found that it keeps calling select and gets timeout and it seems
to me that the the code never gets to break out the following while
loop.

So I was wondering if there is anything I should add to prevent such
situations. select() is returning zero so I was not sure what else I
should check. I am not sure if I explained clearly but if anyone has
experienced similar situations, please give me some advice. Thank you.

        while(still_running) {
            struct timeval timeout;
            int rc; /* select() return code */

            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 */
            curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);

            /* In a real-world program you OF COURSE check the return
code of the
             function calls, *and* you make sure that maxfd is bigger than -1
             so that the call to select() below makes sense! */

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

            switch(rc) {
                case -1:
                    /* select error */
                    break;
                case 0:
                    ;//printf("timeout!\n");
                default:
                    /* timeout or readable/writable sockets */
                    while(CURLM_CALL_MULTI_PERFORM ==
                          curl_multi_perform(multi_handle, &still_running));
                    ;//printf("running: %d!\n", still_running);
                    break;
            }
        }

YEH
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2010-01-14