Commit 807724e1 authored by Romain Bignon's avatar Romain Bignon

add a 'maxcon' parameter in daemon{} config block to limit simultaneous connections (refs #224)

parent 1d624488
......@@ -47,6 +47,9 @@ irc {
# If this parameter is enabled, it run MinBif as a daemon.
# stdin, stdout and stderr will be also closed.
background = true
# Maximum simultaneous connections
maxcon = 10
}
# Ping interval in seconds.
......
......@@ -66,6 +66,7 @@ Minbif::Minbif()
sub->AddItem(new ConfigItem_string("bind", "IP address to listen on"));
sub->AddItem(new ConfigItem_int("port", "Port to listen on", 1, 65535), true);
sub->AddItem(new ConfigItem_bool("background", "Start minbif in background", "true"));
sub->AddItem(new ConfigItem_int("maxcon", "Maximum simultaneous connections", 0));
sub = section->AddSection("oper", "Define an IRC operator", MyConfig::MULTIPLE);
sub->AddItem(new ConfigItem_string("login", "Nickname of IRC operator"), true);
......
......@@ -52,6 +52,8 @@ DaemonForkServerPoll::DaemonForkServerPoll(Minbif* application)
throw ServerPollError();
}
maxcon = section->GetItem("maxcon")->Integer();
if(section->GetItem("background")->Boolean())
{
int r = fork();
......@@ -153,6 +155,14 @@ bool DaemonForkServerPoll::new_client_cb(void*)
return true;
}
if(maxcon > 0 && childs.size() >= (unsigned)maxcon)
{
static const char error[] = "ERROR :Closing Link: Too much connections on server\r\n";
send(new_socket, error, sizeof(error), 0);
close(new_socket);
return true;
}
int fds[2];
if(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == -1)
{
......
......@@ -65,6 +65,7 @@ class DaemonForkServerPoll : public ServerPoll
void m_oper(child_t* child, irc::Message m); /**< IPC handler for the OPER command. */
irc::IRC* irc;
int maxcon;
int sock;
int read_id;
_CallBack *read_cb;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment