Module: check_mk
Branch: master
Commit: 63dd02ad72b87396d2402b9f3b4a12df62cd52f3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=63dd02ad72b873…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jan 21 15:35:19 2016 +0100
Refactoring: Use vector instead old-skool C array.
---
livestatus/src/InputBuffer.cc | 16 ++++++----------
livestatus/src/InputBuffer.h | 4 ++--
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index 0290641..f4fd7ab 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -62,17 +62,13 @@ pair<list<string>, InputBuffer::Result>
failure(InputBuffer::Result r)
}
}
-// TODO: We need the suppression pragma below because _readahead_buffer is not
-// initialized in the constructor. Just replace all this manual fiddling with
-// pointers, offsets, etc. with vector.
-
-// cppcheck-suppress uninitMemberVar
InputBuffer::InputBuffer(int fd, const int *termination_flag)
- : _fd(fd), _termination_flag(termination_flag)
+ : _fd(fd)
+ , _termination_flag(termination_flag)
+ , _readahead_buffer(buffer_size)
{
_read_index = 0; // points to data not yet processed
_write_index = 0; // points to end of data in buffer
- _end_index = buffer_size; // points ot end of buffer
}
// read in data enough for one complete request (and maybe more).
@@ -111,7 +107,7 @@ pair<list<string>, InputBuffer::Result>
InputBuffer::readRequest()
{
// Is there still space left in the buffer => read in
// further data into the buffer.
- if (_write_index < _end_index)
+ if (_write_index < _readahead_buffer.capacity())
{
Result rd = readData(); // tries to read in further data into buffer
if (rd == Result::timeout) {
@@ -155,7 +151,7 @@ pair<list<string>, InputBuffer::Result>
InputBuffer::readRequest()
}
// OK. So no space is left in the buffer. But maybe at the
// *beginning* of the buffer is space left again. This is
- // very probable if _write_index == _end_index. Most
+ // very probable if _write_index == _readahead_buffer.capacity(). Most
// of the buffer's content is already processed. So we simply
// shift the yet unprocessed data to the very left of the buffer.
else if (_read_index > 0) {
@@ -224,7 +220,7 @@ InputBuffer::Result InputBuffer::readData()
int retval = select(_fd + 1, &fds, NULL, NULL, &tv);
if (retval > 0 && FD_ISSET(_fd, &fds)) {
- ssize_t r = read(_fd, &_readahead_buffer[_write_index], _end_index -
_write_index);
+ ssize_t r = read(_fd, &_readahead_buffer[_write_index],
_readahead_buffer.capacity() - _write_index);
if (r < 0) {
return Result::eof;
}
diff --git a/livestatus/src/InputBuffer.h b/livestatus/src/InputBuffer.h
index 5c0256f..89b7d15 100644
--- a/livestatus/src/InputBuffer.h
+++ b/livestatus/src/InputBuffer.h
@@ -30,6 +30,7 @@
#include <list>
#include <string>
#include <utility>
+#include <vector>
class InputBuffer {
public:
@@ -52,10 +53,9 @@ private:
int _fd;
const int *_termination_flag;
- char _readahead_buffer[buffer_size];
+ std::vector<char> _readahead_buffer;
size_t _read_index;
size_t _write_index;
- size_t _end_index;
Result readData();
};