Skip to content

Commit

Permalink
Added user limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
cathyjf committed Oct 24, 2010
1 parent 7005895 commit 499756b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const char *getPidFileName() {

int initialise(int argc, char **argv, bool &daemon) {
string configFile;
int port, databasePort, workerThreads, serverUid;
int port, databasePort, workerThreads, serverUid, userLimit;
string serverName, welcomeFile, welcomeMessage;
string databaseName, databaseHost, databaseUser, databasePassword;
string authParameter, loginParameter, registerParameter;
Expand All @@ -80,6 +80,10 @@ int initialise(int argc, char **argv, bool &daemon) {
po::value<int>(&port)->default_value(
8446),
"server port")
("server.limit",
po::value<int>(&userLimit)->default_value(
-1),
"maximum number of users allowed")
("server.threads",
po::value<int>(&workerThreads)->default_value(
20),
Expand All @@ -88,7 +92,7 @@ int initialise(int argc, char **argv, bool &daemon) {
po::value<int>(&serverUid),
"UID to run the server process as")
("auth.salt",
"use simple simple authentication")
"use simple salt authentication")
("auth.vbulletin",
po::value<string>(
&authParameter)->implicit_value("vbulletin"),
Expand Down Expand Up @@ -278,7 +282,7 @@ int initialise(int argc, char **argv, bool &daemon) {
}
}

network::Server server(port);
network::Server server(port, userLimit);
server.installSignalHandlers();

ScriptMachine *machine = server.getMachine();
Expand Down
15 changes: 11 additions & 4 deletions src/network/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ typedef pair<string, string> CLAUSE_PAIR;

class ServerImpl {
public:
ServerImpl(Server *, const int);
ServerImpl(Server *, const int, const int);
Server *getServer() const { return m_server; }
void installSignalHandlers();
void run();
Expand Down Expand Up @@ -697,6 +697,7 @@ class ServerImpl {
ChannelPtr m_mainChannel;
CLIENT_LIST m_clients;
int m_population;
const int m_userLimit;
shared_mutex m_clientMutex;
io_service m_service;
tcp::acceptor m_acceptor;
Expand All @@ -717,8 +718,8 @@ class ServerImpl {

ServerImpl *ServerImpl::m_blockingServer = NULL;

Server::Server(const int port) {
m_impl = new ServerImpl(this, port);
Server::Server(const int port, const int userLimit) {
m_impl = new ServerImpl(this, port, userLimit);
}

void Server::installSignalHandlers() {
Expand Down Expand Up @@ -2099,8 +2100,9 @@ ServerImpl::ClauseList::ClauseList(vector<CLAUSE_PAIR> &clauses)
finalise();
}

ServerImpl::ServerImpl(Server *server, const int port):
ServerImpl::ServerImpl(Server *server, const int port, const int userLimit):
m_population(0),
m_userLimit(userLimit),
m_acceptor(m_service, tcp::endpoint(tcp::v4(), port), true),
m_server(server) {
acceptClient();
Expand Down Expand Up @@ -2380,6 +2382,11 @@ void ServerImpl::handleAccept(ClientImplPtr client,
<< error.message() << endl;
return;
}
if (m_population > m_userLimit) {
boost::system::error_code ec;
client->getSocket().close(ec);
return;
}
const boost::system::error_code startError = client->start();
if (startError) {
Log::out() << "Error in ClientImpl::start(): "
Expand Down
2 changes: 1 addition & 1 deletion src/network/network.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Client {

class Server {
public:
Server(const int port);
Server(const int port, const int userLimit);
~Server();
void installSignalHandlers();
void run();
Expand Down

0 comments on commit 499756b

Please sign in to comment.