[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] MHD_connection_close API
From: |
Evgeny Grin |
Subject: |
Re: [libmicrohttpd] MHD_connection_close API |
Date: |
Tue, 01 Dec 2015 22:01:05 +0300 |
I'd like to add that calling shutdown() on socket will not trigger select() on
many platforms.
If you unsure that you'll need to keep-alive on socket - always add
"Connection: Close" header. It's absolutely safe and do not have any noticeable
drawbacks.
--
Best Wishes,
Evgeny Grin
01.12.2015, 18:08, "Christian Grothoff" <address@hidden>:
> 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