libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] libmicrohttpd with c++ issue


From: Carlos Henrique Júnior
Subject: Re: [libmicrohttpd] libmicrohttpd with c++ issue
Date: Wed, 30 Jun 2010 12:25:58 -0300

It's working!!!!! thank you dude!! :D


Carlos Júnior <address@hidden>
www.milk-it.net
+55 31 8763-5606
+55 31 3227-1009


On Wed, Jun 30, 2010 at 10:10 AM, Christian Grothoff <address@hidden> wrote:
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,
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).

Best,

Christian


reply via email to

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