From 8ea377f8459d349205252c7db0a3480484ce8fe2 Mon Sep 17 00:00:00 2001 From: Juan Carlos Luciani Date: Thu, 3 Jul 2008 20:41:23 +0000 Subject: [PATCH] Enhanced the RPC retry logic for the Windows client to be bounded by time rather than number of retries. Also, added a pause between retries to avoid saturating the network. The corresponding Linux client changes still need to be made. This changes allow us to support large number of clients against a single server. --- CASA-auth-token/client/library/linux/rpc.c | 2 +- .../client/library/windows/platform.c | 14 ++++++++ CASA-auth-token/client/library/windows/rpc.c | 34 ++++++++++++++++--- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/CASA-auth-token/client/library/linux/rpc.c b/CASA-auth-token/client/library/linux/rpc.c index f29366c9..42587be4 100644 --- a/CASA-auth-token/client/library/linux/rpc.c +++ b/CASA-auth-token/client/library/linux/rpc.c @@ -553,7 +553,7 @@ Rpc( //=======================================================================-- { CasaStatus retStatus; - int retries = 3; + int retries = 0; DbgTrace(1, "-Rpc- Start\n", 0); diff --git a/CASA-auth-token/client/library/windows/platform.c b/CASA-auth-token/client/library/windows/platform.c index 7510c17e..f1aa9ac9 100644 --- a/CASA-auth-token/client/library/windows/platform.c +++ b/CASA-auth-token/client/library/windows/platform.c @@ -543,6 +543,20 @@ NormalizeHostName( else { DbgTrace(0, "-NormalizeHostName- Name resolution failed, error = %d\n", WSAGetLastError()); + + // Not able to resolve the name in DNS, just use the host name as + // the normalized name. + pEntry->buffLengthRequired = strlen(pHostName) + 1; + pEntry->pNormalizedHostName = (char*) malloc(pEntry->buffLengthRequired); + if (pEntry->pNormalizedHostName) + { + // Copy the host name + strcpy(pEntry->pNormalizedHostName, pHostName); + } + else + { + DbgTrace(0, "-NormalizeHostName- Buffer allocation error\n", 0); + } } } else diff --git a/CASA-auth-token/client/library/windows/rpc.c b/CASA-auth-token/client/library/windows/rpc.c index 8890809c..38c50436 100644 --- a/CASA-auth-token/client/library/windows/rpc.c +++ b/CASA-auth-token/client/library/windows/rpc.c @@ -33,6 +33,8 @@ #define INCREMENT_RESPONSE_DATA_BUF_SIZE 256 #define MAX_RPC_RETRIES 3 +#define MILLISECONDS_BETWEEN_RPC_RETRIES 3000 +#define MAX_RPC_TIME_MILLISECONDS 60000 //===[ Function prototypes ]=============================================== @@ -776,13 +778,38 @@ Rpc( //=======================================================================-- { CasaStatus retStatus; - int retries = 3; + 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 + Sleep(MILLISECONDS_BETWEEN_RPC_RETRIES); + } + // Issue the RPC retStatus = InternalRpc(pSession, pMethod, @@ -794,10 +821,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);