curl-library
RE: timeout with Unix multithread program
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:
while(stillRunning)
{
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);
// 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
break;
case 0:
// timeout case
// check if new URL are in the list
cout << "*** timeout ***" << endl;
waitForHttpHandle();
if ( mv_onStop == false)
addHttpHandle(&stillRunning);
else
// exit from loop
stillRunning = 0;
break;
default:
// readable/writeable sockets
if (FD_ISSET(mp_pipeFD[0], &fdread))
{
// our own file descriptor
// to be implemented
}
else
{
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
downloadCompletedPerform();
}
break;
}
}
Thanks in advance,
Vincent
-----Original Message-----
From: Daniel Stenberg [mailto:daniel_at_haxx.se]
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?
Yes, there are also the CURLOPT_LOW_SPEED_LIMIT and CURLOPT_LOW_SPEED_TIME
pair that limits connection times.
-- Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs. ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf ------------------------------------------------------- This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sfReceived on 2003-01-06