curl-library
libcurl 7.25 / multi / win32
Date: Sun, 20 May 2012 18:39:54 +0100
Hi,
I've been trying to get to grips with the multi interface (everything works
fine with easy)
I initially tried to get fopen.c example working to no avail and so wrote a
simpler test program (see below)
This code runs fine but just loops as every loop curl_multi_fdset returns
with maxfd == -1
Neither my write or debug are ever called.
Tracing into curl_mult_fdset I see this line...
bitmap = multi_getsock(easy, sockbunch, MAX_SOCKSPEREASYHANDLE);
this always returns bitmap==0
Tracing into multi_getsock....
easy->state==CURLM_STATE_WAITRESOLVE
which leads to the following getting called...
int Curl_resolver_getsock(struct connectdata *conn,
curl_socket_t *socks,
int numsocks)
{
(void)conn;
(void)socks;
(void)numsocks;
return 0;
}
This is 0 is what is bitmap is set to.
What am I doing wrong? My enviroment is :
libcurl 7.25 (static library built from project file)
win32
msvc10
Thanks in advance,
Adam
//****************************************
// multi curl test
//****************************************
void adamTest()
{
curl_global_init(CURL_GLOBAL_ALL);
CURLM *mh=curl_multi_init();
if (mh)
{
CURL * eh=curl_easy_init();
if (eh)
{
int runningHandles=0;
curl_easy_setopt(eh, CURLOPT_URL,"http://www.c-burn.com");
curl_easy_setopt(eh, CURLOPT_WRITEDATA, 0L);
curl_easy_setopt(eh, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(eh, CURLOPT_WRITEFUNCTION, adam_write_callback);
curl_easy_setopt(eh, CURLOPT_DEBUGFUNCTION, adam_debug_callback);
curl_easy_setopt(eh, CURLOPT_DEBUGDATA, 0L);
//nb. uncommenting out this to use easy interface works
//curl_easy_perform(eh);
curl_multi_add_handle(mh, eh);
/* lets start the fetch */
curl_multi_perform(mh, &runningHandles);
while(runningHandles>0)
{
struct timeval timeout;
int rc; /* select() return code */
fd_set fdread;
fd_set fdwrite;
fd_set fdexcep;
int maxfd = -1;
long curl_timeo = -1;
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;
curl_multi_timeout(mh, &curl_timeo);
if(curl_timeo >= 0)
{
timeout.tv_sec = curl_timeo / 1000;
if(timeout.tv_sec > 1)
timeout.tv_sec = 1;
else
timeout.tv_usec = (curl_timeo % 1000) * 1000;
}
/* get file descriptors from the transfers */
curl_multi_fdset(mh, &fdread, &fdwrite, &fdexcep, &maxfd);
if (maxfd>-1)
{
/* In a real-world program you OF COURSE check the return code of the
function calls. On success, the value of maxfd is guaranteed to be
greater or equal than -1. We call select(maxfd + 1, ...), specially in
case of (maxfd == -1), we call select(0, ...), which is basically equal
to sleep. */
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
switch(rc)
{
case -1:
/* select error */
break;
case 0: /* timeout */
default: /* action */
curl_multi_perform(mh, &runningHandles);
break;
}
}
else
Sleep(100);
}
/* make sure the easy handle is not in the multi handle anymore */
curl_multi_remove_handle(mh,eh);
/* cleanup */
curl_easy_cleanup(eh);
}
curl_multi_cleanup(mh);
}
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2012-05-20