Set client socket timeout from env if exists
[platform/core/appfw/pkgmgr-info.git] / src / common / socket / client_socket.cc
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 {