diff --git a/CASA-auth-token/server/utilities/IpcLibs/linux/client/client.cpp b/CASA-auth-token/server/utilities/IpcLibs/linux/client/client.cpp index 9a36e469..d21a9322 100644 --- a/CASA-auth-token/server/utilities/IpcLibs/linux/client/client.cpp +++ b/CASA-auth-token/server/utilities/IpcLibs/linux/client/client.cpp @@ -58,20 +58,20 @@ int DebugLevel = 0; bool UseSyslog = false; // Application Name for logging purposes -char unInitialized[] = "Uninitialized"; +static char unInitialized[] = "Uninitialized"; char *pAppName = unInitialized; // Application threaded information -bool appMultithreaded; +static bool appMultithreaded; // Client mutex -pthread_mutex_t clientMutex; +static pthread_mutex_t clientMutex; // Mutex for interlocked operations pthread_mutex_t interlockedMutex; // Indicators -bool svcInitialized = false; +static bool svcInitialized = false; // Map of open remote endpoints. // @@ -83,10 +83,10 @@ bool svcInitialized = false; typedef map*> REPMap; typedef REPMap::iterator REPMapIter; typedef pair REPIterBoolPair; -REPMap repMap; +static REPMap *g_pRepMap = NULL; // RemoteEndPoint handle allocator -uint32_t remoteEndPointHandleAllocator = 1; +static uint32_t remoteEndPointHandleAllocator = 1; //++======================================================================= @@ -159,7 +159,7 @@ IpcClientOpenUnixRemoteEndPoint( { // Insert the new RemoteEndPoint into the REP map REPIterBoolPair insertResult; - insertResult = repMap.insert(make_pair(handle, pSmartRemoteEndPoint)); + insertResult = g_pRepMap->insert(make_pair(handle, pSmartRemoteEndPoint)); if (!insertResult.second) { // Insertion failed @@ -275,7 +275,7 @@ IpcClientOpenInetRemoteEndPoint( { // Insert the new RemoteEndPoint into the REP map REPIterBoolPair insertResult; - insertResult = repMap.insert(make_pair(handle, pSmartRemoteEndPoint)); + insertResult = g_pRepMap->insert(make_pair(handle, pSmartRemoteEndPoint)); if (!insertResult.second) { // Insertion failed @@ -352,12 +352,12 @@ IpcClientCloseRemoteEndPoint( // Find the appropriate RemoteEndPoint object in the REP Map using // the handle provided by the caller. - REPMapIter iter = repMap.find(endPointHandle); - if (iter != repMap.end()) + REPMapIter iter = g_pRepMap->find(endPointHandle); + if (iter != g_pRepMap->end()) { // Object was found in the map, remove it. SmartRemoteEndPoint *pSmartRemoteEndPoint = iter->second; - repMap.erase(iter); + g_pRepMap->erase(iter); // Release our mutex before deleting the endpoint pthread_mutex_unlock(&clientMutex); @@ -452,8 +452,8 @@ IpcClientSubmitReq( // Find the appropriate RemoteEndPoint object in the REP Map using // the handle provided by the caller. - REPMapIter iter = repMap.find(endPointHandle); - if (iter != repMap.end()) + REPMapIter iter = g_pRepMap->find(endPointHandle); + if (iter != g_pRepMap->end()) { // Object was found in the map, use it to submit // the request. @@ -543,29 +543,37 @@ IpcClientInit( // Verify that we have not been initialized already if (!svcInitialized) { - // Save a copy of the application name - pAppName = new char[strlen(pName) + 1]; - if (pAppName == NULL) - { - DbgTrace(0, "IpcClientInit- Memory allocation failure\n", 0); - goto exit; + try { + // Save a copy of the application name + pAppName = new char[strlen(pName) + 1]; + if (pAppName == NULL) + { + DbgTrace(0, "IpcClientInit- Memory allocation failure\n", 0); + goto exit; + } + strcpy(pAppName, pName); + + // Create our Remote Endpoint Map + g_pRepMap = new REPMap(); + + // Save the app multithreaded information + appMultithreaded = multithreaded; + + // Save the rest of the debug settings + DebugLevel = debugLevel; + UseSyslog = useSyslog; + + // Initialize our mutexes + pthread_mutex_init(&clientMutex, NULL); + pthread_mutex_init(&interlockedMutex, NULL); + + // Success + svcInitialized = true; + retStatus = 0; + + } catch (...) { + DbgTrace(0, "IpcClientInit- Exception caught\n", 0); } - strcpy(pAppName, pName); - - // Save the app multithreaded information - appMultithreaded = multithreaded; - - // Save the rest of the debug settings - DebugLevel = debugLevel; - UseSyslog = useSyslog; - - // Initialize our mutexes - pthread_mutex_init(&clientMutex, NULL); - pthread_mutex_init(&interlockedMutex, NULL); - - // Success - svcInitialized = true; - retStatus = 0; } else { @@ -606,11 +614,11 @@ IpcClientShutdown(void) // Clean up the REP map pthread_mutex_lock(&clientMutex); - while (!repMap.empty()) + while (!g_pRepMap->empty()) { - REPMapIter iter = repMap.begin(); + REPMapIter iter = g_pRepMap->begin(); SmartRemoteEndPoint *pSmartRemoteEndPoint = iter->second; - repMap.erase(iter); + g_pRepMap->erase(iter); pthread_mutex_unlock(&clientMutex); delete pSmartRemoteEndPoint; @@ -629,6 +637,10 @@ IpcClientShutdown(void) while (numCChannelObjects) sleep(0); // Only suffer a time-slice sleep(0); + + // Delete the Remote Endpoint Map + delete(g_pRepMap); + g_pRepMap = NULL; } else {