mirror of
https://gitee.com/openharmony/startup_appspawn
synced 2024-11-23 07:00:17 +00:00
!1530 modify client default timeout
Merge pull request !1530 from 杨浩/modifyclienttimeout
This commit is contained in:
commit
1744f10ee2
@ -142,6 +142,16 @@ APPSPAWN_STATIC int CreateClientSocket(uint32_t type, uint32_t timeout)
|
||||
return -1;
|
||||
}
|
||||
|
||||
APPSPAWN_STATIC int UpdateSocketTimeout(uint32_t timeout, int socketFd)
|
||||
{
|
||||
struct timeval timeoutVal = {timeout, 0};
|
||||
int ret = setsockopt(socketFd, SOL_SOCKET, SO_SNDTIMEO, &timeoutVal, sizeof(timeoutVal));
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "Set opt SO_SNDTIMEO error: %{public}d", errno);
|
||||
ret = setsockopt(socketFd, SOL_SOCKET, SO_RCVTIMEO, &timeoutVal, sizeof(timeoutVal));
|
||||
APPSPAWN_CHECK(ret == 0, return ret, "Set opt SO_RCVTIMEO error: %{public}d", errno);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ReadMessage(int socketFd, uint32_t sendMsgId, uint8_t *buf, int len, AppSpawnResult *result)
|
||||
{
|
||||
ssize_t rLen = TEMP_FAILURE_RETRY(read(socketFd, buf, len));
|
||||
@ -245,6 +255,7 @@ APPSPAWN_STATIC void TryCreateSocket(AppSpawnReqMsgMgr *reqMgr)
|
||||
static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode, AppSpawnResult *result)
|
||||
{
|
||||
uint32_t retryCount = 1;
|
||||
int isColdRun = reqNode->isAsan;
|
||||
while (retryCount <= reqMgr->maxRetryCount) {
|
||||
if (reqMgr->socketId < 0) { // try create socket
|
||||
TryCreateSocket(reqMgr);
|
||||
@ -254,6 +265,9 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode,
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) {
|
||||
UpdateSocketTimeout(ASAN_TIMEOUT, reqMgr->socketId);
|
||||
}
|
||||
|
||||
if (reqNode->msg->msgId == 0) {
|
||||
reqNode->msg->msgId = reqMgr->msgNextId++;
|
||||
@ -264,6 +278,9 @@ static int ClientSendMsg(AppSpawnReqMsgMgr *reqMgr, AppSpawnReqMsgNode *reqNode,
|
||||
reqMgr->recvBlock.buffer, reqMgr->recvBlock.blockSize, result);
|
||||
}
|
||||
if (ret == 0) {
|
||||
if (isColdRun && reqMgr->timeout < ASAN_TIMEOUT) {
|
||||
UpdateSocketTimeout(reqMgr->timeout, reqMgr->socketId);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// retry
|
||||
|
@ -28,8 +28,10 @@ extern "C" {
|
||||
|
||||
#ifdef ASAN_DETECTOR
|
||||
#define TIMEOUT_DEF 60
|
||||
#define ASAN_TIMEOUT 60
|
||||
#else
|
||||
#define TIMEOUT_DEF 2
|
||||
#define ASAN_TIMEOUT 5
|
||||
#endif
|
||||
|
||||
#define RETRY_TIME (200 * 1000) // 200 * 1000 wait 200ms CONNECT_RETRY_DELAY = 200 * 1000
|
||||
@ -73,6 +75,7 @@ typedef struct TagAppSpawnReqMsgNode {
|
||||
uint32_t retryCount;
|
||||
int fdCount;
|
||||
int fds[APP_MAX_FD_COUNT];
|
||||
int isAsan;
|
||||
AppSpawnMsgFlags *msgFlags;
|
||||
AppSpawnMsgFlags *permissionFlags;
|
||||
AppSpawnMsg *msg;
|
||||
|
@ -300,6 +300,7 @@ static AppSpawnReqMsgNode *CreateAppSpawnReqMsg(uint32_t msgType, const char *pr
|
||||
reqNode->msgFlags = NULL;
|
||||
reqNode->permissionFlags = NULL;
|
||||
reqNode->fdCount = 0;
|
||||
reqNode->isAsan = 0;
|
||||
int ret = CreateBaseMsg(reqNode, msgType, processName);
|
||||
APPSPAWN_CHECK(ret == 0, DeleteAppSpawnReqMsg(reqNode);
|
||||
return NULL, "Failed to create base msg for %{public}s", processName);
|
||||
@ -393,6 +394,15 @@ int AppSpawnReqMsgSetBundleInfo(AppSpawnReqMsgHandle reqHandle, uint32_t bundleI
|
||||
return AddAppData(reqNode, TLV_BUNDLE_INFO, data, MAX_DATA_IN_TLV, "TLV_BUNDLE_INFO");
|
||||
}
|
||||
|
||||
static int CheckEnabled(const char *param, const char *value)
|
||||
{
|
||||
char tmp[32] = {0}; // 32 max
|
||||
int ret = GetParameter(param, "", tmp, sizeof(tmp));
|
||||
APPSPAWN_LOGV("CheckEnabled key %{public}s ret %{public}d result: %{public}s", param, ret, tmp);
|
||||
int enabled = (ret > 0 && strcmp(tmp, value) == 0);
|
||||
return enabled;
|
||||
}
|
||||
|
||||
int AppSpawnReqMsgSetAppFlag(AppSpawnReqMsgHandle reqHandle, AppFlagsIndex flagIndex)
|
||||
{
|
||||
AppSpawnReqMsgNode *reqNode = (AppSpawnReqMsgNode *)reqHandle;
|
||||
@ -400,6 +410,13 @@ int AppSpawnReqMsgSetAppFlag(AppSpawnReqMsgHandle reqHandle, AppFlagsIndex flagI
|
||||
APPSPAWN_CHECK(reqNode->msgFlags != NULL, return APPSPAWN_ARG_INVALID, "No msg flags tlv ");
|
||||
APPSPAWN_CHECK(flagIndex < MAX_FLAGS_INDEX, return APPSPAWN_ARG_INVALID,
|
||||
"Invalid msg app flags %{public}d", flagIndex);
|
||||
if (!reqNode->isAsan &&
|
||||
(flagIndex == APP_FLAGS_UBSAN_ENABLED || flagIndex == APP_FLAGS_ASANENABLED ||
|
||||
flagIndex == APP_FLAGS_TSAN_ENABLED || flagIndex == APP_FLAGS_HWASAN_ENABLED ||
|
||||
(flagIndex == APP_FLAGS_COLD_BOOT && CheckEnabled("startup.appspawn.cold.boot", "true")))) {
|
||||
reqNode->isAsan = 1;
|
||||
}
|
||||
|
||||
return SetAppSpawnMsgFlags(reqNode->msgFlags, flagIndex);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user