[Top][All Lists]

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

Re: [libmicrohttpd] Request for documenting MHD_quiesce_daemon

From: Christian Grothoff
Subject: Re: [libmicrohttpd] Request for documenting MHD_quiesce_daemon
Date: Sun, 28 Sep 2014 16:51:18 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Icedove/24.8.0


On 09/28/14 15:30, Rafał Miłecki wrote:
> Hello MHD devs/fans :)
> I was trying to find a way to cleanly shutdown my HTTP server. I
> wanted to stop accepting new connections and then wait up to few
> seconds for the active ones to be closed.
> Initially I wanted to implement it on my own, but then I found out
> there is no way to get amount of active connections. Ofc it's open
> source, so I found appropriate patch:
> but I didn't really want to require patched libmicrohttpd.
> Then I accidentally found out there is something called
> MHD_quiesce_daemon. Unfortunately it's poorly documented and I'm not
> sure if this is what I want at all.

It likely is.

> Could you document this function, please? I think it could be described in the
> 5 Starting and stopping the server
> chapter of the manual.

It is in there (but maybe no in the version on the website). In
Subversion, it says:

@deftypefun int MHD_quiesce_daemon (struct MHD_Daemon *daemon)
@cindex quiesce
Stop accepting connections from the listening socket.  Allows clients
to continue processing, but stops accepting new connections.  Note
that the caller is responsible for closing the returned socket;
however, if MHD is run using threads (anything but external select
mode), it must not be closed until AFTER @code{MHD_stop_daemon} has
been called (as it is theoretically possible that an existing thread
is still using it).

This function is useful in the special case that a listen socket
is to be migrated to another process (i.e. a newer version of the
HTTP server) while existing connections should continue to be
processed until they are finished.

Return @code{-1} on error (daemon not listening), the handle to the
listen socket otherwise.

@end deftypefun

> This would be more than great to also provide some example in the tutorial:
> My guess (after reading daemon.c) is that I need to call:
> 1) MHD_quiesce_daemon
> 2) MHD_stop_daemon
> 3) MHD_socket_close_
> is that correct?

Yes; now for (3) you may just want to call "close()" directly, it's a
normal listen socket after all.

> Is there any way to check at some point, if there are
> any remaining connections? Let's say I call MHD_quiesce_daemon, then
> I'd like to wait up to 60 seconds for all connections being closed.
> Obviously, if they will be closed after 5 seconds (out of 60), I want
> to quit earlier. Is this possible with the provided tools?

You could use the MHD_get_fdset() and similar APIs to check if MHD still
has any sockets it is select()/poll()-ing on (or waiting for timeout),
and if that set is empty and timeout is infinite, you know MHD is done.

> Thanks for the great library and your work on this :)

You're welcome.

Happy hacking!


reply via email to

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