Next: microhttpd-dauth, Previous: microhttpd-responses, Up: Top [Contents][Index]
Sometimes it may be possible that clients upload data faster
than an application can process it, or that an application
needs an extended period of time to generate a response.
If MHD_USE_THREAD_PER_CONNECTION
is used, applications
can simply deal with this by performing their logic within the
thread and thus effectively blocking connection processing
by MHD. In all other modes, blocking logic must not be
placed within the callbacks invoked by MHD as this would also
block processing of other requests, as a single thread may be
responsible for tens of thousands of connections.
Instead, applications using thread modes other than
MHD_USE_THREAD_PER_CONNECTION
should use the
following functions to perform flow control.
Suspend handling of network data for a given connection. This can be used to dequeue a connection from MHD’s event loop (external select, internal select or thread pool; not applicable to thread-per-connection!) for a while.
If you use this API in conjunction with a internal select or a
thread pool, you must set the option MHD_ALLOW_SUSPEND_RESUME
to
ensure that a resumed connection is immediately processed by MHD.
Suspended connections continue to count against the total number of connections allowed (per daemon, as well as per IP, if such limits are set). Suspended connections will NOT time out; timeouts will restart when the connection handling is resumed. While a connection is suspended, MHD will not detect disconnects by the client.
The only safe time to suspend a connection is from the
MHD_AccessHandlerCallback
or from the respective
MHD_ContentReaderCallback
(but in this case the
response object must not be shared among multiple
connections).
Finally, it is an API violation to call MHD_stop_daemon
while
having suspended connections (this will at least create memory and
socket leaks or lead to undefined behavior). You must explicitly
resume all connections before stopping the daemon.
the connection to suspend
Resume handling of network data for suspended connection. It is safe to resume a suspended connection at any time. Calling this function on a connection that was not previously suspended will result in undefined behavior.
If you are using this function in “external” select mode, you must
make sure to run MHD_run
afterwards (before again calling
MHD_get_fdset
), as otherwise the change may not be reflected in
the set returned by MHD_get_fdset
and you may end up with a
connection that is stuck until the next network activity.
You can check whether a connection is currently suspended using
MHD_get_connection_info
by querying for
MHD_CONNECTION_INFO_CONNECTION_SUSPENDED
.
the connection to resume
Next: microhttpd-dauth, Previous: microhttpd-responses, Up: Top [Contents][Index]