curl-library
Re: crash using libcurl 7.19 multi interface
Date: Thu, 12 Mar 2009 19:30:43 +0100
Daniel Stenberg wrote:
> On Thu, 12 Mar 2009, Hendrik Schober wrote:
>
>> So I take it that a short look at the code did not reveal anything blatantly
>> stupid?
>>
>> Thanks for looking into this!
>
> Well, I didn't catch anything given a glance but the code doesn't build for
> me so I couldn't try it (and I should add that C++ makes me all itchy and
> uncomfortable):
> [...]
I'm sorry for forgetting to include that header.
Meanwhile I've reduced the code further. (And the only C++
left in it is some string handling and output to stdout and
stderr. I hope that doesn't make you too uncomfortable.)
The new code is attached. (Note: This doesn't crash every
time I start it. Percentage varies widely. I suppose this
is an MT issue.)
I have checked the code on a Linux machine. But that had
libcurl 7.18.2 installed. I was unable to reproduce the
issue on that machine.
Schobi
#include <iostream>
#include <string>
#include <cstdlib>
#include <curl/curl.h>
int main()
{
std::cout << curl_version();
if( curl_global_init(CURL_GLOBAL_ALL) ) {
std::cerr << "curl_global_init() failed\n";
return 2;
}
CURLM * myCurlMultiHandle = curl_multi_init();
if( !myCurlMultiHandle ) {
std::cerr << "curl_multi_init() failed\n";
return 2;
}
const std::string myURLBase = "http://go.microsoft.com/fwlink/?LinkId=";
for( unsigned int u = 0; u<10; ++u ) {
const std::string myURL = myURLBase+"1000"+char('0'+u);
CURL * myCurlHandle = curl_easy_init();
if( !myCurlHandle ) {
std::cerr << "curl_easy_init() failed\n";
return 2;
}
if (CURLE_OK != curl_easy_setopt(myCurlHandle, CURLOPT_URL, myURL.c_str()) ) {
std::cerr << "curl_easy_setopt() failed\n";
return 2;
}
if (CURLE_OK != curl_multi_add_handle(myCurlMultiHandle, myCurlHandle) ) {
std::cerr << "curl_easy_setopt() failed\n";
return 2;
}
}
int myRunningCount;
std::cerr << "Handling requests...\n";
do {
for(;;) {
CURLMcode myStatus = curl_multi_perform(myCurlMultiHandle, &myRunningCount);
if( myStatus == CURLM_OK ) {
break;
}
if( myStatus != CURLM_CALL_MULTI_PERFORM ) {
std::cerr << "curl_multi_perform() failed with status " << myStatus << '\n';
return 3;
}
}
} while (myRunningCount);
std::cerr << "...curl finished handling requests.\n";
return 0;
}
Received on 2009-03-12