Skip to content

Commit

Permalink
Add functions for modify and get the current connections count for fi…
Browse files Browse the repository at this point in the history
…ber server template.
  • Loading branch information
zhengshuxin committed Mar 2, 2024
1 parent 5e7b208 commit 1cee9d5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib_fiber/cpp/include/fiber/master_fiber.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions lib_fiber/cpp/src/fiber_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions lib_fiber/cpp/src/fiber_server.hpp
Original file line number Diff line number Diff line change
@@ -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, ...);
10 changes: 10 additions & 0 deletions lib_fiber/cpp/src/master_fiber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 1cee9d5

Please sign in to comment.