From f976f3749c6639915a646a88049fe523e3d5f051 Mon Sep 17 00:00:00 2001 From: Kevin Rocard Date: Thu, 24 Apr 2014 15:14:53 +0200 Subject: Remote-processor continue on EINTR BZ: 190038 EINTR is a normal error and should not fail recv or send. Continue if those errors are received. Change-Id: I66416153eb432b8f7daf97119c7c59c87e88da08 Signed-off-by: Kevin Rocard Signed-off-by: Mattijs Korpershoek --- remote-processor/Socket.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'remote-processor') diff --git a/remote-processor/Socket.cpp b/remote-processor/Socket.cpp index 3530453..07e6b60 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 #include #include +#include #include #include #include @@ -109,15 +110,22 @@ 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. - // -1 if an error occurred - // In both case the read could not be achieve 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; } @@ -132,13 +140,15 @@ bool CSocket::write(const void* pvData, uint32_t uiSize) int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL); - // Return value of 0 is not an error if (iAccessedSize == -1) { - - return false; + // 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; } -- cgit v1.1