summaryrefslogtreecommitdiffstats
path: root/remote-processor/Socket.cpp
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2015-07-15 15:37:57 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2015-07-15 17:09:51 -0700
commita9be2d378b7ad84e679a48efa81f42fb54f85d9a (patch)
tree587d34728dac3517a213d6d2a9a6ebdecd4e7531 /remote-processor/Socket.cpp
parentc99720d29f2ee618cc74c9336d2cd2a26544c020 (diff)
downloadexternal_parameter-framework-a9be2d378b7ad84e679a48efa81f42fb54f85d9a.zip
external_parameter-framework-a9be2d378b7ad84e679a48efa81f42fb54f85d9a.tar.gz
external_parameter-framework-a9be2d378b7ad84e679a48efa81f42fb54f85d9a.tar.bz2
Drop release v2.6.0+no-stlport
Bug 246391 Change-Id: I662b7b0f90c97cb169978e1b64ad1fe32c440cf5 Signed-off-by: Jean-Michel Trivi <jmtrivi@google.com>
Diffstat (limited to 'remote-processor/Socket.cpp')
-rw-r--r--remote-processor/Socket.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/remote-processor/Socket.cpp b/remote-processor/Socket.cpp
index b36d32f..0aec7a2 100644
--- a/remote-processor/Socket.cpp
+++ b/remote-processor/Socket.cpp
@@ -39,8 +39,9 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/time.h>
+#include <signal.h>
-CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0))
+CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0)), mSendFlag(0)
{
assert(_iSockFd != -1);
@@ -50,6 +51,19 @@ CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0))
// they are ready to be sent, instead of waiting for more data on the
// socket.
setsockopt(_iSockFd, IPPROTO_TCP, TCP_NODELAY, (char *)&iNoDelay, sizeof(iNoDelay));
+
+ // Disable sigpipe reception on send
+# if not defined(SIGPIPE)
+ // Pipe signal does not exist, there no sigpipe to ignore on send
+# elif defined(SO_NOSIGPIPE)
+ const int set = 1;
+ setsockopt(_iSockFd, SOL_SOCKET, SO_NOSIGPIPE, &set, sizeof(set));
+# elif defined(MSG_NOSIGNAL)
+ // Use flag NOSIGNAL on send call
+ mSendFlag = MSG_NOSIGNAL;
+# else
+# error Can not disable SIGPIPE
+# endif
}
CSocket::CSocket(int iSockId) : _iSockFd(iSockId)
@@ -59,7 +73,11 @@ CSocket::CSocket(int iSockId) : _iSockFd(iSockId)
CSocket::~CSocket()
{
- close(_iSockFd);
+ // fd might be invalide if send had an error.
+ // valgrind displays a warning if closing an invalid fd.
+ if (_iSockFd != -1) {
+ close(_iSockFd);
+ }
}
// Socket address init
@@ -108,7 +126,7 @@ bool CSocket::read(void* pvData, uint32_t uiSize)
while (uiSize) {
- int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
+ int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, 0);
switch (iAccessedSize) {
case 0:
@@ -140,17 +158,19 @@ bool CSocket::write(const void* pvData, uint32_t uiSize)
while (uiSize) {
- int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
+ int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, mSendFlag);
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;
+ if (errno == EINTR) {
+ // The send system call was interrupted, try again
+ continue;
}
+
+ // An error occured, forget this socket
+ _disconnected = true;
+ close(_iSockFd);
+ _iSockFd = -1; // Avoid writing again on the same socket
+ return false;
} else {
uiSize -= iAccessedSize;
uiOffset += iAccessedSize;