libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] large incremental responses


From: Erik Smith
Subject: Re: [libmicrohttpd] large incremental responses
Date: Fri, 3 Dec 2021 09:40:07 -0800

Hi Evgeny,

That's mostly how I understood it from past experience.  To use that directly, it does require that my producer logic be written in a callback style: like a state function that's producing a chunk of content at a time. Secondly it must only send up to max bytes, which will require buffer management.   So this does complicate that logic when compared to the synchronous thread-per-request style.   My near term option appears to be to use a worker thread that writes content into a buffer with the appropriate concurrency control.  Eventually I would like to adopt a fiber approach and it would be good to know if anyone has experience with that.  

Erik
 
Hi Erik,
You need to create response by MHD_create_response_from_callback(). Use 'MHD_SIZE_UNKNOWN' if size is not known in advance. When data callback is called by MHD, provide all data you have at that moment (but not more than requested by MHD of course). If you don't have any data available call MHD_suspend_connection(). Later, when you get new portion of data ready to send, call MHD_resume_connection() then data callback will be called automatically by MHD.
Does it suit your needs?
--
Evgeny
On 02.12.2021 21:53, Erik Smith wrote:
If I want to send a large response that takes time to generate and have the response sent incrementally in a push style (regular write calls in synchronous code, not callbacks) so that the client doesn't time out, how would I do that?  Is that something I'm going to have to write some concurrency mechanism for so that I can use a callback or is there a simpler way?


reply via email to

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