Module: check_mk
Branch: master
Commit: 39efbbef6c09645e0309052fa8c8ae13ad2f23dc
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=39efbbef6c0964…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Jul 11 14:54:23 2017 +0200
Encapsulate select() calls, part 8
Move FD_SET calls into Poller class.
Change-Id: I60290e7f59bd58ed3895e6ab4cfca5d5f2f8eb95
---
livestatus/src/InputBuffer.cc | 2 +-
livestatus/src/OutputBuffer.cc | 2 +-
livestatus/src/Poller.h | 3 +++
livestatus/src/module.cc | 2 +-
livestatus/src/unixcat.cc | 3 +--
5 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index ef34ff9..15025bb 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -206,7 +206,7 @@ InputBuffer::Result InputBuffer::readData() {
}
Poller poller;
- FD_SET(_fd, poller.readFDs());
+ poller.addReadFD(_fd);
int retval = poller.poll(_fd + 1, milliseconds(200));
if (retval > 0 && FD_ISSET(_fd, poller.readFDs())) {
ssize_t r = read(_fd, &_readahead_buffer[_write_index],
diff --git a/livestatus/src/OutputBuffer.cc b/livestatus/src/OutputBuffer.cc
index 2d8a2f7..354aa3b 100644
--- a/livestatus/src/OutputBuffer.cc
+++ b/livestatus/src/OutputBuffer.cc
@@ -79,7 +79,7 @@ void OutputBuffer::writeData(ostringstream &os) {
size_t bytes_to_write = os.tellp();
while (!_termination_flag && bytes_to_write > 0) {
Poller poller;
- FD_SET(_fd, poller.writeFDs());
+ poller.addWriteFD(_fd);
int retval = poller.poll(_fd + 1, milliseconds(100));
if (retval > 0 && FD_ISSET(_fd, poller.writeFDs())) {
ssize_t bytes_written = write(_fd, buffer, bytes_to_write);
diff --git a/livestatus/src/Poller.h b/livestatus/src/Poller.h
index 72721fc..819ef43 100644
--- a/livestatus/src/Poller.h
+++ b/livestatus/src/Poller.h
@@ -51,6 +51,9 @@ public:
return retval;
}
+ 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; }
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index d72a6e9..fda1ba9 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -202,7 +202,7 @@ void *main_thread(void *data) {
do_statistics();
Poller poller;
- FD_SET(g_unix_socket, poller.readFDs());
+ 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())) {
int cc = accept(g_unix_socket, nullptr, nullptr);
diff --git a/livestatus/src/unixcat.cc b/livestatus/src/unixcat.cc
index 43483d9..8c48d15 100644
--- a/livestatus/src/unixcat.cc
+++ b/livestatus/src/unixcat.cc
@@ -23,7 +23,6 @@
// Boston, MA 02110-1301 USA.
#include <pthread.h>
-#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
@@ -61,7 +60,7 @@ void printErrno(const string &msg) {
ssize_t read_with_timeout(int from, char *buffer, int size,
microseconds timeout) {
Poller poller;
- FD_SET(from, poller.readFDs());
+ poller.addReadFD(from);
int retval = poller.poll(from + 1, timeout);
if (retval > 0) {
return read(from, buffer, size);