diff --git a/CASA-auth-token/client/library/linux/rpc.c b/CASA-auth-token/client/library/linux/rpc.c index 42587be4..9fc281a8 100644 --- a/CASA-auth-token/client/library/linux/rpc.c +++ b/CASA-auth-token/client/library/linux/rpc.c @@ -30,6 +30,8 @@ //===[ Type definitions ]================================================== #define MAX_RPC_RETRIES 3 +#define MILLISECONDS_BETWEEN_RPC_RETRIES 3000 +#define MAX_RPC_TIME_MILLISECONDS 60000 //===[ External prototypes ]=============================================== @@ -554,12 +556,37 @@ Rpc( { CasaStatus retStatus; int retries = 0; + DWORD startTime = GetTickCount(); + DWORD currentTime; DbgTrace(1, "-Rpc- Start\n", 0); // Retry the RPC as needed do { + // Check if this is a retry + if (retries != 0) + { + // This is a retry, check if we should keep retrying. + currentTime = GetTickCount(); + if (currentTime > startTime) + { + if ((currentTime - startTime) > MAX_RPC_TIME_MILLISECONDS) + { + DbgTrace(1, "-Rpc- Stopping after %d retries\n", retries); + break; + } + } + else + { + // The clock must have wrapped, treat it as if no time has elapsed. + startTime = currentTime; + } + + // Pause before the next retry + usleep(MILLISECONDS_BETWEEN_RPC_RETRIES * 1000); + } + // Issue the RPC retStatus = InternalRpc(pSession, pMethod, @@ -571,8 +598,7 @@ Rpc( // Account for this try retries ++; - } while (CasaStatusCode(retStatus) == CASA_STATUS_CONNECTION_ERROR - && retries < MAX_RPC_RETRIES); + } while (CasaStatusCode(retStatus) == CASA_STATUS_CONNECTION_ERROR); DbgTrace(1, "-Rpc- End, retStatus = %0X\n", retStatus);