libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] issue in storing incrementally received data chunks


From: Kenneth Mastro
Subject: Re: [libmicrohttpd] issue in storing incrementally received data chunks from upload_data
Date: Tue, 24 Feb 2015 08:46:59 -0500

I'm not an expert, but I kind of doubt that 'upload_data' is a null-terminated string.  It probably just stops at the number of bytes that were specified in 'upload_data_size' and has garbage after that.

So - your std::string.append call is probably adding more than it needs to because it's looking for a null terminator for when to stop.  Try using the 'append' function that takes a size:

xmlDataString.append(upload_data, *upload_data_size);

As a side note - you may also want to consider using a stringstream instead of a std::string.  Should be a lot more efficient than repeatedly calling 'append' like this.


Hope that helps.


Ken



On Tue, Feb 24, 2015 at 8:23 AM, dumitrița munteanu <address@hidden> wrote:

Hello all, 

I am using MHD daemon server in order to send incrementally large strings containing xml data

The size of the sent data chuck(from curls) is equal with the sum of the received data chucks
(received data size in MHD daemon server  == sum of all upload_data_size for a specific connection).

The problem is that the string in which i append incrementally the data chunks as they arrive   is always bigger than the data it has been sent/received. 

I do not understand where from comes this additional data and why my postXMLData variable gets always larger. 
 

My code looks like this: 

static postXMLData = "";

static int AnswerToConnection (void *cls, struct MHD_Connection *connection, 
const char *url, const char *method, const char *version,
const char *upload_data, size_t *upload_data_size, void **con_cls)
{  
static int i;

// the first call - initialize data structures
if (*con_cls == NULL)
{
*con_cls = &i;
 
return MHD_YES;
}

// next calls - receive data incrementally
if (*upload_data_size != 0)
{
         xmlDataString.append(upload_data); 

(*upload_data_size) = 0;

return MHD_YES;
}

// last call -  upload_data_size = 0 - processed received data
if (*upload_data_size == 0) 
{
FILE *f; f=fopen("test_data_output_2.txt", "w"); fprintf(f, "%s", postXMLData .c_str()); fclose(f);
   
  int ret = pProcessRequest->SendPage(connection, ANSWER_PAGE);
  return ret;
}   


reply via email to

[Prev in Thread] Current Thread [Next in Thread]