Do not create a new socket if the max. number of clients is attained

Fixes coverity issue 23431.
This commit is contained in:
Jean-Marc Lasgouttes 2015-02-20 15:46:34 +01:00
parent 3db4b23b3f
commit 4a439d6ac0

View File

@ -97,6 +97,11 @@ string const ServerSocket::address() const
// is OK and if the number of clients does not exceed MAX_CLIENTS
void ServerSocket::serverCallback()
{
if (clients.size() >= MAX_CLIENTS) {
writeln("BYE:Too many clients connected");
return;
}
int const client_fd = socktools::accept(fd_);
if (fd_ == -1) {
@ -104,11 +109,6 @@ void ServerSocket::serverCallback()
return;
}
if (clients.size() >= MAX_CLIENTS) {
writeln("BYE:Too many clients connected");
return;
}
// Register the new client.
clients[client_fd] =
shared_ptr<LyXDataSocket>(new LyXDataSocket(client_fd));