curl-library
Re: Persistant Connections testing
Date: Wed, 28 Nov 2001 11:17:19 +0200
Daniel Stenberg wrote:
> On Tue, 27 Nov 2001, Dimitris Sarris wrote:
>
> > When I execute the above, it crashes at the first call of
> > "curl_easy_perform". I debugged with dbx and I found that it crashes
> > inside the "Curl_getaddrinfo", at line 831 of the "ftp.c" :
> >
> > 831: if(gethostbyaddr_r((char *) &address,
> > sizeof(address), AF_INET,
> > (struct hostent *)hostent_buf,
> > hostent_buf + sizeof(*answer)))
>
> Do you know why this particular code crashes? I can only think of one problem
> here:
>
> The 'address' variable is an "unsigned long" type while the man page says it
> should be using the in_addr_t type. In a 64 bit architecture, it might make a
> difference if the in_addr_t isn't a typedef'ed long.
>
> Could it be this?
Here it is a slightly changed persistant example (copied from your
repository)
_______________________________________________________________________________________________
#include <stdio.h>
#include <unistd.h>
#include <curl/curl.h>
/* to make this work under windows, use the win32-functions from the
docs/examples/win32socket.c file as well */
/* This example REQUIRES libcurl 7.7 or later */
#if (LIBCURL_VERSION_NUM < 0x070700)
#error Too old libcurl version, upgrade or stay away.
#endif
/*
class TestWrapper {
private:
CURL* curl;
public:
TestWrapper() {
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
}
~TestWrapper() {
curl_easy_cleanup(curl);
}
void GetFile() {
FILE *ftpfile;
CURLcode res;
ftpfile = fopen("readme.txt", "wb");
curl_easy_setopt(curl, CURLOPT_URL, "ftp://myhost/readme.txt");
curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
curl_easy_setopt(curl, CURLOPT_USERPWD, "dimitris:dimitris");
res = curl_easy_perform(curl);
fclose(ftpfile);
}
void GetList() {
FILE *ftpls;
CURLcode res;
ftpls = fopen("ftpls.txt", "wb");
curl_easy_setopt(curl, CURLOPT_URL, "ftp://myhost");
curl_easy_setopt(curl, CURLOPT_FILE, ftpls);
res = curl_easy_perform(curl);
fclose(ftpls);
}
};
*/
CURL* curl;
void Init() {
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
}
void End() {
curl_easy_cleanup(curl);
}
void GetFile() {
FILE *ftpfile;
CURLcode res;
ftpfile = fopen("readme.txt", "wb");
curl_easy_setopt(curl, CURLOPT_URL, "ftp://myhost/readme.txt");
curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
curl_easy_setopt(curl, CURLOPT_USERPWD, "dimitris:dimitris");
res = curl_easy_perform(curl);
//fclose(ftpfile);
}
void GetList() {
FILE *ftpls;
CURLcode res;
ftpls = fopen("ftpls.txt", "wb");
curl_easy_setopt(curl, CURLOPT_URL, "ftp://myhost");
curl_easy_setopt(curl, CURLOPT_FILE, ftpls);
curl_easy_setopt(curl, CURLOPT_USERPWD, "dimitris:dimitris");
res = curl_easy_perform(curl);
// fclose(ftpls);
}
int main(int argc, char **argv)
{
/* C++ mode
TestWrapper test;
test.GetFile();
test.GetList();
*/
/* Procedural mode */
Init();
GetFile();
GetList();
End();
/* */
/* cURL example
CURL *curl;
CURLcode res;
FILE *ftpfile, *ftpls;
ftpfile = fopen("readme.txt", "wb");
ftpls = fopen("ftpls.txt", "wb");
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl, CURLOPT_URL, "ftp://myhost/readme.txt");
curl_easy_setopt(curl, CURLOPT_FILE, ftpfile);
curl_easy_setopt(curl, CURLOPT_USERPWD, "dimitris:dimitris");
res = curl_easy_perform(curl);
curl_easy_setopt(curl, CURLOPT_URL, "ftp://myhost");
curl_easy_setopt(curl, CURLOPT_FILE, ftpls);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
*/
return 0;
}
_______________________________________________________________________________________________
As you can see there are 3 different approaches:
1. Your approach (all the code in the main procedure)
2. Procedural approach (global curl instance, 4 procedures are doing
the
work)
3. Object-oriented approach (Class TestWrapper is doing all the
work)
It has no problem running with the 1st approach (your example), but with
the
other 2 approaches crashes at the same position with my first example.
At the
first call to "curl_easy_perform".
I am running this example at a Digital Unix platform (Tru64 4.0D)
Have you compiled and tested my first example?
Can you compile and test all the 3 variants in order to see if it is a
platform
problem or a "curl" bug or my software bug?
Thanks,
Dimitris
Received on 2001-11-28