Module: check_mk
Branch: master
Commit: 76d67beda553b4b1c163cf0dc121bc22335ccf11
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=76d67beda553b4…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Jul 11 14:17:38 2017 +0200
Encapsulate select() calls, part 7
Mechanically move all FD_ZERO calls into Poller's constructor. This reduces
code size and partially initialized entities are an anti-pattern, anyway,
they lead to temporal coupling, see e.g.
http://blog.ploeh.dk/2011/05/24/DesignSmellTemporalCoupling/
Change-Id: Ie9f04a86746fe7b234288c89a32f8f2b785de0f3
---
livestatus/src/InputBuffer.cc | 2 --
livestatus/src/OutputBuffer.cc | 2 --
livestatus/src/Poller.h | 5 ++++-
livestatus/src/module.cc | 4 +---
livestatus/src/unixcat.cc | 1 -
5 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index 058797a..ef34ff9 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -206,9 +206,7 @@ InputBuffer::Result InputBuffer::readData() {
}
Poller poller;
- FD_ZERO(poller.readFDs());
FD_SET(_fd, poller.readFDs());
-
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 5af8f4e..2d8a2f7 100644
--- a/livestatus/src/OutputBuffer.cc
+++ b/livestatus/src/OutputBuffer.cc
@@ -79,9 +79,7 @@ void OutputBuffer::writeData(ostringstream &os) {
size_t bytes_to_write = os.tellp();
while (!_termination_flag && bytes_to_write > 0) {
Poller poller;
- FD_ZERO(poller.writeFDs());
FD_SET(_fd, poller.writeFDs());
-
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 6c5dd50..72721fc 100644
--- a/livestatus/src/Poller.h
+++ b/livestatus/src/Poller.h
@@ -32,7 +32,10 @@
class Poller {
public:
- Poller() {}
+ Poller() {
+ FD_ZERO(&_readfds);
+ FD_ZERO(&_writefds);
+ }
template <typename Rep, typename Period>
int poll(int nfds, std::chrono::duration<Rep, Period> timeout) {
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 599cc43..d72a6e9 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -202,10 +202,8 @@ void *main_thread(void *data) {
do_statistics();
Poller poller;
- FD_ZERO(poller.readFDs());
FD_SET(g_unix_socket, poller.readFDs());
- int retval =
- poller.poll(g_unix_socket + 1, milliseconds(2500));
+ 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);
if (cc > g_max_fd_ever) {
diff --git a/livestatus/src/unixcat.cc b/livestatus/src/unixcat.cc
index 7fefd98..43483d9 100644
--- a/livestatus/src/unixcat.cc
+++ b/livestatus/src/unixcat.cc
@@ -61,7 +61,6 @@ void printErrno(const string &msg) {
ssize_t read_with_timeout(int from, char *buffer, int size,
microseconds timeout) {
Poller poller;
- FD_ZERO(poller.readFDs());
FD_SET(from, poller.readFDs());
int retval = poller.poll(from + 1, timeout);
if (retval > 0) {