cURL / Mailing Lists / curl-library / Single Mail


RE: timeout with Unix multithread program

From: Legoff Vincent <>
Date: Mon, 6 Jan 2003 11:31:11 +0100

I tried to set CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT in my program,
but the thread in charge of downloading the URL waits for something and
nothing happens when the timeout should expires.
(I use the multi interface of CURL)

I have also set CURLOPT_NOSIGNAL to true (as specified in the documentation),
but nothing change.

Perhaps, there is something to do to handle the timeout?

Below the option I set for the download:
                curl_easy_setopt(httpHandle, CURLOPT_URL, urlString.c_str());
                curl_easy_setopt(httpHandle, CURLOPT_WRITEFUNCTION, writeCallback);
                curl_easy_setopt(httpHandle, CURLOPT_HEADERFUNCTION, writeHeaderCallback);
                curl_easy_setopt(httpHandle, CURLOPT_FAILONERROR, 1);
                curl_easy_setopt(httpHandle, CURLOPT_CONNECTTIMEOUT, 5);
                curl_easy_setopt(httpHandle, CURLOPT_TIMEOUT, 5);
                curl_easy_setopt(httpHandle, CURLOPT_NOSIGNAL, true);

And below the way I get the result of the download:
                                struct timeval timeout;
                                int rc; // select return code
                                fd_set fdread;
                                fd_set fdwrite;
                                fd_set fdexcep;
                                int maxfd;
                                // add our File Descriptor in order to inform
                                // that a new URL has to be downloaded and has been put
                                // in the httpHandleList
                                FD_SET(mp_pipeFD[0], &fdread);
                                timeout.tv_sec = 60;
                                timeout.tv_usec = 0;
                                // get file descriptors from the transfers
                                curl_multi_fdset(mp_multiHandle, &fdread, &fdwrite, &fdexcep, &maxfd);
                                int maxFileDesc = (maxfd>mp_pipeFD[0])?maxfd+1:mp_pipeFD[0]+1;
                                rc = select(maxFileDesc, &fdread, &fdwrite, &fdexcep, &timeout);
                                switch (rc)
                                        case -1:
                                                //select error
                                        case 0:
                                                // timeout case
                                                // check if new URL are in the list
                                                cout << "*** timeout ***" << endl;
                                                if ( mv_onStop == false)
                                                        // exit from loop
                                                        stillRunning = 0;
                                                // readable/writeable sockets
                                                if (FD_ISSET(mp_pipeFD[0], &fdread))
                                                        // our own file descriptor
                                                        // to be implemented
                                                        while(CURLM_CALL_MULTI_PERFORM == curl_multi_perform(mp_multiHandle, & stillRunning));

                                                        // check if some downloads are completed
                                                        // use curl_multi_info_read to get the info
                                                        // about the download

Thanks in advance,


-----Original Message-----
From: Daniel Stenberg []
Sent: Friday, December 27, 2002 6:59 PM
To: libcurl Mailing list
Subject: Re: timeout with Unix multithread program

On Mon, 23 Dec 2002, Legoff Vincent wrote:

> I have a Unix multithread program, and I would like to set a timeout for
> the HTTP connection and also for the download. It seems that
> CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT do not work for such a program.

Why not? AFAIK, they do.

> Is there another way to set such timeout in my program?

pair that limits connection times.

 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
This email is sponsored by:ThinkGeek
Welcome to geek heaven.
This email is sponsored by:ThinkGeek
Welcome to geek heaven.
Received on 2003-01-06