Hi Nicolas, On 04.05.2017 3:18, Nicolas Mora wrote: > I'm currently working on an implementation of a websocket manager with > MHD and it's getting pretty good so far. > > The problem I have is when the daemon is shut down and there are open > connections. The documentation on MHD_quiesce_daemon says that "Note > that the caller is responsible for closing the returned socket;" which > is close to what I have, but since a websocket can be left open > indefinitely, I need to know if the daemon needs to stop. MHD_quiesce_daemon() prevent MHD from accepting new connections but allow to continue processing with current connections. The returned socket is listening socket. > Is there a signal or an event or any other way for the upgrade_handler > function to know that a MHD_quiesce_daemon or a MHD_stop_daemon has > been sent ?
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(). 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? -- Best Wishes, Evgeny Grin
