curl-library
Sporadic "Couldn't resolve host" error on windows with libcurl 7.30.0
Date: Fri, 19 Sep 2014 14:14:41 -0400
Hi
I use libcurl for making http connections to a local tomcat server. However
I sometimes see "Couldn't resolve host name" on windows. But I do not see
such issue on linux. The command I use to build libcurl 7.30.0 on windows
is
nmake /f Makefile.vc mode=dll VC=10 ENABLE_WINSSL=no MACHINE=x64
This may not be a network issue as other people in other network using my
tool with my compiled libcurl is seeing this too. To narrow down the
problem I wrote a multi-threaded app which runs 100 threads, in each thread
if requests http page in a loop of range 1000. In total 100000 requests, I
can see 6-10 requests fails with above error.
Interestingly I do not see such error on linux 64 bit machine in the same
network with locally compiled libcurl 7.30.0.
If somebody can give me some suggestions, resolution, how to trace such
situation would be helpful. Am I missing some thing or this is expected for
a busy network?
int curl_perform_http(const char *url) {
CURLcode res = CURLE_OK;
char error_buffer[CURL_ERROR_SIZE] = "";
CURL *curl = NULL;
char *buffer = NULL;
int perform_result = 1;
curl_response curl_result;
curl = curl_easy_init();
if (curl == NULL)
return perform_result;
res = curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
if (res != CURLE_OK) {
goto goterror;
}
res = curl_easy_setopt(curl, CURLOPT_URL, url);
if (res != CURLE_OK) {
goto goterror;
}
res = curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
if (res != CURLE_OK) {
goto goterror;
}
buffer = (char *) calloc(CURL_BUFFER_SIZE, sizeof (char));
if (buffer == NULL) {
goto goterror;
}
curl_result.data = buffer;
curl_result.pos = 0;
res = curl_easy_setopt(curl, CURLOPT_URL, url);
if (res != CURLE_OK) {
goto goterror;
}
res = curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_collect_response);
if (res != CURLE_OK) {
goto goterror;
}
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, &curl_result);
if (res != CURLE_OK) {
goto goterror;
}
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
goto goterror;
}
perform_result = 0;
goterror:
if (res != CURLE_OK) {
printf("Curl: Error in curl, error details: %s, %s\n",
curl_easy_strerror(res), error_buffer);
}
if (buffer != NULL) {
free(buffer);
buffer = NULL;
}
if (curl != NULL) {
curl_easy_cleanup(curl);
}
return (perform_result);
}
size_t curl_collect_response(void *ptr, size_t size, size_t nmemb, void
*stream)
{
curl_response *result = (curl_response *)stream;
size_t sz = CURL_BUFFER_SIZE - 1;
if (result->pos + (size * nmemb) >= sz) {
printf("error: buffer too small\n");
return (0);
}
/* copy the data from ptr to curl_response object */
memcpy(result->data + result->pos, ptr, (size * nmemb));
result->pos += (int)(size * nmemb);
return (size * nmemb);
}
In each thread I call curl_perform_http 1000 times.
Many thanks for a wonderful library.
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-09-19