diff --git a/lib_fiber/cpp/include/fiber/master_fiber.hpp b/lib_fiber/cpp/include/fiber/master_fiber.hpp index fdece48f0..b7cf4a1b7 100644 --- a/lib_fiber/cpp/include/fiber/master_fiber.hpp +++ b/lib_fiber/cpp/include/fiber/master_fiber.hpp @@ -34,6 +34,19 @@ class FIBER_CPP_API master_fiber : public master_base { */ const char* get_conf_path(void) const; + /** + * 获得当前服务总连接数 + * @return {long long} + */ + long long users_count(); + + /** + * 修改当前服务连接数 + * @param n {int} 增加或减少(可以为负数)的连接数值 + * @return {long long} 返回修改的连接数 + */ + long long users_count_add(int n); + protected: master_fiber(void); diff --git a/lib_fiber/cpp/src/fiber_server.cpp b/lib_fiber/cpp/src/fiber_server.cpp index f81987439..1448d7da3 100644 --- a/lib_fiber/cpp/src/fiber_server.cpp +++ b/lib_fiber/cpp/src/fiber_server.cpp @@ -118,6 +118,24 @@ const char *acl_fiber_server_conf(void) return __conf_file; } +long long acl_fiber_server_users_count_add(int n) +{ + if (__clock) { + return acl_atomic_clock_users_add(__clock, n); + } else { + return 0; + } +} + +long long acl_fiber_server_users_count() +{ + if (__clock) { + return acl_atomic_clock_users(__clock); + } else { + return 0; + } +} + static void fiber_client(ACL_FIBER *fiber acl_unused, void *ctx) { ACL_VSTREAM *cstream = (ACL_VSTREAM *) ctx; diff --git a/lib_fiber/cpp/src/fiber_server.hpp b/lib_fiber/cpp/src/fiber_server.hpp index adc9848b2..b2b5a464f 100644 --- a/lib_fiber/cpp/src/fiber_server.hpp +++ b/lib_fiber/cpp/src/fiber_server.hpp @@ -1,5 +1,8 @@ #pragma once const char *acl_fiber_server_conf(void); +long long acl_fiber_server_users_count_add(int n); +long long acl_fiber_server_users_count(); + void acl_fiber_server_main(int argc, char *argv[], void (*service)(void*, ACL_VSTREAM*), void *ctx, int name, ...); diff --git a/lib_fiber/cpp/src/master_fiber.cpp b/lib_fiber/cpp/src/master_fiber.cpp index 2ebd03ef3..f9c932446 100644 --- a/lib_fiber/cpp/src/master_fiber.cpp +++ b/lib_fiber/cpp/src/master_fiber.cpp @@ -155,4 +155,14 @@ int master_fiber::service_on_sighup(void* ctx, ACL_VSTRING* buf) return ret ? 0 : -1; } +long long master_fiber::users_count() +{ + return acl_fiber_server_users_count(); +} + +long long master_fiber::users_count_add(int n) +{ + return acl_fiber_server_users_count_add(n); +} + } // namespace acl