|
From: | silvioprog |
Subject: | Re: [libmicrohttpd] MHD threading models: what model is similar to Least Connected? |
Date: | Mon, 5 Dec 2016 14:46:16 -0300 |
You will need something like:
-----------------
size_t N = 0; /* number of inited daemons */
size_t n = 0; /* current worker */
MHD_Daemon* daemons[MAX_DAEMONS];
daemons[N++] = MHD_start_daemon (MHD_USE_NO_LISTEN_SOCKET |
MHD_USE_SELECT_INTERNALLY, ....);
while (processingAllowed())
{
int fd = accept (listen_fd, &addr, &addrlen);
if (-1 == fd)
continue;
if (!isSomeFunctionOfMyAppResponding())
{
if (N < MAX_DAEMONS)
{ /* Add new daemon if space is available */
daemons[N++] = MHD_start_daemon (MHD_USE_NO_LISTEN_SOCKET |
MHD_USE_SELECT_INTERNALLY, ....);
}
n++; /* Switch to next worker */
if (MAX_DAEMONS == n)
{
n = 0; /* Return processing to first daemon */
}
}
MHD_add_connection (daemons[n], fd, &addr, &addrlen);
}
-----------------
"Slow" daemons will continue processing their connections, when slowdown
is detected, you will switch new connections to next daemon.
--
Best Wishes,
Evgeny Grin
[Prev in Thread] | Current Thread | [Next in Thread] |