-// Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
/// Verify that the socket can be marked ready.
ASSERT_NO_THROW(watch->markReady());
EXPECT_EQ(1, selectCheck(select_fd));
+ EXPECT_TRUE(watch->isReady());
// Interfere by closing the fd.
ASSERT_EQ(0, close(select_fd));
+ // Verify that isReady() does not throw.
+ ASSERT_NO_THROW(watch->isReady());
+
+ // and return false.
+ EXPECT_FALSE(watch->isReady());
+
// Verify that trying to clear it does not throw.
ASSERT_NO_THROW(watch->clearReady());
/// Verify that the socket can be marked ready.
ASSERT_NO_THROW(watch->markReady());
+ EXPECT_TRUE(watch->isReady());
EXPECT_EQ(1, selectCheck(select_fd));
// Interfere by reading the fd. This should empty the read pipe.
// make sure we aren't in a weird state.
ASSERT_NO_THROW(watch->clearReady());
- // Verify the select_fd fails as socket is invalid/closed.
+ // Verify the select_fd does not fail.
+ EXPECT_FALSE(watch->isReady());
EXPECT_EQ(0, selectCheck(select_fd));
// Verify that getSelectFd() returns is still good.
/// Verify that the socket can be marked ready.
ASSERT_NO_THROW(watch->markReady());
+ EXPECT_TRUE(watch->isReady());
EXPECT_EQ(1, selectCheck(select_fd));
// Interfere by reading the fd. This should empty the read pipe.
ASSERT_THROW(watch->clearReady(), WatchSocketError);
// Verify the select_fd does not evaluate to ready.
+ EXPECT_FALSE(watch->isReady());
EXPECT_NE(1, selectCheck(select_fd));
// Verify that getSelectFd() returns INVALID.
EXPECT_EQ(WatchSocket::SOCKET_NOT_VALID, watch->getSelectFd());
// No errors should be reported.
EXPECT_TRUE(error_string.empty());
+ // Not ready too.
+ ASSERT_NO_THROW(watch->isReady());
+ EXPECT_FALSE(watch->isReady());
}
} // end of anonymous namespace
-// Copyright (C) 2014-2015,2017 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2014-2018 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
#include <errno.h>
#include <sstream>
#include <string.h>
-#include <sys/select.h>
+#include <sys/ioctl.h>
#include <unistd.h>
namespace isc {
return (false);
}
- fd_set read_fds;
- FD_ZERO(&read_fds);
-
- // Add select_fd socket to listening set
- FD_SET(sink_, &read_fds);
-
- // Set zero timeout (non-blocking).
- struct timeval select_timeout;
- select_timeout.tv_sec = 0;
- select_timeout.tv_usec = 0;
-
+ // Use ioctl FIONREAD vs polling select as it is faster.
+ int len;
+ int result = ioctl(sink_, FIONREAD, &len);
// Return true only if read ready, treat error same as not ready.
- return (select(sink_ + 1, &read_fds, NULL, NULL, &select_timeout) > 0);
+ return ((result == 0) && (len > 0));
}
void