process: make max number of children (connections) configurable

At least some Panasonic clients try to open more than 5 simultaneous
connections to the server.  If we keep the default of 5 max children,
it results in choppy playback on those clients.

Make this setting configurable, and default to 50 max connections.
Our process is pretty lightweight, so 50 children should not be a
problem on most systems.
This commit is contained in:
Justin Maggard
2014-03-03 13:32:20 -08:00
parent 372afa1ae6
commit 1a78a94f70
6 changed files with 33 additions and 7 deletions

View File

@ -38,18 +38,20 @@
#include <signal.h>
#include <sys/wait.h>
#include "upnpglobalvars.h"
#include "process.h"
#include "config.h"
#include "log.h"
static const int max_number_of_children = 5;
static int number_of_children = 0;
pid_t
process_fork(void)
{
if (number_of_children >= max_number_of_children)
if (number_of_children >= runtime_vars.max_connections)
{
DPRINTF(E_WARN, L_GENERAL, "Exceeded max connections [%d], not forking\n",
runtime_vars.max_connections);
errno = EAGAIN;
return -1;
}
@ -63,8 +65,21 @@ process_fork(void)
void
process_handle_child_termination(int signal)
{
waitpid(-1, NULL, WNOHANG);
--number_of_children;
pid_t pid;
while ((pid = waitpid(-1, NULL, WNOHANG)))
{
if (pid == -1)
{
if (errno == EINTR)
continue;
else
break;
}
else if (pid == 0)
break;
--number_of_children;
}
}
int