cynara-tests: replace select w/ poll 81/223081/1
authorKonrad Lipinski <k.lipinski2@samsung.com>
Wed, 22 Jan 2020 15:04:50 +0000 (16:04 +0100)
committerKonrad Lipinski <k.lipinski2@samsung.com>
Wed, 22 Jan 2020 15:04:59 +0000 (16:04 +0100)
Change-Id: If7cf3efec5d0a38a6467a1dbea962c80820c6cd5

src/cynara-tests/common/cynara_test_client_async_client.cpp

index 21c9460..885b3e1 100644 (file)
@@ -21,6 +21,7 @@
 #include <cynara-client-async.h>
 
 #include <exception>
+#include <poll.h>
 #include <unistd.h>
 
 namespace CynaraTestClientAsync {
@@ -129,35 +130,22 @@ void Client::process(int expectedResult,
     if (m_statusMonitor.getStatus() == DISCONNECTED)
         return;
 
-    int fd = m_statusMonitor.getFd();
-    fd_set fds;
-    timeval tv;
-    FD_ZERO(&fds);
-    FD_SET(fd, &fds);
-    tv.tv_sec = timeoutSeconds;
-    tv.tv_usec = 0;
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wrestrict"
-
-    int ret;
-    if (m_statusMonitor.getStatus() == READ)
-        ret = TEMP_FAILURE_RETRY(select(fd + 1, &fds, NULL, NULL, &tv));
-    else
-        ret = TEMP_FAILURE_RETRY(select(fd + 1, &fds, &fds, NULL, &tv));
+    pollfd fds[1];
+    fds->fd = m_statusMonitor.getFd();
+    fds->events = POLLIN | (m_statusMonitor.getStatus() == READ ? 0 : POLLOUT);
+    int ret = TEMP_FAILURE_RETRY(poll(fds, 1, timeoutSeconds * 1000));
 
     if (ret == 0) {
         RUNNER_ASSERT_MSG(timeoutExpectation != EXPECT_NO_TIMEOUT,
-                             "Unexpected select timeout."
+                             "Unexpected poll timeout."
                              << " ret = " << ret);
         return;
     }
-#pragma GCC diagnostic push
     RUNNER_ASSERT_ERRNO_MSG(ret > 0,
-                               "Select returned error:"
+                               "Poll returned error:"
                                << " ret = " << ret);
     RUNNER_ASSERT_MSG(timeoutExpectation != EXPECT_TIMEOUT,
-                         "Select returned positive value, when timeout was expected."
+                         "Poll returned positive value, when timeout was expected."
                          << " ret = " << ret);
 
     RUNNER_DEFER_SCOPE(ret = cynara_async_process(m_cynara););