libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] MHD_connection_close API


From: Christian Grothoff
Subject: Re: [libmicrohttpd] MHD_connection_close API
Date: Tue, 1 Dec 2015 16:07:55 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.3.0

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

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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