diff options
author | Simon Rettberg | 2017-10-06 12:18:19 +0200 |
---|---|---|
committer | Simon Rettberg | 2017-10-06 12:18:19 +0200 |
commit | 0c4a63c894fb20eefe72a78789931fe02b6d8d18 (patch) | |
tree | 683b929f481e51559e80dca58938b6e8dcd75352 /src/server | |
parent | [SERVER] rpc: Fix bitmask calc for odd subnet sizes (not 8, 16, ...) (diff) | |
download | dnbd3-0c4a63c894fb20eefe72a78789931fe02b6d8d18.tar.gz dnbd3-0c4a63c894fb20eefe72a78789931fe02b6d8d18.tar.xz dnbd3-0c4a63c894fb20eefe72a78789931fe02b6d8d18.zip |
[SERVER] Return client count when requesting stats but not client list
Diffstat (limited to 'src/server')
-rw-r--r-- | src/server/net.c | 8 | ||||
-rw-r--r-- | src/server/rpc.c | 10 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/server/net.c b/src/server/net.c index 11b318c..8e287e7 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -545,6 +545,7 @@ json_t* net_clientsToJson(const bool fullList) uint64_t bytesSent; char host[HOSTNAMELEN]; host[HOSTNAMELEN-1] = '\0'; + json_int_t counter = 0; spin_lock( &_clients_lock ); for ( i = 0; i < _num_clients; ++i ) { @@ -564,6 +565,8 @@ json_t* net_clientsToJson(const bool fullList) if ( fullList ) { strncpy( host, client->hostName, HOSTNAMELEN - 1 ); imgId = client->image->id; + } else { + counter++; } spin_lock( &client->statsLock ); spin_unlock( &client->lock ); @@ -581,7 +584,10 @@ json_t* net_clientsToJson(const bool fullList) spin_lock( &_clients_lock ); } spin_unlock( &_clients_lock ); - return jsonClients; + if ( fullList ) { + return jsonClients; + } + return json_integer( counter ); } void net_disconnectAll() diff --git a/src/server/rpc.c b/src/server/rpc.c index 782c6b8..138e94b 100644 --- a/src/server/rpc.c +++ b/src/server/rpc.c @@ -122,7 +122,7 @@ static bool handleStatus(int sock, const char *request, int permissions) // Call this first because it will update the total bytes sent counter json_t *jsonClients = NULL; if ( stats || clients ) { - jsonClients = net_clientsToJson( permissions & ACL_CLIENT_LIST ); + jsonClients = net_clientsToJson( clients ); } const int uptime = dnbd3_serverUptime(); json_t *statisticsJson; @@ -137,8 +137,12 @@ static bool handleStatus(int sock, const char *request, int permissions) statisticsJson = json_pack( "{sI}", "uptime", (json_int_t) uptime ); } - if ( clients ) { - json_object_set_new( statisticsJson, "clients", jsonClients ); + if ( jsonClients != NULL ) { + if ( clients ) { + json_object_set_new( statisticsJson, "clients", jsonClients ); + } else if ( stats ) { + json_object_set_new( statisticsJson, "clientCount", jsonClients ); + } } if ( images ) { json_object_set_new( statisticsJson, "images", image_getListAsJson() ); |