curl-library
Re: Problem with my class in independents threads- Error: "Failure when receiving data from the peer"
Date: Mon, 27 Jul 2009 00:36:23 +0200
On Monday 27 of July 2009 00:17:27 Denis Bondarev wrote:
> AnsiString GCurl::FuncHTTPGet(int Time_Wait,AnsiString url)
> {
> char errbuf[CURL_ERROR_SIZE];
> CURL *curl;
> String table;
> GCurl_Error="Ok";
> curl = curl_easy_init();
>
>
> curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION,&Writer ); // !
>
> curl_easy_setopt(curl, CURLOPT_WRITEDATA , &table);
>
> curl_easy_setopt(curl, CURLOPT_URL, url);
>
> curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U;
> Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1");
> curl_easy_setopt(curl, CURLOPT_TIMEOUT,Time_Wait);
> curl_easy_setopt(curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
> curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION,1);
> curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "outfile.txt");
> curl_easy_setopt ( curl, CURLOPT_COOKIEFILE, "outfile.txt" );
>
> curl_easy_setopt(curl, CURLOPT_HEADER , 1 );
>
> curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
> res=curl_easy_perform(curl);
> if(res)
> GCurl_Error=errbuf;
> curl_easy_cleanup(curl);
> curl_global_cleanup();
The 1st mistake I spotted here. You call curl_global_cleanup() on each
request. You should call it exactly once as described here:
http://curl.haxx.se/libcurl/c/curl_global_cleanup.html
... and of course call curl_global_init() before you start to use libcurl
(also once).
> return table;
> delete curl;
Why are you calling C++ delete operator on curl easy handle?
Kamil
Received on 2009-07-27