Module: check_mk
Branch: master
Commit: fdebf5e9345f7ce54add611b42bd74133d2f5db7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fdebf5e9345f7c…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Thu Jan 21 13:45:46 2016 +0100
Restrict the lifetime of an InputBuffer to a single connection.
---
livestatus/src/InputBuffer.cc | 10 ++--------
livestatus/src/InputBuffer.h | 3 +--
livestatus/src/module.c | 5 ++---
livestatus/src/store_c.cc | 9 ++-------
livestatus/src/store_c.h | 3 +--
5 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index 92c7c77..6bababb 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -67,20 +67,14 @@ pair<list<string>, InputBuffer::Result>
failure(InputBuffer::Result r)
// pointers, offsets, etc. with vector.
// cppcheck-suppress uninitMemberVar
-InputBuffer::InputBuffer(int *termination_flag)
- : _fd(-1), _termination_flag(termination_flag)
+InputBuffer::InputBuffer(int fd, int *termination_flag)
+ : _fd(fd), _termination_flag(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 + buffer_size; // points ot end of buffer
}
-void InputBuffer::setFd(int fd)
-{
- _fd = fd;
- _read_pointer = _write_pointer = _readahead_buffer;
-}
-
// read in data enough for one complete request (and maybe more).
pair<list<string>, InputBuffer::Result> InputBuffer::readRequest()
{
diff --git a/livestatus/src/InputBuffer.h b/livestatus/src/InputBuffer.h
index 4f5bc07..2e7626f 100644
--- a/livestatus/src/InputBuffer.h
+++ b/livestatus/src/InputBuffer.h
@@ -44,8 +44,7 @@ public:
timeout
};
- explicit InputBuffer(int *termination_flag);
- void setFd(int fd);
+ InputBuffer(int fd, int *termination_flag);
std::pair<std::list<std::string>, Result> readRequest();
private:
diff --git a/livestatus/src/module.c b/livestatus/src/module.c
index 518cde8..4de4788 100644
--- a/livestatus/src/module.c
+++ b/livestatus/src/module.c
@@ -210,7 +210,6 @@ void *main_thread(void *data __attribute__ ((__unused__)))
void *client_thread(void *data __attribute__ ((__unused__)))
{
- void *input_buffer = create_inputbuffer(&g_should_terminate);
void *output_buffer = create_outputbuffer();
while (!g_should_terminate) {
@@ -220,7 +219,7 @@ void *client_thread(void *data __attribute__ ((__unused__)))
if (cc >= 0) {
if (g_debug_level >= 2)
logger(LG_INFO, "Accepted client connection on fd %d", cc);
- set_inputbuffer_fd(input_buffer, cc);
+ void *input_buffer = create_inputbuffer(cc, &g_should_terminate);
int keepalive = 1;
unsigned requestnr = 1;
while (keepalive) {
@@ -231,12 +230,12 @@ void *client_thread(void *data __attribute__ ((__unused__)))
g_counters[COUNTER_REQUESTS]++;
requestnr ++;
}
+ delete_inputbuffer(input_buffer);
close(cc);
}
g_num_active_connections--;
}
delete_outputbuffer(output_buffer);
- delete_inputbuffer(input_buffer);
return voidp;
}
diff --git a/livestatus/src/store_c.cc b/livestatus/src/store_c.cc
index c36af2f..d952696 100644
--- a/livestatus/src/store_c.cc
+++ b/livestatus/src/store_c.cc
@@ -103,14 +103,9 @@ void delete_outputbuffer(void *ob)
delete static_cast<OutputBuffer *>(ob);
}
-void *create_inputbuffer(int *termination_flag)
+void *create_inputbuffer(int fd, int *termination_flag)
{
- return new InputBuffer(termination_flag);
-}
-
-void set_inputbuffer_fd(void *ib, int fd)
-{
- static_cast<InputBuffer *>(ib)->setFd(fd);
+ return new InputBuffer(fd, termination_flag);
}
void delete_inputbuffer(void *ib)
diff --git a/livestatus/src/store_c.h b/livestatus/src/store_c.h
index 1e885a2..b165011 100644
--- a/livestatus/src/store_c.h
+++ b/livestatus/src/store_c.h
@@ -43,8 +43,7 @@ extern "C"
void *create_outputbuffer();
void flush_output_buffer(void *ob, int fd, int *termination_flag);
void delete_outputbuffer(void *);
- void *create_inputbuffer(int *termination_flag);
- void set_inputbuffer_fd(void *, int fd);
+ void *create_inputbuffer(int fd, int *termination_flag);
void delete_inputbuffer(void *);
void queue_add_connection(int cc);
int queue_pop_connection();