*/
int try_catch(const std::function<int()>& func);
-time_t monotonicNow();
+time_t monotonicCoarseNow();
// Used for measuring function/method/scope execution time
class ScopedTimeStamper {
/*
- * Copyright (c) 2019-2020 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2019-2022 Samsung Electronics Co., Ltd. All rights reserved.
*
* This file is licensed under the terms of MIT License or the Apache License
* Version 2.0 of your choice. See the LICENSE.MIT file for MIT license details.
return SECURITY_MANAGER_ERROR_UNKNOWN;
}
-time_t monotonicNow() {
+time_t monotonicCoarseNow() {
struct timespec now;
- if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) {
+ if (clock_gettime(CLOCK_MONOTONIC_COARSE, &now)) {
int err = errno;
LogError("Can't access monotonic clock, error: " << GetErrnoString(err));
return 0;
auto &desc = m_socketDescriptionVector[sock];
desc.isOpen = true;
- desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
+ desc.timeout = monotonicCoarseNow() + SOCKET_TIMEOUT;
desc.buffer.InitForInput();
if (false == desc.isTimeout) {
void SocketManager::ReadyForRead(int sock) {
auto &desc = m_socketDescriptionVector[sock];
auto &buffer = desc.buffer;
- desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
+ desc.timeout = monotonicCoarseNow() + SOCKET_TIMEOUT;
ssize_t size = read(sock, buffer.Ptr(), buffer.InputSize());
return; // We do not want to propagate error to next layer
}
- desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
+ desc.timeout = monotonicCoarseNow() + SOCKET_TIMEOUT;
if (buffer.OutputDone(result))
CloseSocket(sock);
}
LogDebug("No usable timeout found.");
ptrTimeout = NULL; // select will wait without timeout
} else {
- time_t currentTime = monotonicNow();
+ time_t currentTime = monotonicCoarseNow();
auto &pqTimeout = m_timeoutQueue.top();
// 0 means that select won't block and socket will be closed ;-)
POSITIVE_TEST_CASE(T288_monotonic_clock)
{
time_t t;
- BOOST_REQUIRE_NO_THROW(t = monotonicNow());
+ BOOST_REQUIRE_NO_THROW(t = monotonicCoarseNow());
BOOST_REQUIRE_MESSAGE(t > 0, "Invalid monotonic time value");
}