libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] MHD_connection_close API


From: Robert Groenenberg
Subject: Re: [libmicrohttpd] MHD_connection_close API
Date: Wed, 2 Dec 2015 19:42:11 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0

Hi Christian,

Well, dropping a connection may not be very clean, but that was only to avoid waiting for a request only close it at that point. It's certainly not intended to be a 'hackish' implementation. As MHD_connection_close() is not really thread safe, I'll go for adding the 'Close' header at least when there is a request pending. For now I'll reject new incoming request by returning MHD_NO.

Thanks for your input!

Cheers,
Robert

On 12/01/2015 04:07 PM, Christian Grothoff wrote:
Hi Robert,

I see. The issue is that there is no good way to do this safely (in all
threading modes).  MHD may internally be trying to close the connection
(i.e. timeout, client close), so especially if you're multi-threaded,
there is no 'safe' way for you to just call MHD_connection_close().

If you're in single-threaded mode, you could be sure that MHD doesn't
currently try the same thing, but that's a very specific case.  For that
case, I have a slightly hackish but reasonable alternative: just call
MHD_get_connection_info() to get the *socket* of the connection and call
'shutdown()' (for reading at least) on that socket. This will unblock
the socket on select() and cause future read attempts by MHD to fail,
forcing MHD to shutdown the connection as intended.

Given that you're doing something a bit outside of the HTTP
specification here (in the sense of being really impolite and tearing
down a running connection, possibly dropping data in transmission from
the HTTP client), I think this hackish method matches the level of hack
you desire here ;-).

Note that in multi-threaded modes, doing this effectively means that you
risk calling shutdown() on a totally unrelated socket, so you may want
to abstain from this hack in such a setting...

I hope this helps!


Happy hacking!

Christian



On 12/01/2015 02:31 PM, Robert Groenenberg wrote:
Hi Christian,

Let me first clarify the scenario a bit more: the goal is to close the
connection from a client in case the configuration in the application
wrt this client has changed.

I do agree that for a request being processed it would be best to add a
"Connection: Close" header and I probably should do that :)
However, this still leaves the cases where the response has already been
handed to MHD before the need to close the connection arises. The next
opportunity to do so is then when the response is sent (NOTIFY_COMPLETED).
When there are no requests in progress, I'd like to be able to drop the
connection without waiting for it to send a request and then close the
connection.

Cheers,
Robert




reply via email to

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