[Top][All Lists]

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

Re: [libmicrohttpd] libmicrohttpd with c++ issue

From: Christian Grothoff
Subject: Re: [libmicrohttpd] libmicrohttpd with c++ issue
Date: Wed, 30 Jun 2010 15:10:45 +0200
User-agent: KMail/1.13.3 (Linux/2.6.32-trunk-vserver-amd64; KDE/4.4.4; x86_64; ; )

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,
>       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, 
and MHD (based on your options) did not make a copy.  Simply use:

        response = MHD_create_response_from_data(content.size(),
                                (void*)content.c_str(), MHD_NO, MHD_YES);

and it should work (assuming there is nothing else).



reply via email to

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