libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] MHD_RESPMEM_PERSISTENT


From: Mark Wagner
Subject: Re: [libmicrohttpd] MHD_RESPMEM_PERSISTENT
Date: Tue, 24 Jan 2017 20:01:01 -0800

On Tue, Jan 24, 2017 at 3:17 AM, Miguel Sancho
<address@hidden> wrote:
> Hi,
> using the MHD_RESPMEM_PERSISTENT option I am getting an error. The following
> HTTP response gives a corrupt file when downloading from
> libmicrohttpd.0.9.50. However same code with MHD_RESPMEM_MUST_COPY option
> works fine:
>
> response = MHD_create_response_from_buffer(size,(void*)buffer,
>
> MHD_RESPMEM_PERSISTENT);
> ret = MHD_queue_response (connection, 200, response);
> MHD_destroy_response (response);
> free(buffer);
>
> The buffer isn't changed for at least the lifetime of the response, what is
> wrong here?

You're making some incorrect assumptions about the lifetime of the
response object.  MHD_queue_response() means "send the response when
you get a chance", while MHD_destroy_response() means "I'm done with
my pointer to the response; feel free to release the response object
when you're done with it".  As far as I'm aware, there's no way to
know when the library is actually done with the response object.

MHD_RESPMEM_PERSISTENT should really only be used for response buffers
that are truly persistent: things like static strings, or files that
are loaded at program startup and kept in memory until termination.
It may be safe to free the buffer when the
MHD_RequestCompletedCallback is called, but the documentation is
unclear about this.

-- 
Mark



reply via email to

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