/*
- * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return 0;
}
+time_t monotonicNow() {
+ struct timespec now;
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) {
+ int err = errno;
+ LogError("Can't access monotonic clock, error: " << CKM::GetErrnoString(err));
+ return 0;
+ }
+ return now.tv_sec;
+}
+
} // namespace anonymous
namespace CKM {
desc.counter = ++m_counter;
if (timeout) {
- desc.timeout = time(NULL) + SOCKET_TIMEOUT;
+ desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
Timeout tm;
tm.time = desc.timeout;
tm.sock = sock;
event.rawBuffer.resize(4096);
auto &desc = m_socketDescriptionVector[sock];
- desc.timeout = time(NULL) + SOCKET_TIMEOUT;
+ desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
ssize_t size = read(sock, &event.rawBuffer[0], 4096);
desc.rawBuffer.erase(desc.rawBuffer.begin(), desc.rawBuffer.begin() + result);
- desc.timeout = time(NULL) + SOCKET_TIMEOUT;
+ desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
if (desc.rawBuffer.empty())
FD_CLR(sock, &m_writeSet);
LogDebug("No usaable timeout found.");
ptrTimeout = NULL; // select will wait without timeout
} else {
- time_t currentTime = time(NULL);
+ time_t currentTime = monotonicNow();
auto &pqTimeout = m_timeoutQueue.top();
// 0 means that select won't block and socket will be closed ;-)