diff options
author | Robin Burchell <viroteck@viroteck.net> | 2012-05-27 06:09:36 -0700 |
---|---|---|
committer | Robin Burchell <viroteck@viroteck.net> | 2012-05-27 06:09:36 -0700 |
commit | a441c1b1be087a9974dad211aa3706e1909d6ab3 (patch) | |
tree | 356cac842b3ddba090b3a9af94bd2827682961a3 | |
parent | 5d172e0dfc4f316e21b55bf5349c90fd74ba2c3b (diff) | |
parent | 43c9637aec3b98fe24ba94f75636c53871cf4d4d (diff) |
Merge pull request #142 from attilamolnar/insp20+sestatsfix
[2.0] Count the actual number of sent/received bytes in SocketEngine statistics
-rw-r--r-- | src/socketengine.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/socketengine.cpp b/src/socketengine.cpp index daba54580..72075dd49 100644 --- a/src/socketengine.cpp +++ b/src/socketengine.cpp @@ -176,26 +176,34 @@ void SocketEngine::SetReuse(int fd) int SocketEngine::RecvFrom(EventHandler* fd, void *buf, size_t len, int flags, sockaddr *from, socklen_t *fromlen) { - this->UpdateStats(len, 0); - return recvfrom(fd->GetFd(), (char*)buf, len, flags, from, fromlen); + int nbRecvd = recvfrom(fd->GetFd(), (char*)buf, len, flags, from, fromlen); + if (nbRecvd > 0) + this->UpdateStats(nbRecvd, 0); + return nbRecvd; } int SocketEngine::Send(EventHandler* fd, const void *buf, size_t len, int flags) { - this->UpdateStats(0, len); - return send(fd->GetFd(), (char*)buf, len, flags); + int nbSent = send(fd->GetFd(), (const char*)buf, len, flags); + if (nbSent > 0) + this->UpdateStats(0, nbSent); + return nbSent; } int SocketEngine::Recv(EventHandler* fd, void *buf, size_t len, int flags) { - this->UpdateStats(len, 0); - return recv(fd->GetFd(), (char*)buf, len, flags); + int nbRecvd = recv(fd->GetFd(), (char*)buf, len, flags); + if (nbRecvd > 0) + this->UpdateStats(nbRecvd, 0); + return nbRecvd; } int SocketEngine::SendTo(EventHandler* fd, const void *buf, size_t len, int flags, const sockaddr *to, socklen_t tolen) { - this->UpdateStats(0, len); - return sendto(fd->GetFd(), (char*)buf, len, flags, to, tolen); + int nbSent = sendto(fd->GetFd(), (const char*)buf, len, flags, to, tolen); + if (nbSent > 0) + this->UpdateStats(0, nbSent); + return nbSent; } int SocketEngine::Connect(EventHandler* fd, const sockaddr *serv_addr, socklen_t addrlen) |