summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Swierczek <t.swierczek@samsung.com>2019-03-19 06:13:12 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2019-03-19 06:13:12 +0000
commit4528906c350ce17b0b8d9db23b889a71beea9628 (patch)
treeef29d595c953302df92b8f0cb03e76dace049f0e
parenta196a5c91cf05fbdc7b324d06ecdd0b8caad9322 (diff)
parent555564ea6ddbcffaae67ec1c9633d974321ca049 (diff)
downloadauth-fw-4528906c350ce17b0b8d9db23b889a71beea9628.tar.gz
auth-fw-4528906c350ce17b0b8d9db23b889a71beea9628.tar.bz2
auth-fw-4528906c350ce17b0b8d9db23b889a71beea9628.zip
Merge "Replace time(NULL) with monotonic clock usage" into tizensubmit/tizen/20190430.085417accepted/tizen/unified/20190502.051445
-rw-r--r--src/server/main/include/socket-manager.h3
-rw-r--r--src/server/main/socket-manager.cpp22
2 files changed, 18 insertions, 7 deletions
diff --git a/src/server/main/include/socket-manager.h b/src/server/main/include/socket-manager.h
index ea60fc6..a2d7641 100644
--- a/src/server/main/include/socket-manager.h
+++ b/src/server/main/include/socket-manager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Jooseong Lee <jooseong.lee@samsung.com>
*
@@ -71,6 +71,7 @@ protected:
void ProcessQueue(void);
void NotifyMe(void);
void CloseSocket(int sock);
+ time_t monotonicNow();
struct SocketDescription {
bool isListen;
diff --git a/src/server/main/socket-manager.cpp b/src/server/main/socket-manager.cpp
index 74f2f16..cdd26d4 100644
--- a/src/server/main/socket-manager.cpp
+++ b/src/server/main/socket-manager.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Jooseong Lee <jooseong.lee@samsung.com>
*
@@ -134,7 +134,7 @@ SocketManager::CreateDefaultReadSocketDescription(int sock, bool timeout,
desc.counter = ++m_counter;
if (timeout) {
- desc.timeout = time(NULL) + SOCKET_TIMEOUT;
+ desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
if (false == desc.isTimeout) {
Timeout tm;
@@ -248,7 +248,7 @@ void SocketManager::ReadyForRead(int sock)
event.connectionID.counter = m_socketDescriptionVector[sock].counter;
event.interfaceID = desc.interfaceID;
event.rawBuffer.resize(4096);
- desc.timeout = time(NULL) + SOCKET_TIMEOUT;
+ desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
ssize_t size = read(sock, &event.rawBuffer[0], 4096);
if (size == 0) {
@@ -306,7 +306,7 @@ void SocketManager::ReadyForSendMsg(int sock)
if (desc.sendMsgDataQueue.empty())
FD_CLR(sock, &m_writeSet);
- desc.timeout = time(NULL) + SOCKET_TIMEOUT;
+ desc.timeout = monotonicNow() + SOCKET_TIMEOUT;
GenericSocketService::WriteEvent event;
event.connectionID.sock = sock;
event.connectionID.counter = desc.counter;
@@ -341,7 +341,7 @@ void SocketManager::ReadyForWriteBuffer(int sock)
}
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);
@@ -400,7 +400,7 @@ void SocketManager::MainLoop()
ptrTimeout->tv_sec = SOCKET_TIMEOUT;
ptrTimeout->tv_usec = 0;
} 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 ;-)
ptrTimeout->tv_sec =
@@ -789,4 +789,14 @@ void SocketManager::CloseSocket(int sock)
FD_CLR(sock, &m_writeSet);
}
+time_t SocketManager::monotonicNow() {
+ struct timespec now;
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) {
+ int err = errno;
+ LogError("Can't access monothonic clock, error: " << errnoToString(err));
+ return 0;
+ }
+ return now.tv_sec;
+}
+
} // namespace AuthPasswd