summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChanggyu Choi <changyu.choi@samsung.com>2020-08-04 13:52:33 +0900
committerHwanKyu Jhun <h.jhun@samsung.com>2020-08-06 00:29:19 +0000
commit02286537102cefe75794b195ddce239209566d1d (patch)
treecfb34e2a53b236795f5a8eef215c04888a818a07
parent72be72d258b24896a16e099e27d9d0dc550d611e (diff)
downloadaul-1-02286537102cefe75794b195ddce239209566d1d.tar.gz
aul-1-02286537102cefe75794b195ddce239209566d1d.tar.bz2
aul-1-02286537102cefe75794b195ddce239209566d1d.zip
Change timeout parameter option
Change timeout parameter to millisecond. If "timeout_msec == -1", set default timeout(5s). Else if "timeout_msec == INT_MAX", then not set(infinity). Change-Id: I219e8defab34c90ee9b0aeb0eb4c0afcc9533743 Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
-rw-r--r--aul/socket/client.cc4
-rw-r--r--aul/socket/client.hh2
-rw-r--r--aul/socket/socket.cc18
-rw-r--r--aul/socket/socket.hh2
4 files changed, 16 insertions, 10 deletions
diff --git a/aul/socket/client.cc b/aul/socket/client.cc
index 9d6b01cf..b5cef4c7 100644
--- a/aul/socket/client.cc
+++ b/aul/socket/client.cc
@@ -23,7 +23,7 @@
namespace aul {
-Client::Client(std::string path, int timesec) : Socket(std::move(path)) {
+Client::Client(std::string path, int timeout_msec) : Socket(std::move(path)) {
int retry = 2;
do {
int ret = Connect();
@@ -44,7 +44,7 @@ Client::Client(std::string path, int timesec) : Socket(std::move(path)) {
if (retry == 0)
THROW(-ECOMM);
- SetTimeout(timesec);
+ SetTimeout(timeout_msec);
}
int Client::Send(const Packet& packet) {
diff --git a/aul/socket/client.hh b/aul/socket/client.hh
index 5f9a2c44..c54bb059 100644
--- a/aul/socket/client.hh
+++ b/aul/socket/client.hh
@@ -24,7 +24,7 @@ namespace aul {
class Client : public Socket {
public:
- Client(std::string path, int timesec = 5);
+ Client(std::string path, int timeout_msec = 5000);
int Send(const Packet& packet);
int Recv(Packet& packet);
};
diff --git a/aul/socket/socket.cc b/aul/socket/socket.cc
index f28cb0a9..10313894 100644
--- a/aul/socket/socket.cc
+++ b/aul/socket/socket.cc
@@ -16,8 +16,11 @@
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <unistd.h>
+#include <algorithm>
+
#include "aul/common/log_private.hh"
#include "aul/socket/socket.hh"
@@ -166,18 +169,21 @@ void Socket::SetOption() {
}
}
-void Socket::SetTimeout(int timesec) {
- if (timesec == -1)
+void Socket::SetTimeout(int timeout_msec) {
+ if (timeout_msec == INT_MAX)
return;
- if (timesec < 0) {
- _E("Invalid timesec parameter");
+ if (timeout_msec == -1)
+ timeout_msec = 5000;
+
+ if (timeout_msec < 0) {
+ _E("Invalid timeout_msec parameter");
return;
}
struct timeval timeout = {
- .tv_sec = (time_t)timesec,
- .tv_usec = 0
+ .tv_sec = static_cast<time_t>(timeout_msec / 1000),
+ .tv_usec = static_cast<useconds_t>((timeout_msec % 1000) * 1000)
};
int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
if (ret < 0)
diff --git a/aul/socket/socket.hh b/aul/socket/socket.hh
index e07f3068..6cb084bf 100644
--- a/aul/socket/socket.hh
+++ b/aul/socket/socket.hh
@@ -41,7 +41,7 @@ class Socket {
int Connect();
int GetFd();
- void SetTimeout(int timesec);
+ void SetTimeout(int timeout_msec);
std::string GetPath();
private: