Next: , Previous: , Up: Top   [Contents][Index]

9 Flow control.

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.

Function: int MHD_suspend_connection (struct MHD_Connection *connection)

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_USE_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

Function: int MHD_resume_connection (struct MHD_Connection *connection)

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.


the connection to resume

Next: , Previous: , Up: Top   [Contents][Index]