summaryrefslogtreecommitdiffstats
path: root/remote-processor/Socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'remote-processor/Socket.cpp')
-rw-r--r--remote-processor/Socket.cpp44
1 files changed, 34 insertions, 10 deletions
diff --git a/remote-processor/Socket.cpp b/remote-processor/Socket.cpp
index d79b45a..b36d32f 100644
--- a/remote-processor/Socket.cpp
+++ b/remote-processor/Socket.cpp
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright (c) 2011-2014, Intel Corporation
* All rights reserved.
*
@@ -34,6 +34,7 @@
#include <assert.h>
#include <netdb.h>
#include <strings.h>
+#include <errno.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
@@ -109,12 +110,24 @@ bool CSocket::read(void* pvData, uint32_t uiSize)
int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
- if (!iAccessedSize || iAccessedSize == -1) {
-
+ switch (iAccessedSize) {
+ case 0:
+ // recv return value is 0 when the peer has performed an orderly shutdown.
+ _disconnected = true;
+ errno = ECONNRESET; // Warn the client that the client disconnected.
return false;
+
+ case -1:
+ // errno == EINTR => The recv system call was interrupted, try again
+ if (errno != EINTR) {
+ return false;
+ }
+ break;
+
+ default:
+ uiSize -= iAccessedSize;
+ uiOffset += iAccessedSize;
}
- uiSize -= iAccessedSize;
- uiOffset += iAccessedSize;
}
return true;
}
@@ -129,12 +142,19 @@ bool CSocket::write(const void* pvData, uint32_t uiSize)
int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
- if (!iAccessedSize || iAccessedSize == -1) {
-
- return false;
+ if (iAccessedSize == -1) {
+ if (errno == ECONNRESET) {
+ // Peer has disconnected
+ _disconnected = true;
+ }
+ // errno == EINTR => The send system call was interrupted, try again
+ if (errno != EINTR) {
+ return false;
+ }
+ } else {
+ uiSize -= iAccessedSize;
+ uiOffset += iAccessedSize;
}
- uiSize -= iAccessedSize;
- uiOffset += iAccessedSize;
}
return true;
}
@@ -144,3 +164,7 @@ int CSocket::getFd() const
{
return _iSockFd;
}
+
+bool CSocket::hasPeerDisconnected() {
+ return _disconnected;
+}