From: Sangyoon Jang Date: Thu, 24 Aug 2023 06:14:22 +0000 (+0900) Subject: Set client socket timeout from env if exists X-Git-Tag: accepted/tizen/8.0/unified/20231005.093052~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fappfw%2Fpkgmgr-info.git;a=commitdiff_plain;h=0c6298044f0359d91aa34a3182853f61dfce2ce6 Set client socket timeout from env if exists Change-Id: Iceb6ba89e6c7a40f93e555faad1e0e72894f8725 Signed-off-by: Sangyoon Jang --- diff --git a/src/common/socket/client_socket.cc b/src/common/socket/client_socket.cc index f386e00..2cf574f 100644 --- a/src/common/socket/client_socket.cc +++ b/src/common/socket/client_socket.cc @@ -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 { diff --git a/src/common/socket/client_socket.hh b/src/common/socket/client_socket.hh index a08113b..3503a59 100644 --- a/src/common/socket/client_socket.hh +++ b/src/common/socket/client_socket.hh @@ -31,6 +31,7 @@ class EXPORT_API ClientSocket: public AbstractSocket { private: int TryConnection(); void SetTimeout(int timeout_msec); + int GetTimeoutFromEnv(); }; } // namespace socket