diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 88cf6d2d..02dae947 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -684,15 +684,30 @@ void NetworkPluginServer::sendPing(Client *c) { } NetworkPluginServer::Client *NetworkPluginServer::getFreeClient() { + NetworkPluginServer::Client *c = NULL; + bool spawnNew = false; for (std::list::const_iterator it = m_clients.begin(); it != m_clients.end(); it++) { if ((*it)->users.size() < CONFIG_INT(m_config, "service.users_per_backend")) { if ((*it)->users.size() + 1 == CONFIG_INT(m_config, "service.users_per_backend")) { - exec_(CONFIG_STRING(m_config, "service.backend").c_str(), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str()); + spawnNew = true; + } + if (c == NULL) { + c = *it; + } + else { + if ((*it)->users.size() + 1 != CONFIG_INT(m_config, "service.users_per_backend")) { + spawnNew = false; + break; + } } - return (*it); } } - return NULL; + + if (spawnNew) { + exec_(CONFIG_STRING(m_config, "service.backend").c_str(), CONFIG_STRING(m_config, "service.backend_host").c_str(), CONFIG_STRING(m_config, "service.backend_port").c_str(), m_config->getConfigFile().c_str()); + } + + return c; } }