summaryrefslogtreecommitdiffstats
path: root/src/server/net.c
diff options
context:
space:
mode:
authorStephan Schwaer2015-04-27 18:39:47 +0200
committerStephan Schwaer2015-04-27 18:39:47 +0200
commit05027a457a5ce2788fdb9838d999f9470ed645be (patch)
tree5d79423da484f70b716feee17ce19c3f3291a2ea /src/server/net.c
parent[FUSE] Fix compiler warnings, adjust file permissions, change fuse file name ... (diff)
downloaddnbd3-05027a457a5ce2788fdb9838d999f9470ed645be.tar.gz
dnbd3-05027a457a5ce2788fdb9838d999f9470ed645be.tar.xz
dnbd3-05027a457a5ce2788fdb9838d999f9470ed645be.zip
[SERVER] Added counters for received and sent bytes.
Diffstat (limited to 'src/server/net.c')
-rw-r--r--src/server/net.c12
1 files changed, 12 insertions, 0 deletions
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 ;
}