mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-25 21:15:49 +00:00
Check file handle limit on startup (RIPD-442, RIPD-1024):
Calculate the number of file descriptors that are needed during execution based on the configuration file, with a hard floor of 1024, adjusting the limit if possible. Refuse to run if enough fds are not available. Additionally, allow administrators to limit the number of incoming connections a configured port will accept. By default no limit is imposed.
This commit is contained in:
@@ -94,15 +94,22 @@ ServerHandlerImp::onStop()
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
void
|
||||
ServerHandlerImp::onAccept (Session& session)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
ServerHandlerImp::onAccept (Session& session,
|
||||
boost::asio::ip::tcp::endpoint endpoint)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(countlock_);
|
||||
|
||||
auto const c = ++count_[session.port()];
|
||||
|
||||
if (session.port().limit && c >= session.port().limit)
|
||||
{
|
||||
JLOG (m_journal.trace()) <<
|
||||
session.port().name << " is full; dropping " <<
|
||||
endpoint;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -188,6 +195,8 @@ void
|
||||
ServerHandlerImp::onClose (Session& session,
|
||||
boost::system::error_code const&)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(countlock_);
|
||||
--count_[session.port()];
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user