diff options
author | Roland Reichwein <mail@reichwein.it> | 2023-02-10 19:34:47 +0100 |
---|---|---|
committer | Roland Reichwein <mail@reichwein.it> | 2023-02-10 19:34:47 +0100 |
commit | 00f02b19ad8ce2f8f0195d3610e06566bf68cd0c (patch) | |
tree | bf35dbcd980505ba9bc3404edb0921966b51cecf /whiteboard.cpp | |
parent | cba42916126a1baed33a6f122a5301982993d344 (diff) |
Added connection limit
Diffstat (limited to 'whiteboard.cpp')
-rw-r--r-- | whiteboard.cpp | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/whiteboard.cpp b/whiteboard.cpp index 6a71d3b..044321b 100644 --- a/whiteboard.cpp +++ b/whiteboard.cpp @@ -437,7 +437,12 @@ void Whiteboard::on_accept(boost::system::error_code ec, boost::asio::ip::tcp::s if (ec) { std::cerr << "Error on accept: " << ec.message() << std::endl; } else { - std::make_shared<session>(m_registry, *m_storage, m_storage_mutex, std::move(socket))->run(); + if (m_registry.number_of_connections() >= m_config->getMaxConnections()) { + // limit reached + socket.close(); + } else { + std::make_shared<session>(m_registry, *m_storage, m_storage_mutex, std::move(socket))->run(); + } } do_accept(); |