On Tuesday 29 June 2010 22:46:22 Carlos Palhares wrote:
> Hello guys, how are you?
>
> I believe you're very busy people, but, I wouldn't bother you if I had
> any other option. First of all, here is a code snippet which I'll
> approach:
>
> int Milx::Server::Daemon::_queue_response(struct MHD_Connection *conn,
> Milx::WebCall &call)
> {
> struct MHD_Response *response;
> std::string content = call.content().str();
> response = MHD_create_response_from_data(content.size(),
> (void*)content.c_str(), MHD_NO, MHD_NO);
> MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE,
> call.content_type().c_str());
> MHD_add_response_header(response, MHD_HTTP_HEADER_SERVER,
> MILX_SERVER_NAME);
> int ret = MHD_queue_response(conn, call.status(), response);
> MHD_destroy_response(response);
>
> return ret;
> }
>
> If I debug on the marked lines, I can clearly see that the field data in
> MHD_Response is being correctly filled, but when it's sent back to the
> HTTP client, the first bytes of the content are totally fuzzy! They're
> changed. Another weird thing is that if I do something like this:
>
> const char * tmp = "testing string";
> response = MHD_create_response_from_data(strlen(tmp),
> tmp, MHD_NO, MHD_NO);
>
> it simple works perfectly!!!
>
> So guys, do you guys have any clue?
Yes, the pointer returned by 'content.c_str()' is freed by C++ after the call,