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 --- config.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'config.cpp') diff --git a/config.cpp b/config.cpp index d59156f..afb5cd2 100644 --- a/config.cpp +++ b/config.cpp @@ -14,6 +14,7 @@ namespace { const uint64_t default_maxage{0}; // timeout in seconds; 0 = no timeout const std::string default_listen {"::1:9000"}; const int default_threads{1}; + const int default_max_connections{1000}; } Config::Config(const std::string& config_filename): @@ -21,7 +22,8 @@ Config::Config(const std::string& config_filename): m_maxage{default_maxage}, m_listenAddress{"::1"}, m_listenPort{9000}, - m_threads{default_threads} + m_threads{default_threads}, + m_max_connections{default_max_connections} { try { @@ -42,6 +44,8 @@ Config::Config(const std::string& config_filename): throw std::runtime_error("Bad listen port: "s + std::to_string(m_listenPort)); m_threads = tree.get("config.threads", default_threads); + + m_max_connections = tree.get("config.maxconnections", default_max_connections); } catch (const std::exception& ex) { std::cerr << "Error reading config file " << config_filename << ". Using defaults." << std::endl; } @@ -71,3 +75,9 @@ int Config::getThreads() const { return m_threads; } + +int Config::getMaxConnections() const +{ + return m_max_connections; +} + -- cgit v1.2.3