curl-library
Re: What clear up required after previous errors ?
Date: Mon, 23 Feb 2009 01:19:35 +0000 (GMT)
> Can you produce an example source code that repeats this
> problem?
Please see the end of this email.
> I assume you've tried this with 7.19.3? (you said "latest" but I'd like to get it confirmed
> what specific version it was you used)
7.19.3
> Well, there's no such requirements enforced by libcurl
> and I've never seen this problem before. Not in my own
> tests and not in any reports from others.
OK, must be something in my implementation then.
> What resolver are you using? What platform do you run this
> on?
I'm running on a Sharp Zaurus : XScale/ARM with OpenPDA, Linux kernel 2.4.18.
My own build of libcurl. I don't know enough about networking to tell you about the resolver so please explain to me if you need that info.
Here is an example; it's taken from my app where I have implemented a curl wrapper in C++ as a QT object. I use a QT timer to call curl_multi_perform every 100 ms. It's basically modified from the example codes on the curl website.
/**
* @file curlproxyproblem.c
* @brief Demonstrate problem with proxy
* @author Lyndon Hill
* @date 2009.02.23 Incept.
* @note This is an example, it must be modified before compiling!
*/
#include <curl/curl.h>
/* structs and prototypes */
struct cData
{
char *data;
int size;
};
size_t writeData(void *ptr, size_t size, size_t nmemb, void *data);
void CleanUp();
/* globals */
CURL *handle;
CURLM *mhandle;
int status;
struct cData chunk;
/* main */
int main(int argc, char *argv[])
{
char *url = "http://www.google.com";
char *proxy = "http://myproxy.org";
mhandle = curl_multi_init();
/* Attempt 1: Note: required proxy is missing */
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeData);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
curl_multi_add_handle(mhandle, handle);
curl_multi_perform(mhandle, &status);
while(/* some timer action */)
curl_multi_perform(mhandle, &status);
/* Download should fail: could not resolve URL */
CleanUp();
/* Attempt 2: Set proxy this time!! */
handle = curl_easy_init();
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_PROXY, proxy);
curl_easy_setopt(handle, CURLOPT_VERBOSE, 1);
curl_easy_setopt(handle, CURLOPT_TIMEOUT, 60);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, writeData);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&chunk);
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0L);
curl_multi_add_handle(mhandle, handle);
curl_multi_perform(mhandle, &status);
while(/* some timer action */)
curl_multi_perform(mhandle, &status);
/* Download fails: could not resolve proxy */
CleanUp();
curl_multi_cleanup(mhandle);
curl_global_cleanup();
}
/* Clean up after a transfer */
void CleanUp()
{
curl_multi_remove_handle(mhandle, handle);
curl_easy_cleanup(handle);
}
/* Call back function */
size_t writeData(void *ptr, size_t size, size_t nmemb, void *data)
{
int byteshandled = size*nmemb;
if(byteshandled == 0) return(byteshandled);
struct cData *mem = (struct cData *)(data);
mem->size = byteshandled;
mem->data = new char [byteshandled]; /* allocate memory */
if(!mem->data) return(0); /* could not allocate memory */
memcpy(mem->data, ptr, byteshandled); /* Copy the data stream into the local buffer */
printf("%s", mem->data);
delete mem->data;
return(byteshandled);
}
Received on 2009-02-23