curl-library
Question regarding limiting the response size in a client using libcurl
Date: Tue, 29 Apr 2014 15:33:25 -0400
Hi,
I am writing a C client using libcurl to communicate with a proprietary
server. I am registering a function handle to receive the response from the
server using something like:
*****************************************
curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, responseBodyReceiver );
*****************************************
I want to stop reading response and close connection from the client if the
total data received exceeds some preset response size limit.
So, I want the responseBodyReceiver to look something like:
*****************************************
size_t responseBodyReceiver(void *buffer, size_t size, size_t nmemb, void
*userp)
{
size_t realsize = size * nmemb;
ResponseData *mem = static_cast<ResponseData*>(userp);
size_t newSize = mem->size + realsize;
if( newSize > RESPONSE_SIZE_LIMIT ){
// I would like to stop reading and exit. But want to
// break connection from the client side before I exit
}else{
mem->memory = (char*)realloc( mem->memory, newSize );
memcpy( &(mem->memory[mem->size]), buffer, realsize );
mem->size = newSize;
return realsize;
}
}
*****************************************
I am not sure how I can exit the responseBodyReceiver by closing the
connection from the client side.
Any help would be highly appreciated,
Thanks
Sachin
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-04-29