diff options
author | Simon Rettberg | 2018-08-08 12:09:14 +0200 |
---|---|---|
committer | Simon Rettberg | 2018-08-08 12:09:14 +0200 |
commit | 2860f3393025e114f11feb1b576d2ac6353fbd23 (patch) | |
tree | 51a66fbf9dccff3ee0d7cc905cab7c7ab40911b5 /src/server/rpc.c | |
parent | [SHARED] Use atomic for logger mask (diff) | |
download | dnbd3-2860f3393025e114f11feb1b576d2ac6353fbd23.tar.gz dnbd3-2860f3393025e114f11feb1b576d2ac6353fbd23.tar.xz dnbd3-2860f3393025e114f11feb1b576d2ac6353fbd23.zip |
[SERVER] Use atomic var for (total)bytesSent counters
Gets rid of the lastBytesSent field as well as the stats lock per
client. Cleaned and split up the messy net_clientsToJson function while
at it.
Diffstat (limited to 'src/server/rpc.c')
-rw-r--r-- | src/server/rpc.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/src/server/rpc.c b/src/server/rpc.c index 3d3d665..2e1fca0 100644 --- a/src/server/rpc.c +++ b/src/server/rpc.c @@ -289,18 +289,17 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t if ( altservers && !(permissions & ACL_ALTSERVERS) ) { return sendReply( sock, "403 Forbidden", "text/plain", "No permission to access altservers", -1, keepAlive ); } - // Call this first because it will update the total bytes sent counter - json_t *jsonClients = NULL; - if ( stats || clients ) { - jsonClients = net_clientsToJson( clients ); - } + json_t *statisticsJson; if ( stats ) { + int clientCount; + uint64_t bytesSent; const uint64_t bytesReceived = uplink_getTotalBytesReceived(); - const uint64_t bytesSent = net_getTotalBytesSent(); - statisticsJson = json_pack( "{sIsIsIsI}", + net_getStats( &clientCount, &bytesSent ); + statisticsJson = json_pack( "{sIsIsisIsI}", "bytesReceived", (json_int_t) bytesReceived, "bytesSent", (json_int_t) bytesSent, + "clientCount", clientCount, "uptime", (json_int_t) dnbd3_serverUptime(), "runId", randomRunId ); } else { @@ -313,12 +312,8 @@ static bool handleStatus(int sock, int permissions, struct field *fields, size_t json_object_set_new( statisticsJson, "spaceTotal", json_integer( spaceTotal ) ); json_object_set_new( statisticsJson, "spaceFree", json_integer( spaceAvail ) ); } - if ( jsonClients != NULL ) { - if ( clients ) { - json_object_set_new( statisticsJson, "clients", jsonClients ); - } else if ( stats ) { - json_object_set_new( statisticsJson, "clientCount", jsonClients ); - } + if ( clients ) { + json_object_set_new( statisticsJson, "clients", net_getListAsJson() ); } if ( images ) { json_object_set_new( statisticsJson, "images", image_getListAsJson() ); |