libmicrohttpd
[Top][All Lists]
Advanced

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

Re: [libmicrohttpd] How to close all upgraded connections when shutting


From: Nicolas Mora
Subject: Re: [libmicrohttpd] How to close all upgraded connections when shutting down MHD_Daemon?
Date: Thu, 4 May 2017 07:47:58 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Hi,

Thanks Evgeny and Silvio for your help

Le 2017-05-04 à 03:02, Evgeny Grin a écrit :
MHD_quiesce_daemon() prevent MHD from accepting new connections but
allow to continue processing with current connections.
The returned socket is listening socket.

Actually, I'm not using MHD_quiesce_daemon() at all, just MHD_stop_daemon(). I talked about MHD_quiesce_daemon() because in the online documentation, the phrase I quote is below MHD_quiesce_daemon().

You can track quiesced state of MHD in some global variable (if you are
using single MHD instance) or in local variable associated with MHD
instance. You will need to update this variable when you quiesced MHD.
In upgrade_handler you can check current state of MHD by checking variable.
Keep in mind that MHD will not accept new connection after
MHD_quiesce_daemon(), so upgrade_handler will be called after
MHD_quiesce_daemon() if connection was accepted before
MHD_quiesce_daemon() but not yet "upgraded".

MHD_stop_daemon() will close all connections including "upgraded"
connections. So you can't use "upgraded" connections after
MHD_stop_daemon().

The problem I have is that MHD_stop_daemon() doesn't close all the connections. Instead, it looks like it waits for the active connections to close by themselves and I have the following log message:
Initiated daemon shutdown while "upgraded" connection was not closed.

Could you explain a bit more situation that you need to solve?
Do you want to implement graceful MHD shutdown after closing all
upgraded connections?

I guess what I'd rather have is for the upgraded connections to be closed by MHD when MHD_stop_daemon() is called, so the upgrade callback could interpret it easily. Silvio's suggestion might work too, some signal like a "MHD_DAEMON_INFO_WAS_QUIESCED" or, in my case "MHD_DAEMON_INFO_WAS_STOPPED".

My current implementation is the following.
When a websocket upgrade is called by the client, the websocket callback is executed:
https://github.com/babelouest/ulfius/blob/2.0/src/ulfius.c#L432
Then the program loops on listening to the socket
https://github.com/babelouest/ulfius/blob/2.0/src/u_websocket.c#L115

But in my example program, when the user stops the program by pressing the <enter> key while connections are active, the program doesn't stop and waits for the open websockets to close.
https://github.com/babelouest/ulfius/blob/2.0/example_programs/websocket_example/websocket_example.c



reply via email to

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