curl-library
Re: Running curl in separate SDL thread
Date: Fri, 14 Aug 2009 01:28:56 -0700
I guess I should probably include a more specific question.
I am having issues passing in values to be used within the thread that
this function will run in:
int Downloader::download_func(void *ptr)
{
internalData *iData = reinterpret_cast<internalData *>(ptr);
CURL *mCurl;
mCurl = curl_easy_init();
float progress = 0;
std::string data;
data = "";
curl_easy_setopt(mCurl, CURLOPT_VERBOSE, 1) ;
curl_easy_setopt(mCurl, CURLOPT_HEADER, 0);
curl_easy_setopt(mCurl, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(mCurl, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(mCurl, CURLOPT_PROGRESSFUNCTION, progress);
curl_easy_setopt(mCurl, CURLOPT_PROGRESSDATA, &progress);
curl_easy_setopt(mCurl, CURLOPT_WRITEFUNCTION, writer);
curl_easy_setopt(mCurl, CURLOPT_WRITEDATA, &data);
Logger::logFile << "(INF) Requesting URL '" << *iData->urlPtr <<
"'..." << endl;
curl_easy_setopt(mCurl, CURLOPT_URL, *iData->urlPtr);
CURLcode returnCode = curl_easy_perform(mCurl);
Logger::logFile << "(INF) File has been downloaded." << endl;
curl_easy_cleanup(mCurl);
curl_global_cleanup();
return 0;
}
iData is of the following:
struct internalData
{
bool *finishedPtr;
std::string *urlPtr;
std::string *dataPtr;
float *progressPtr;
vector<string> *errorMessageList;
};
This:
Logger::logFile << "(INF) Requesting URL '" << *iData->urlPtr <<
"'..." << endl;
Will correctly print the url stored in urlPtr. However if I pass that
to
curl_easy_setopt(mCurl, CURLOPT_URL, *iData->urlPtr); then I get
EXEC_BAD_ACCESS.
I think this is a pointer error possibly but maybe you can see
something I dont.
On Aug 14, 2009, at 1:18 AM, Daniel Stenberg wrote:
> On Thu, 13 Aug 2009, Trevor Allen wrote:
>
>> Does anyone have experience regarding running curl from a separate
>> thread using SDL? I am working on a c++ game using SDL and libcurl
>> specifically an updater application and wondering the best way to
>> retrieve data from curl's thread.
>
> From libcurl's angle it doesn't matter what kind threading
> techniques you use or not. It runs in the single thread you invoke
> it in.
>
> --
>
> / daniel.haxx.se
Received on 2009-08-14