cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Running curl in separate SDL thread

From: Kamil Dudka <kdudka_at_redhat.com>
Date: Fri, 14 Aug 2009 10:46:40 +0200

On Fri August 14 2009 10:28:56 Trevor Allen wrote:
> 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.

Of course, you're mixing STL strings with (pure C) zero-terminated strings.
This has nothing to do with threads. You want to use iData->urlPtr->c_str().

Kamil
Received on 2009-08-14