From 00f02b19ad8ce2f8f0195d3610e06566bf68cd0c Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Fri, 10 Feb 2023 19:34:47 +0100 Subject: Added connection limit --- whiteboard.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'whiteboard.cpp') 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(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(m_registry, *m_storage, m_storage_mutex, std::move(socket))->run(); + } } do_accept(); -- cgit v1.2.3