From 215bd98dd50edf704ca0e20d7ffdea90310d750c Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Wed, 9 Jul 2008 17:51:22 +0000 Subject: [PATCH] Changing the RPC retry logic to be bounded by time rather than by the number of retries to match what is being done in the Windows platform. --- CASA-auth-token/client/library/linux/rpc.c | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) 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);