cURL / Mailing Lists / curl-library / Single Mail

curl-library

issue with curl_multi_timeout while doing non-blocking HTTP posts in VMS

From: Sudarshan Raghunathan <sudarshan_raghunathan_at_hotmail.com>
Date: Fri, 27 Jul 2007 10:19:16 -0700

Hi all,
I am having some trouble with the curl_multi_timeout function return value.
My understanding is that this function should return the the max time for
which the app must wait before proceeding. However, the value returned by
this function seems really huge - around 300 seconds!
I am attempting to do a non-blocking HTTP post in Open VMS using curl
7.16.2.
Am I using this call correctly? (note: I don't want to use the select
mechanism for checking socket activity).
Enclosed is my test code sample:

//Performs a HTTP post using the curl multi API - sample text post using TMO
static void perform_curl_multi_api_tmo_test_txt(void)
{
        CURL *curl;
        CURLM *multi_curl;
        char *data="qt=go";
        FILE* fp;
        int still_running = 0;
        CURLMcode code;

        //open output file for writing HTTP post response from the NAV
portal
        fp = fopen(NAV_RESPONSE_MULTI_OUT_FILE,"wb");

        curl = curl_easy_init();
        multi_curl = curl_multi_init();

        if(curl && multi_curl)
        {

                //re-direct output to set response file
                (void)curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
                (void)curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
                (void)curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
                (void)curl_easy_setopt(curl, CURLOPT_URL, ...);

                //add easy handle to the multi handle
                code = curl_multi_add_handle(multi_curl, curl);

                /* post away! - while checking for time outs in the multi
call*/
                 code = curl_multi_perform(multi_curl, &still_running);
                 while(CURLM_CALL_MULTI_PERFORM == code)
                 {
                        code = curl_multi_perform(multi_curl,
&still_running);
                 }

                while(still_running)
                { //=>some transfer ongoing.... wait for time interval and
abort if needed
                        int maxfd;
                        CURLMcode code;
                        long timeout = 0;
                        fd_set fdread;
                        fd_set fdwrite;
                        fd_set fdexcep;

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

                        /* get file descriptors from the transfers */

                        code = curl_multi_fdset(multi_curl, &fdread,
&fdwrite, &fdexcep, &maxfd);
                        if ( code != 0)
                        {
                              break;
                        }

                       if (maxfd != -1)
                       {
                                if (curl_multi_timeout(multi_curl,&timeout)
!= CURLM_OK)
                                {
                                       break;
                                }

                                if (timeout == -1)
                                {
                                       //no timer set
                                        break; //out of while
                                }

                                if (timeout == 0)
                                {
                                        //proceed immediately
                                        while(CURLM_CALL_MULTI_PERFORM ==
                                                
curl_multi_perform(multi_curl, &still_running));
                                }
                                else
                                {
                                        //wait for specified timeout period
and try again
                                        (void)printf("waiting for %u
msecs!!!\n", timeout);

                                        //THIS VALUE IS HUGE!! APPROX 300000
MSECS!

                                        (void)sleep(timeout/1000); //in secs
                                         while(CURLM_CALL_MULTI_PERFORM ==
                                                
curl_multi_perform(multi_curl, &still_running));
                                } //end else
                       }//end if
                 }//end while

                /* always cleanup */
                (void)printf("cleaning up...!\n");
                (void)curl_multi_remove_handle(multi_curl,curl);
                (void)curl_easy_cleanup(curl);
                (void)curl_multi_cleanup(multi_curl);

        }//end if

}

_________________________________________________________________
http://im.live.com/messenger/im/home/?source=hmtextlinkjuly07
Received on 2007-07-27