cURL
Haxx ad
libcurl

curl's project page on SourceForge.net

Sponsors:
Haxx

cURL > Mailing List > Monthly Index > Single Mail

curlpp mailing list Archives

[cURLpp] WriteFunctionFunctor still can not use a member pointer

From: sirtoozee <sirtoozee_at_gmail.com>
Date: Fri, 23 Nov 2007 10:15:42 +0800

Hi curlpp geek:

I read the source code of the example05.cpp(Function functor for
WriteFunction example), the callback WriteMemoryCallback must be
declared static, otherwise it won't link...

So it acts like a class member use a static function pointer only
based on curl but not curlpp, such as

static size_t
WriteFunction(char *ptr, size_t size, size_t nmemb, std::string *stream)
{
 if (stream == NULL)
 {
   return 0;
 }

 stream->append(ptr, size * nmemb);
 cout << ptr << endl;

 return size * nmemb;
}

void *
CGI::Print()
{
 curl_easy_setopt(this->curl, CURLOPT_WRITEDATA, &this->buffer);
 curl_easy_setopt(this->curl, CURLOPT_WRITEFUNCTION, WriteFunction);

 return NULL;
}

When I even know the callback functor can not use a member function
pointer, I still modified the example05.cpp to see whether it work or
not, such as:

size_t
Callback::WriteMemoryCallback(char* ptr, size_t size, size_t nmemb)
{
 size_t realsize = size * nmemb;

 this->m_pBuffer = (char*) this->Realloc(this->m_pBuffer,
this->m_Size + realsize);

 if (this->m_pBuffer == NULL) {
   realsize = 0;
 }

 memcpy(&(this->m_pBuffer[this->m_Size]), ptr, realsize);
 this->m_Size += realsize;

 return realsize;
};

void Callback::print()
{
 cURLpp::Types::WriteFunctionFunctor functor(this->*WriteMemoryCallback);
 cURLpp::Options::WriteFunction *test = new
cURLpp::Options::WriteFunction(functor);
 this->request.setOpt(test);
 this->request.perform();

 std::cout << "Content: " << std::endl << this->m_pBuffer << std::endl;
}

And yes '((Callback*)this)->Callback::WriteMemoryCallback' cannot be
used as a member pointer, since it is of type '<unresolved overloaded
function type>'

So the C++ wrapper of curl still can not make callback functor to use
the member function pointer, right?

sirtoozee

-- 
An individual human existence should be like a river - small at first,
narrowly contained within its banks, and rushing passionately past
boulders and over waterfalls. Gradually the river grows wider, the
banks recede, the waters flow more quietly, and in the end, without
any visible break, they become merged in the sea, and painlessly lose
their individual being.
_______________________________________________
cURLpp mailing list
cURLpp_at_rrette.com
http://www.rrette.com/mailman/listinfo/curlpp
Received on 2007-11-23

These mail archives are generated by hypermail.

donate! Page updated November 12, 2010.
web site info

File upload with ASP.NET