From 43c9637aec3b98fe24ba94f75636c53871cf4d4d Mon Sep 17 00:00:00 2001 From: attilamolnar Date: Wed, 23 May 2012 18:48:43 +0200 Subject: Count the actual number of sent/received bytes in SocketEngine instead of the buffer size passed to the send/receive functions --- src/socketengine.cpp | 24 ++++++++++++++++-------- 1 file 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) -- cgit v1.2.3