summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2012-05-23 18:48:43 +0200
committerattilamolnar <attilamolnar@hush.com>2012-05-23 18:48:43 +0200
commit43c9637aec3b98fe24ba94f75636c53871cf4d4d (patch)
treea71902ebcdc5f333cf100eb85c9b1af01d788132 /src
parent13f0d6735fbf6893463d6a55eb7af2a8c029c96c (diff)
Count the actual number of sent/received bytes in SocketEngine instead of the buffer size passed to the send/receive functions
Diffstat (limited to 'src')
-rw-r--r--src/socketengine.cpp24
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)