Module: check_mk
Branch: master
Commit: 5cd369d977b559e3edfb146e073942b322270074
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5cd369d977b559…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Jan 9 16:48:44 2017 +0100
Fetched livestatus from downstream.
Change-Id: I00590047b81b76a6bd444a1c97e2dbb6d70e63a5
---
livestatus/configure.ac | 2 +-
livestatus/src/InputBuffer.cc | 39 +++++++++++++++------------------------
livestatus/src/module.cc | 16 ++++++++++------
3 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/livestatus/configure.ac b/livestatus/configure.ac
index 56c5378..f1bec81 100644
--- a/livestatus/configure.ac
+++ b/livestatus/configure.ac
@@ -97,7 +97,7 @@ AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_TYPE_SIGNAL
AC_FUNC_STAT
-AC_CHECK_FUNCS([gettimeofday memmove select socket strcasecmp strdup strerror strtoul])
+AC_CHECK_FUNCS([memmove select socket strcasecmp strdup strerror strtoul])
AC_ARG_WITH(nagios4,AC_HELP_STRING([--with-nagios4],[enabled compilation for nagios 4]),
[
CPPFLAGS="${CFLAGS} -DNAGIOS4"
diff --git a/livestatus/src/InputBuffer.cc b/livestatus/src/InputBuffer.cc
index 15b9da7..23a2bde 100644
--- a/livestatus/src/InputBuffer.cc
+++ b/livestatus/src/InputBuffer.cc
@@ -36,26 +36,21 @@
#include "Logger.h"
using std::chrono::milliseconds;
+using std::chrono::system_clock;
using std::string;
-extern int g_query_timeout_msec;
-extern int g_idle_timeout_msec;
+extern milliseconds g_query_timeout;
+extern milliseconds g_idle_timeout;
namespace {
const size_t initial_buffer_size = 4096;
// TODO(sp): Make this configurable?
const size_t maximum_buffer_size = 500 * 1024 * 1024;
-bool timeout_reached(const struct timeval *start, int timeout_ms) {
- if (timeout_ms == 0) {
- return false; // timeout disabled
- }
-
- struct timeval now;
- gettimeofday(&now, nullptr);
- int64_t elapsed = (now.tv_sec - start->tv_sec) * 1000000;
- elapsed += now.tv_usec - start->tv_usec;
- return elapsed / 1000 >= timeout_ms;
+bool timeout_reached(const system_clock::time_point &start,
+ const milliseconds &timeout) {
+ return (timeout != milliseconds(0)) &&
+ (system_clock::now() - start >= timeout);
}
} // namespace
@@ -70,11 +65,9 @@ InputBuffer::InputBuffer(int fd, const bool &termination_flag,
Logger *logger)
// read in data enough for one complete request (and maybe more).
InputBuffer::Result InputBuffer::readRequest() {
- // Remember when we started waiting for a request. This
- // is needed for the idle_timeout. A connection may
- // not be idle longer than that value.
- struct timeval start_of_idle; // Waiting for the first line
- gettimeofday(&start_of_idle, nullptr);
+ // Remember when we started waiting for a request. This is needed for the
+ // idle_timeout. A connection may not be idle longer than that value.
+ auto start_of_idle = system_clock::now();
// Remember if we have read some part of the query. During
// a query the timeout is another (short) than between
@@ -107,14 +100,14 @@ InputBuffer::Result InputBuffer::readRequest() {
if (rd == Result::timeout) {
if (query_started) {
Informational(_logger)
- << "Timeout of " <<
g_query_timeout_msec
+ << "Timeout of " <<
g_query_timeout.count()
<< " ms exceeded while reading query";
return Result::timeout;
}
// Check if we exceeded the maximum time between two queries
- if (timeout_reached(&start_of_idle, g_idle_timeout_msec)) {
+ if (timeout_reached(start_of_idle, g_idle_timeout)) {
Informational(_logger)
- << "Idle timeout of " <<
g_idle_timeout_msec
+ << "Idle timeout of " <<
g_idle_timeout.count()
<< " ms exceeded. Going to close
connection.";
return Result::timeout;
}
@@ -209,11 +202,9 @@ InputBuffer::Result InputBuffer::readRequest() {
// read at least *some* data. Return IB_TIMEOUT if that
// lasts more than g_query_timeout_msec msecs.
InputBuffer::Result InputBuffer::readData() {
- struct timeval start;
- gettimeofday(&start, nullptr);
-
+ auto start = system_clock::now();
while (!_termination_flag) {
- if (timeout_reached(&start, g_query_timeout_msec)) {
+ if (timeout_reached(start, g_query_timeout)) {
return Result::timeout;
}
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 050adbe..3830d81 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -63,6 +63,9 @@
#include "waittriggers.h"
using mk::unsafe_tolower;
+using std::chrono::milliseconds;
+using std::chrono::minutes;
+using std::chrono::seconds;
using std::chrono::system_clock;
using std::make_unique;
using std::ostream;
@@ -71,7 +74,6 @@ using std::string;
using std::to_string;
using std::unordered_map;
using std::vector;
-
NEB_API_VERSION(CURRENT_NEB_API_VERSION)
#ifndef NAGIOS4
extern int event_broker_options;
@@ -81,9 +83,11 @@ extern unsigned long event_broker_options;
extern int enable_environment_macros;
extern char *log_file;
-int g_idle_timeout_msec =
- 300 * 1000; /* maximum idle time for connection in keep alive state */
-int g_query_timeout_msec = 10 * 1000; /* maximum time for reading a query */
+// maximum idle time for connection in keep alive state
+milliseconds g_idle_timeout = minutes(5);
+
+// maximum time for reading a query
+milliseconds g_query_timeout = seconds(10);
size_t g_num_clientthreads =
10; /* allow 10 concurrent connections per default */
@@ -860,7 +864,7 @@ void livestatus_parse_arguments(const char *args_orig) {
if (c < 0) {
Warning(fl_logger_nagios) << "query_timeout must be >=
0";
} else {
- g_query_timeout_msec = c;
+ g_query_timeout = milliseconds(c);
if (c == 0) {
Notice(fl_logger_nagios) << "disabled query
timeout!";
} else {
@@ -874,7 +878,7 @@ void livestatus_parse_arguments(const char *args_orig) {
if (c < 0) {
Warning(fl_logger_nagios) << "idle_timeout must be >=
0";
} else {
- g_idle_timeout_msec = c;
+ g_idle_timeout = milliseconds(c);
if (c == 0) {
Notice(fl_logger_nagios) << "disabled idle
timeout!";
} else {