curl-library
RE: curl_multi_fdset always returns -1 for maxfd
Date: Wed, 12 Nov 2014 10:21:43 +0000
> From: curl-library [mailto:curl-library-bounces_at_cool.haxx.se] On Behalf Of Daniel Stenberg
> Sent: Wednesday, November 12, 2014 2:42 PM
> To: libcurl development
> Subject: RE: curl_multi_fdset always returns -1 for maxfd
>
> On Wed, 12 Nov 2014, Vishakha Vaidya wrote:
>
> > CURLOPT_VERBOSE gave the error "hostname was not found in DNS cache",
>
> The fact that it wasn't in the DNS cache shouldn't be much of a surprise on a fresh handle with empty cache! =) (that message has been removed in later
> versions)
>
> > I changed the url to have ip address and it worked. Why would a
> > hostname not work when I can connect to the hostname using curl.
>
> I don't know, because it shouldn't. curl uses the same API! Can you give us a full source code to an application that can repeat the problem against a public URL?
>
> --
>
> / daniel.haxx.se
> -------------------------------------------------------------------
> List admin: http://cool.haxx.se/list/listinfo/curl-library
> Etiquette: http://curl.haxx.se/mail/etiquette.html
There you go -
/***************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <Winsock2.h>
#include "curl/multi.h"
struct FtpFile {
const char *filename;
FILE *stream;
};
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream)
{
struct FtpFile *out=(struct FtpFile *)stream;
if(out && !out->stream) {
/* open file for writing */
out->stream=fopen(out->filename, "wb");
if(!out->stream)
return -1; /* failure, can't open file to write */
}
return fwrite(buffer, size, nmemb, out->stream);
}
int main(void)
{
CURL *http_handle;
CURL *http_handle2;
CURLM *multi_handle;
struct FtpFile ftpfile={
"index2.html", /* name to store the file as if successful */
NULL
};
int still_running; /* keep number of running handles */
http_handle = curl_easy_init();
http_handle2 = curl_easy_init();
/* set options */
curl_easy_setopt(http_handle, CURLOPT_VERBOSE, (long)1);
//ftp.byethost3.com (185.27.134.11)
curl_easy_setopt(http_handle, CURLOPT_URL, "ftp://b3_15536782:tester@ ftp.byethost3.com/htdocs/index2.html");
curl_easy_setopt(http_handle, CURLOPT_WRITEFUNCTION, my_fwrite);
curl_easy_setopt(http_handle, CURLOPT_WRITEDATA, &ftpfile);
multi_handle = curl_multi_init();
curl_multi_add_handle(multi_handle, http_handle);
curl_multi_perform(multi_handle, &still_running);
do {
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);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
curl_multi_timeout(multi_handle, &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;
}
curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
switch(rc) {
case -1:
break;
case 0:
default:
curl_multi_perform(multi_handle, &still_running);
break;
}
} while(still_running);
curl_multi_cleanup(multi_handle);
curl_easy_cleanup(http_handle);
printf("DONE");
getch();
return 0;
}
/***************************************************************************/
Other info :
CURL version 7.38.0
OS - windows 7 Enterprise
Configuration used to build curl - DLL Debug - DLL openssl, built using vc11 project
Program linked against ws2_32.lib
Note : the code works fine on mac
Thanks,
Vishakha
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-11-12