libmicrohttpd
[Top][All Lists]
Advanced

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

[libmicrohttpd] MHD_quiesce_daemon() question


From: silvioprog
Subject: [libmicrohttpd] MHD_quiesce_daemon() question
Date: Sun, 26 Mar 2017 02:33:29 -0300

Hello masters,

I found the following related message:

https://lists.gnu.org/archive/html/libmicrohttpd/2014-09/msg00012.html

I've used a similar logic, but with item X below, because I need to wait the client processing:

1) MHD_quiesce_daemon()
X) while (info.num_connections > 0) sleep(0.5s) # pseudo code
2) MHD_stop_daemon()
3) close()

Real implementation:

bool bf_httpsrv_shutdown(struct bf_httpsrv *srv, bool force) {
MHD_socket fd;
if (srv && srv->listening) {
fd = MHD_quiesce_daemon(srv->mhd);
if (!force)
while (MHD_get_daemon_info(srv->mhd, MHD_DAEMON_INFO_CURRENT_CONNECTIONS)->num_connections > 0)
usleep(1000 * 500); //TODO: allow to use external callback
MHD_stop_daemon(srv->mhd);
if (fd != MHD_INVALID_SOCKET)
close(fd);
srv->listening = false;
return true;
}
return false;
}

Calling it with bf_httpsrv_shutdown(srv, false) the server stops waiting for clients processing.

So, what do you think about the logic above? Should it be improved?!

Thanks in advance for any suggestions!

--
Silvio Clécio

reply via email to

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