From 4e42c1c4cce201c56cf291d7adb9010726cce160 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Wed, 26 Jul 2023 04:49:21 +0000 Subject: [PATCH] add timeout to auth --- src/os/src/detail/osSemaphore.c | 16 ++++++++-------- src/rpc/src/rpcMain.c | 14 +++++++++++--- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/os/src/detail/osSemaphore.c b/src/os/src/detail/osSemaphore.c index 712d479d70..f937ee862f 100644 --- a/src/os/src/detail/osSemaphore.c +++ b/src/os/src/detail/osSemaphore.c @@ -118,13 +118,13 @@ int32_t tsem_timewait(tsem_t* sem, int64_t ms) { #endif -#if defined(_TD_DARWIN_64) +// #if defined(_TD_DARWIN_64) -int tsem_timewait(tsem_t* psem, int64_t milis) { - if (psem == NULL || *psem == NULL) return -1; - dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); - dispatch_semaphore_wait(*psem, time); - return 0; -} +// int tsem_timewait(tsem_t* psem, int64_t milis) { +// if (psem == NULL || *psem == NULL) return -1; +// dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(milis * USEC_PER_SEC)); +// dispatch_semaphore_wait(*psem, time); +// return 0; +// } -#endif \ No newline at end of file +// #endif \ No newline at end of file diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 55a94e3746..bc9d24b62f 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -576,11 +576,19 @@ void rpcSendRecvWithTimeout(void *shandle, SRpcEpSet *pEpSet, SRpcMsg *pMsg, SRp int64_t rid = 0; rpcSendRequest(shandle, pEpSet, pMsg, &rid); - tsem_timewait(&sem, 3 * 1000); - rpcCancelRequest(rid); +#if defined (LINUX) + if (tsem_timewait(&sem, 3 * 1000) == 0) { + // do nothing + } else { + rpcCancelRequest(rid); + pRsp->code = -1; + } + +#else + tsem_wait(&sem); +#endif tsem_destroy(&sem); - pRsp->code = -1; return; } -- GitLab