* limitations under the License.
*/
+#include "client_socket.hh"
+
#include <errno.h>
#include <fcntl.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
-#include "client_socket.hh"
#include "utils/logging.hh"
#include "pkgmgrinfo_debug.h"
+namespace {
+
+bool IsDBWriteRequest(pkgmgr_common::ReqType req_type) {
+ if (req_type != pkgmgr_common::ReqType::SET_PKG_INFO &&
+ req_type != pkgmgr_common::ReqType::SET_CERT_INFO &&
+ req_type != pkgmgr_common::ReqType::WRITE_QUERY)
+ return false;
+
+ return true;
+}
+
+}
+
namespace pkgmgr_common {
namespace socket {
.tv_sec = static_cast<time_t>(timeout_msec / 1000),
.tv_usec = static_cast<suseconds_t>((timeout_msec % 1000) * 1000)};
- int ret = setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout,
- sizeof(timeout));
- if (ret < 0)
+ if (setsockopt(fd_, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0)
LOG(ERROR) << "setsockopt() is failed. fd: " << fd_
<< ", errno: " << errno;
}
-bool ClientSocket::Connect() {
+bool ClientSocket::Connect(ReqType req_type) {
if (Create() < 0)
return false;
- SetTimeout(5000);
+ SetTimeout(IsDBWriteRequest(req_type) ? 60 * 1000 : 30 * 1000);
- int ret = -1;
int retry_cnt = 3;
do {
- ret = TryConnection();
+ int ret = TryConnection();
if (ret == 0) {
break;
} else if (ret < -1) {
LOG(ERROR) << "Maybe peer not launched or peer dead. path: " << GetPath()
<< ", fd: " << GetFd();
- if (getuid() == 0) {
- // If requester is root, don't wait
+
+ // If requester is root, don't wait
+ if (getuid() == 0)
return false;
- }
+
usleep(100 * 1000);
--retry_cnt;
} else if (ret < 0) {