}
bool SelectEventHandler::readReady(int fd) {
+ if (fd >= FD_SETSIZE) {
+ isc_throw(BadValue, "invalid value for fd exceeds maximum allowed " << FD_SETSIZE);
+ }
return (FD_ISSET(fd, &read_fd_set_data_));
}
+bool SelectEventHandler::hasError(int fd) {
+ if (fd >= FD_SETSIZE) {
+ isc_throw(BadValue, "invalid value for fd exceeds maximum allowed " << FD_SETSIZE);
+ }
+ return (false);
+}
+
void SelectEventHandler::clear() {
FD_ZERO(&read_fd_set_);
max_fd_ = 0;
/// @return True if file descriptor is ready for reading.
bool readReady(int fd);
+ /// @brief Check if file descriptor has error.
+ ///
+ /// @param fd The file descriptor.
+ ///
+ /// @return True if file descriptor has error.
+ virtual bool hasError(int fd);
+
/// @brief Clear registered file descriptors.
void clear();
FDEventHandlerPtr handler = FDEventHandlerFactory::factoryFDEventHandler();
if (handler->type() == FDEventHandler::TYPE_SELECT) {
EXPECT_THROW(handler->add(FD_SETSIZE), BadValue);
+ EXPECT_THROW(handler->readReady(FD_SETSIZE), BadValue);
+ EXPECT_THROW(handler->hasError(FD_SETSIZE), BadValue);
} else {
EXPECT_NO_THROW(handler->add(FD_SETSIZE));
}
#include <gtest/gtest.h>
#include <thread>
+#include <vector>
#include <fcntl.h>
#include <signal.h>
using namespace isc;
using namespace isc::util;
+using namespace std;
const unsigned char MARKER = 0;
pipe(pipe_fd_);
}
+TEST_F(FDEventHandlerTest, noLimit) {
+ if (handler_->type() != FDEventHandler::TYPE_SELECT) {
+ vector<int> fds;
+ const size_t limit = 2 * FD_SETSIZE;
+ int result;
+ for (size_t i = 0; i < limit; ++i) {
+ int pipe_fd[2];
+ result = pipe(pipe_fd);
+ if (result < 0) {
+ for (size_t j = 0; j < fds.size(); ++j) {
+ close(fds[j]);
+ }
+ ASSERT_GT(result, 0);
+ }
+ fds.push_back(pipe_fd[0]);
+ EXPECT_EQ(sizeof(i), write(pipe_fd[1], &i, sizeof(i)));
+ fds.push_back(pipe_fd[1]);
+ EXPECT_NO_THROW(handler_->add(pipe_fd[0]));
+ }
+ EXPECT_EQ(limit, handler_->waitEvent(0, 1000));
+ for (size_t i = 0; i < fds.size(); i += 2) {
+ size_t data = 0;
+ EXPECT_EQ(sizeof(i), read(fds[i], &data, sizeof(data)));
+ EXPECT_EQ(data, i / 2);
+ close(fds[i]);
+ close(fds[i + 1]);
+ }
+ }
+}
+
} // end of anonymous namespace