From 3aa93e62e7243c9564bae169b204912dee9492f1 Mon Sep 17 00:00:00 2001 From: An Tao Date: Fri, 18 Aug 2023 15:31:11 +0800 Subject: [PATCH] Add getConnectionCount method (#1731) --- lib/inc/drogon/HttpAppFramework.h | 4 ++++ lib/src/HttpAppFrameworkImpl.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/lib/inc/drogon/HttpAppFramework.h b/lib/inc/drogon/HttpAppFramework.h index 5be17c48..88911196 100644 --- a/lib/inc/drogon/HttpAppFramework.h +++ b/lib/inc/drogon/HttpAppFramework.h @@ -1521,6 +1521,10 @@ class DROGON_EXPORT HttpAppFramework : public trantor::NonCopyable virtual HttpAppFramework &enableCompressedRequest(bool enable = true) = 0; virtual bool isCompressedRequestEnabled() const = 0; + /* + * @brief get the number of active connections. + */ + virtual int64_t getConnectionCount() const = 0; private: virtual void registerHttpController( diff --git a/lib/src/HttpAppFrameworkImpl.h b/lib/src/HttpAppFrameworkImpl.h index 8d62cc19..4f689eb5 100644 --- a/lib/src/HttpAppFrameworkImpl.h +++ b/lib/src/HttpAppFrameworkImpl.h @@ -606,6 +606,11 @@ class HttpAppFrameworkImpl final : public HttpAppFramework const std::string &ext, const std::string &mime) override; + int64_t getConnectionCount() const override + { + return connectionNum_.load(std::memory_order_relaxed); + } + private: void registerHttpController(const std::string &pathPattern, const internal::HttpBinderBasePtr &binder,