[Top][All Lists]

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

Re: [libmicrohttpd] Zero copy MHD_create_response_from_callback

From: Christian Grothoff
Subject: Re: [libmicrohttpd] Zero copy MHD_create_response_from_callback
Date: Thu, 17 Nov 2022 13:24:38 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0

Dear Dan,

Sounds like you should be using MHD_create_response_from_iovec(). That way, you can avoid the memcpy() entirely.

Happy hacking!


On 11/17/22 08:27, Dan Inve wrote:

I'm using libmicrohttpd to respond to an HTTP request for a large amount of
data (sometimes GBs) using external select
and MHD_create_response_from_callback with a known size. The data is
sourced from hardware via a kernel driver. When the HTTP request is
received, data is requested from the hardware, and then transferred in 64MB
chunks to buffers allocated by the driver. Inside of
my MHD_ContentReaderCallback, I check if the data transfer by the driver is
complete, and currently memcpy 'max' bytes of data at a time from the
driver buffer into the 'char *buf' passed to the callback.

I've attempted two methods when it comes to specifying block_size for
If I specify 64MB, the problem is that the memcpy takes too long and blocks
my application loop. I've also tried specifying a small block size like
64KB. However, the response is slow and inefficient because it is only
responding 64KB per loop, which is doing other things as well.

Is there a zero-copy way to use MHD_create_response_from_callback that
doesn't require memcpy'ing the data into buf in the callback? Perhaps by
specifying a pointer to a buffer in the callback (similar to


reply via email to

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