[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] multipart/form-data Partial Write in Iterator
From: |
Evgeny Grin |
Subject: |
Re: [libmicrohttpd] multipart/form-data Partial Write in Iterator |
Date: |
Wed, 9 Aug 2023 18:41:57 +0300 |
User-agent: |
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 |
Hi Gregory,
Unfortunately currently MHD has no API to attach arbitrary FD to
internal event loop.
However, there are several ways how to handle it correctly.
The easiest way is thread-per-connection mode (flag
MHD_USE_THREAD_PER_CONNECTION). In this mode individual threads are
created for every connection. As every thread is responsible for a
single connection only, you can use blocking writes, and this will not
affect other requests/connections.
The proper way of handling it in other modes is more complicated. You
can report partial processing of the upload data by setting
`*upload_data_size` to non-zero value. However, this cause MHD to
iterate over all connections wait for new network event and call "access
handler" callback again, but only when something happens on the
monitored sockets. The next MHD version will not wait for new data in
such case, but call callback after iterating all connections. To handle
partial write situation correctly, when incomplete data was processed by
write you need to setup some external watcher for the file FD and call
MHD_suspend_connection() before return from access handler. Then watcher
should call MHD_resume_connection() when more data could be written to
the file.
If you are not expecting very high traffic and you file storage device
is not very slow, you can use blocking writes even without
thread-per-connection. It will delay processing other requests' data but
significantly simplify your code logic. When using thread pool, it will
delay data processing only for connection in the same thread.
--
Evgeny
On 08.08.2023 14:46, Gregory Oakes via libmicrohttpd wrote:
Hello everyone,
I'm currently writing an application using libmicrohttpd, and I've
encountered a question that I can't find an answer to in the manual. I
am handling a file upload on a POST request by writing the contents to
a temporary file. When I went to actually write the data, it struck me
that the write would block the event loop.
Am I able to attach my file write to libmicrohttpd's event loop
somehow? Otherwise, am I able to report a partial write in the
iterator?
Respectfully,
Gregory Oakes
OpenPGP_0x460A317C3326D2AE.asc
Description: OpenPGP public key
OpenPGP_signature
Description: OpenPGP digital signature