Module: check_mk
Branch: master
Commit: 07c03928f2be59ab41649706871f667d8f3e06cc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=07c03928f2be59…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Jul 11 15:23:31 2017 +0200
Encapsulate select() calls, part 9
Move FD_ISSET calls into Poller class. This removes the last call sites of
Poller::readFDs() and Poller::writeFDs(), so those temporary anti-patterns
are gone now. Furthermore, we get rid of quite a few <sys/select.h>
includes, which is a good thing.
Change-Id: Id83b4b749df1bbdbf71ed9d9d9fbb4c2b4ae8388
---
livestatus/src/InputBuffer.cc | 3 +--
livestatus/src/OutputBuffer.cc | 3 +--
livestatus/src/Poller.h | 4 ++--
livestatus/src/module.cc | 4 ++--
4 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index 15025bb..889205b 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -23,7 +23,6 @@
// Boston, MA 02110-1301 USA.
#include "InputBuffer.h"
-#include <sys/select.h>
#include <unistd.h>
#include <cctype>
#include <cstring>
@@ -208,7 +207,7 @@ InputBuffer::Result InputBuffer::readData() {
Poller poller;
poller.addReadFD(_fd);
int retval = poller.poll(_fd + 1, milliseconds(200));
- if (retval > 0 && FD_ISSET(_fd, poller.readFDs())) {
+ if (retval > 0 && poller.isReadFDSet(_fd)) {
ssize_t r = read(_fd, &_readahead_buffer[_write_index],
_readahead_buffer.capacity() - _write_index);
if (r < 0) {
diff --git a/livestatus/src/OutputBuffer.cc b/livestatus/src/OutputBuffer.cc
index 354aa3b..83471a2 100644
--- a/livestatus/src/OutputBuffer.cc
+++ b/livestatus/src/OutputBuffer.cc
@@ -23,7 +23,6 @@
// Boston, MA 02110-1301 USA.
#include "OutputBuffer.h"
-#include <sys/select.h>
#include <unistd.h>
#include <chrono>
#include <cstddef>
@@ -81,7 +80,7 @@ void OutputBuffer::writeData(ostringstream &os) {
Poller poller;
poller.addWriteFD(_fd);
int retval = poller.poll(_fd + 1, milliseconds(100));
- if (retval > 0 && FD_ISSET(_fd, poller.writeFDs())) {
+ if (retval > 0 && poller.isWriteFDSet(_fd)) {
ssize_t bytes_written = write(_fd, buffer, bytes_to_write);
if (bytes_written == -1) {
generic_error ge("could not write " +
diff --git a/livestatus/src/Poller.h b/livestatus/src/Poller.h
index 819ef43..f80a867 100644
--- a/livestatus/src/Poller.h
+++ b/livestatus/src/Poller.h
@@ -54,8 +54,8 @@ public:
void addReadFD(int fd) { FD_SET(fd, &_readfds); }
void addWriteFD(int fd) { FD_SET(fd, &_writefds); }
- fd_set *readFDs() { return &_readfds; }
- fd_set *writeFDs() { return &_writefds; }
+ bool isReadFDSet(int fd) const { return FD_ISSET(fd, &_readfds); }
+ bool isWriteFDSet(int fd) const { return FD_ISSET(fd, &_writefds); }
private:
fd_set _readfds;
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index fda1ba9..22d75af 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -30,7 +30,7 @@
#include "config.h"
#include <fcntl.h>
#include <pthread.h>
-#include <sys/select.h>
+#include <sys/time.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
@@ -204,7 +204,7 @@ void *main_thread(void *data) {
Poller poller;
poller.addReadFD(g_unix_socket);
int retval = poller.poll(g_unix_socket + 1, milliseconds(2500));
- if (retval > 0 && FD_ISSET(g_unix_socket, poller.readFDs())) {
+ if (retval > 0 && poller.isReadFDSet(g_unix_socket)) {
int cc = accept(g_unix_socket, nullptr, nullptr);
if (cc > g_max_fd_ever) {
g_max_fd_ever = cc;