Set client socket timeout from env if exists 36/298336/1
authorSangyoon Jang <jeremy.jang@samsung.com>
Thu, 24 Aug 2023 06:14:22 +0000 (15:14 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 6 Sep 2023 04:30:07 +0000 (04:30 +0000)
Change-Id: Iceb6ba89e6c7a40f93e555faad1e0e72894f8725
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/common/socket/client_socket.cc
src/common/socket/client_socket.hh

index f386e00..2cf574f 100644 (file)
@@ -64,11 +64,26 @@ void ClientSocket::SetTimeout(int timeout_msec) {
         << ", errno: " << errno;
 }
 
+int ClientSocket::GetTimeoutFromEnv() {
+  const char* timeout_str = getenv("PKGMGR_SOCKET_TIMEOUT");
+  if (timeout_str == nullptr)
+    return -1;
+
+  int timeout_msec = atoi(timeout_str);
+  if (timeout_msec <= 0)
+    return -1;
+
+  return timeout_msec;
+}
+
 bool ClientSocket::Connect(ReqType req_type) {
   if (Create() < 0)
     return false;
 
-  SetTimeout(IsDBWriteRequest(req_type) ? 60 * 1000 : 5 * 1000);
+  int timeout = GetTimeoutFromEnv();
+  if (timeout <= 0)
+    timeout = IsDBWriteRequest(req_type) ? 60 * 1000 : 5 * 1000;
+  SetTimeout(timeout);
 
   int retry_cnt = 3;
   do {
index a08113b..3503a59 100644 (file)
@@ -31,6 +31,7 @@ class EXPORT_API ClientSocket: public AbstractSocket {
  private:
   int TryConnection();
   void SetTimeout(int timeout_msec);
+  int GetTimeoutFromEnv();
 };
 
 }  // namespace socket