From 2a5d24ce1cdd5a4caac4676a99131f3368e758ea Mon Sep 17 00:00:00 2001 From: Bartlomiej Grzelewski Date: Wed, 31 Jul 2013 11:22:11 +0200 Subject: [PATCH] Add support for EINTR in client. [Issue#] N/A [Bug] Poll did not support EINTR code. This error may break communication between security-server and client. [Solution] Add support for EINTR. [Verification] Compile, run tests. Change-Id: I0c052f3895f351adf80908db0b7c1ac826f3c0e0 --- src/server2/client/client-common.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/server2/client/client-common.cpp b/src/server2/client/client-common.cpp index e626f68..c5ea276 100644 --- a/src/server2/client/client-common.cpp +++ b/src/server2/client/client-common.cpp @@ -41,15 +41,23 @@ IMPLEMENT_SAFE_SINGLETON(SecurityServer::Log::LogSystem); namespace { +const int POLL_TIMEOUT = 1000; + void securityClientEnableLogSystem(void) { SecurityServer::Singleton::Instance().SetTag("SECURITY_SERVER_CLIENT"); } int waitForSocket(int sock, int event, int timeout) { + int retval; pollfd desc[1]; desc[0].fd = sock; desc[0].events = event; - int retval = poll(desc, 1, timeout); + + while((-1 == (retval = poll(desc, 1, timeout))) && (errno == EINTR)) { + timeout >>= 1; + errno = 0; + } + if (0 == retval) { LogDebug("Poll timeout"); } else if (-1 == retval) { @@ -107,7 +115,7 @@ public: int retval = TEMP_FAILURE_RETRY(connect(m_sock, (struct sockaddr*)&clientAddr, SUN_LEN(&clientAddr))); if ((retval == -1) && (errno == EINPROGRESS)) { - if (0 >= waitForSocket(m_sock, POLLIN, 1000)) { + if (0 >= waitForSocket(m_sock, POLLIN, POLL_TIMEOUT)) { LogError("Error in waitForSocket."); return SECURITY_SERVER_API_ERROR_SOCKET; } @@ -170,7 +178,7 @@ int sendToServer(char const * const interface, const RawBuffer &send, SocketBuff } while ((send.size() - done) > 0) { - if (0 >= waitForSocket(sock.Get(), POLLOUT, 1000)) { + if (0 >= waitForSocket(sock.Get(), POLLOUT, POLL_TIMEOUT)) { LogError("Error in poll(POLLOUT)"); return SECURITY_SERVER_API_ERROR_SOCKET; } @@ -184,7 +192,7 @@ int sendToServer(char const * const interface, const RawBuffer &send, SocketBuff } do { - if (0 >= waitForSocket(sock.Get(), POLLIN, 1000)) { + if (0 >= waitForSocket(sock.Get(), POLLIN, POLL_TIMEOUT)) { LogError("Error in poll(POLLIN)"); return SECURITY_SERVER_API_ERROR_SOCKET; } -- 2.7.4