Module: check_mk
Branch: master
Commit: 2cb4f1039bb1dc78df078b09b86f99b9692eb67d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2cb4f1039bb1dc…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jan 21 08:30:35 2016 +0100
Using the C preprocessor is soooo old-skool, let's use C++...
---
livestatus/src/InputBuffer.cc | 12 ++++++++----
livestatus/src/InputBuffer.h | 7 ++++---
2 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index bb88846..724403d 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -33,8 +33,12 @@
using std::string;
+const size_t InputBuffer::buffer_size;
+
+namespace {
+const int read_timeout_usec = 200000;
+}
-#define READ_TIMEOUT_USEC 200000
extern int g_query_timeout_msec;
extern int g_idle_timeout_msec;
@@ -50,7 +54,7 @@ InputBuffer::InputBuffer(int *termination_flag)
{
_read_pointer = &_readahead_buffer[0]; // points to data not yet
processed
_write_pointer = _read_pointer; // points to end of data in buffer
- _end_pointer = _read_pointer + IB_BUFFER_SIZE; // points ot end of buffer
+ _end_pointer = _read_pointer + buffer_size; // points ot end of buffer
}
void InputBuffer::setFd(int fd)
@@ -195,8 +199,8 @@ InputBuffer::Result InputBuffer::readData()
if (timeout_reached(&start, g_query_timeout_msec))
return Result::timeout;
- tv.tv_sec = READ_TIMEOUT_USEC / 1000000;
- tv.tv_usec = READ_TIMEOUT_USEC % 1000000;
+ tv.tv_sec = read_timeout_usec / 1000000;
+ tv.tv_usec = read_timeout_usec % 1000000;
fd_set fds;
FD_ZERO(&fds);
diff --git a/livestatus/src/InputBuffer.h b/livestatus/src/InputBuffer.h
index 7b0e00a..9cbee78 100644
--- a/livestatus/src/InputBuffer.h
+++ b/livestatus/src/InputBuffer.h
@@ -26,11 +26,10 @@
#define InputBuffer_h
#include "config.h" // IWYU pragma: keep
+#include <stddef.h>
#include <deque>
#include <string>
-#define IB_BUFFER_SIZE 65536
-
class InputBuffer {
public:
enum class Result {
@@ -51,11 +50,13 @@ public:
std::string nextLine();
private:
+ static const size_t buffer_size = 65536;
+
int _fd;
int *_termination_flag;
typedef std::deque<std::string> _requestlines_t;
_requestlines_t _requestlines;
- char _readahead_buffer[IB_BUFFER_SIZE];
+ char _readahead_buffer[buffer_size];
char *_read_pointer;
char *_write_pointer;
char *_end_pointer;