From 05027a457a5ce2788fdb9838d999f9470ed645be Mon Sep 17 00:00:00 2001 From: Stephan Schwaer Date: Mon, 27 Apr 2015 18:39:47 +0200 Subject: [SERVER] Added counters for received and sent bytes. --- src/server/net.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/server/net.c') diff --git a/src/server/net.c b/src/server/net.c index 3046795..9836043 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -44,6 +44,9 @@ #include "../types.h" #include "locks.h" +static uint64_t totalBytesSent = 0; +static pthread_spinlock_t statisticsSentLock; + static inline bool recv_request_header(int sock, dnbd3_request_t *request) { int ret, fails = 0; @@ -112,6 +115,11 @@ static inline bool send_reply(int sock, dnbd3_reply_t *reply, void *payload) return true; } +void net_init() +{ + spin_init( &statisticsSentLock, PTHREAD_PROCESS_PRIVATE ); +} + void *net_client_handler(void *dnbd3_client) { dnbd3_client_t *client = (dnbd3_client_t *)dnbd3_client; @@ -307,6 +315,7 @@ void *net_client_handler(void *dnbd3_client) } done += ret; } + client->bytesSent += request.size; // Increase counter for statistics. } if ( lock ) pthread_mutex_unlock( &client->sendMutex ); break; @@ -359,6 +368,9 @@ set_name: ; } exit_client_cleanup: ; dnbd3_removeClient( client ); + spin_lock( &statisticsSentLock ); + totalBytesSent += client->bytesSent; // Add the amount of bytes send to statistics of the server. + spin_unlock( &statisticsSentLock ); client = dnbd3_freeClient( client ); return NULL ; } -- cgit v1.2.3-55-g7522