From: Bartlomiej Grzelewski Date: Wed, 31 Jul 2013 09:22:11 +0000 (+0200) Subject: Add support for EINTR in client. X-Git-Tag: submit/tizen/20140307.131547~92 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90828f9198a117d08d7befcba32123d2410901e6;p=platform%2Fcore%2Fsecurity%2Fsecurity-server.git 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 --- 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; }