Skip to content
Permalink
Browse files

Use std::chrono_literals a bit more often.

Change-Id: I1479f3a21e852637d789933a71ce961ced1cb924
  • Loading branch information...
svenpanne committed Oct 9, 2019
1 parent 8c6daa4 commit a10c42711ae2e4b40985257974bbe66967211ba3
@@ -80,6 +80,7 @@ inline std::chrono::system_clock::time_point from_tm(tm tp) {

template <typename Rep, typename Period>
inline timeval to_timeval(std::chrono::duration<Rep, Period> dur) {
using namespace std::chrono_literals;
timeval tv;
// NOTE: The static_casts below are needed to avoid warning on e.g. some
// 32bit platforms, because the underlying types might be larger than the
@@ -89,8 +90,7 @@ inline timeval to_timeval(std::chrono::duration<Rep, Period> dur) {
tv.tv_sec = static_cast<decltype(tv.tv_sec)>(
std::chrono::duration_cast<std::chrono::seconds>(dur).count());
tv.tv_usec = static_cast<decltype(tv.tv_usec)>(
std::chrono::duration_cast<std::chrono::microseconds>(
dur % std::chrono::seconds(1))
std::chrono::duration_cast<std::chrono::microseconds>(dur % 1s)
.count());
return tv;
}
@@ -33,6 +33,8 @@
#include <utility>
#include "Logger.h"

using namespace std::chrono_literals;

EventConsoleConnection::EventConsoleConnection(Logger *logger, std::string path)
: _logger(logger), _path(std::move(path)) {}

@@ -57,7 +59,7 @@ void EventConsoleConnection::run() {
}
Debug(_logger) << "retrying to connect";
stream.clear();
std::this_thread::sleep_for(std::chrono::milliseconds(1));
std::this_thread::sleep_for(1ms);
}

check(stream, "connect");
@@ -35,6 +35,8 @@
#include "nagios.h"
#endif

using namespace std::chrono_literals;

double HostSpecialDoubleColumn::getValue(Row row) const {
#ifdef CMC
if (auto object = columnData<Object>(row)) {
@@ -104,7 +106,7 @@ double HostSpecialDoubleColumn::staleness(const Object *object) {
check_result_age = last_period_change - last_check;
} else {
// e.g. for timeperiod "never"
check_result_age = std::chrono::seconds(0);
check_result_age = 0s;
}
}

@@ -128,6 +130,6 @@ double HostSpecialDoubleColumn::staleness(const Object *object) {
// make sure that we do not fail if it is set to 0 by some error.
return std::chrono::duration_cast<std::chrono::seconds>(check_result_age)
.count() /
(interval == std::chrono::seconds(0) ? 1 : interval.count());
(interval == 0s ? 1 : interval.count());
}
#endif
@@ -31,14 +31,16 @@
#include "Logger.h"
#include "Poller.h"

using namespace std::chrono_literals;

namespace {
constexpr size_t initial_buffer_size = 4096;
// TODO(sp): Make this configurable?
constexpr size_t maximum_buffer_size = 500 * 1024 * 1024;

bool timeout_reached(const std::chrono::system_clock::time_point &start,
const std::chrono::milliseconds &timeout) {
return (timeout != std::chrono::milliseconds(0)) &&
return (timeout != 0ms) &&
(std::chrono::system_clock::now() - start >= timeout);
}
} // namespace
@@ -226,7 +228,7 @@ InputBuffer::Result InputBuffer::readData() {

Poller poller;
poller.addFileDescriptor(_fd, PollEvents::in);
int retval = poller.poll(std::chrono::milliseconds(200));
int retval = poller.poll(200ms);
if (retval > 0 && poller.isFileDescriptorSet(_fd, PollEvents::in)) {
ssize_t r = read(_fd, &_readahead_buffer[_write_index],
_readahead_buffer.capacity() - _write_index);
@@ -30,6 +30,8 @@
#include "Logger.h"
#include "Poller.h"

using namespace std::chrono_literals;

OutputBuffer::OutputBuffer(int fd, const bool &termination_flag, Logger *logger)
: _fd(fd)
, _termination_flag(termination_flag)
@@ -70,7 +72,7 @@ void OutputBuffer::writeData(std::ostringstream &os) {
while (!shouldTerminate() && bytes_to_write > 0) {
Poller poller;
poller.addFileDescriptor(_fd, PollEvents::out);
int retval = poller.poll(std::chrono::milliseconds(100));
int retval = poller.poll(100ms);
if (retval > 0 && poller.isFileDescriptorSet(_fd, PollEvents::out)) {
ssize_t bytes_written = write(_fd, buffer, bytes_to_write);
if (bytes_written == -1) {
@@ -54,6 +54,8 @@
#include "nagios.h" // for contact
#endif

using namespace std::chrono_literals;

namespace {
std::string nextStringArgument(char **line) {
if (auto value = next_field(line)) {
@@ -586,7 +588,7 @@ void Query::parseLocaltimeLine(char *line) {
"timezone difference greater than or equal to 24 hours");
}

if (offset != std::chrono::seconds(0)) {
if (offset != 0s) {
using hour = std::chrono::duration<double, std::ratio<3600>>;
Debug(_logger) << "timezone offset is "
<< std::chrono::duration_cast<hour>(offset).count()
@@ -36,6 +36,8 @@
#include "Query.h"
#include "auth.h"

using namespace std::chrono_literals;

namespace {
// NOTE: Keep this in sync with EC code. Ugly...
std::vector<std::string> grepping_filters = {
@@ -208,8 +210,7 @@ bool TableEventConsole::isAuthorizedForEventViaContactGroups(
if (col->isNone(row)) {
return false;
}
for (const auto &name :
col->getValue(row, unknown_auth_user(), std::chrono::seconds(0))) {
for (const auto &name : col->getValue(row, unknown_auth_user(), 0s)) {
if (core()->is_contact_member_of_contactgroup(
core()->find_contactgroup(name), ctc)) {
return (result = true, true);
@@ -31,6 +31,8 @@

extern timeperiod *timeperiod_list;

using namespace std::chrono_literals;

TimeperiodsCache::TimeperiodsCache(Logger *logger) : _logger(logger) {}

void TimeperiodsCache::logCurrentTimeperiods() {
@@ -57,7 +59,7 @@ void TimeperiodsCache::update(std::chrono::system_clock::time_point now) {
std::lock_guard<std::mutex> lg(_mutex);
// Update cache only once a minute. The timeperiod definitions have a
// 1-minute granularity, so a 1-second resultion is not needed.
if (now < _last_update + std::chrono::minutes(1)) {
if (now < _last_update + 1min) {
return;
}
_last_update = now;
@@ -63,6 +63,8 @@
#include "nagios.h"
#include "strutil.h"

using namespace std::chrono_literals;

NEB_API_VERSION(CURRENT_NEB_API_VERSION)
#ifndef NAGIOS4
extern int event_broker_options;
@@ -72,10 +74,10 @@ extern unsigned long event_broker_options;
extern int enable_environment_macros;

// maximum idle time for connection in keep alive state
static std::chrono::milliseconds fl_idle_timeout = std::chrono::minutes(5);
static std::chrono::milliseconds fl_idle_timeout = 5min;

// maximum time for reading a query
static std::chrono::milliseconds fl_query_timeout = std::chrono::seconds(10);
static std::chrono::milliseconds fl_query_timeout = 10s;

// allow 10 concurrent connections per default
size_t g_livestatus_threads = 10;
@@ -204,13 +206,13 @@ void *main_thread(void *data) {
while (!fl_should_terminate) {
do_statistics();
auto now = std::chrono::system_clock::now();
if (now - last_update_status >= std::chrono::seconds(5)) {
if (now - last_update_status >= 5s) {
update_status();
last_update_status = now;
}
Poller poller;
poller.addFileDescriptor(g_unix_socket, PollEvents::in);
int retval = poller.poll(std::chrono::milliseconds(2500));
int retval = poller.poll(2500ms);
if (retval > 0 &&
poller.isFileDescriptorSet(g_unix_socket, PollEvents::in)) {
#if HAVE_ACCEPT4

0 comments on commit a10c427

Please sign in to comment.
You can’t perform that action at this time.