[mapguide-commits] r4277 - in trunk/MgDev: Common/Foundation/System Common/MapGuideCommon/Services Server/src/Common/Base Server/src/Core

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Fri Oct 2 12:28:32 EDT 2009


Author: brucedechant
Date: 2009-10-02 12:28:31 -0400 (Fri, 02 Oct 2009)
New Revision: 4277

Modified:
   trunk/MgDev/Common/Foundation/System/StreamHelper.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/ServerConnectionImp.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.cpp
   trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.h
   trunk/MgDev/Server/src/Common/Base/ClientHandler.cpp
   trunk/MgDev/Server/src/Common/Base/ServiceOperation.cpp
   trunk/MgDev/Server/src/Common/Base/ServiceOperation.h
   trunk/MgDev/Server/src/Core/TimedEventHandler.cpp
Log:
Fix for trac ticket 1110 - Stability improvements
http://trac.osgeo.org/mapguide/ticket/1110

Notes:
- Added check for 0 length strings
- Added missing stream close_writer(), close_reader() and close() methods.
  Note: This sometimes caused a TCP/IP mismatch error even though web and server were the same.
- Removed unused TLS
- Adjusted guards around thread data


Modified: trunk/MgDev/Common/Foundation/System/StreamHelper.cpp
===================================================================
--- trunk/MgDev/Common/Foundation/System/StreamHelper.cpp	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Common/Foundation/System/StreamHelper.cpp	2009-10-02 16:28:31 UTC (rev 4277)
@@ -79,6 +79,13 @@
 
     if (mssDone != stat) return stat;
 
+    // Check for 0 length string
+    if(len == 0)
+    {
+        wcStr = L"";
+        return stat;
+    }
+
     UINT8 currSize = sizeof(wchar_t);
     if (currSize == charSize)
     {

Modified: trunk/MgDev/Common/MapGuideCommon/Services/ServerConnectionImp.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/ServerConnectionImp.cpp	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Common/MapGuideCommon/Services/ServerConnectionImp.cpp	2009-10-02 16:28:31 UTC (rev 4277)
@@ -105,7 +105,14 @@
     {
         int err = ACE_OS::last_error();
         MG_UNUSED_ARG(err);
-        // Could not connect
+
+        // We failed to connect so we must clean this up differently then just relying on the 
+        // desturctor because the Disconnect() method called by the destructor will try and 
+        // send a control packet which we don't want.
+        mServer->close_writer();
+        mServer->close_reader();
+        mServer->close();
+
         delete mServer;
         mServer = NULL;
         return false;
@@ -149,6 +156,7 @@
         }
 
         // Long enough.  Bail.
+        mServer->close_reader();
         mServer->close();
 
         delete mServer;

Modified: trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.cpp
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.cpp	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.cpp	2009-10-02 16:28:31 UTC (rev 4277)
@@ -21,8 +21,6 @@
 #undef CreateService
 #endif
 
-static ACE_thread_key_t g_threadLocalSiteConnection = 0;
-
 //////////////////////////////////////////////////////////////////
 /// <summary>
 /// Creates a site connection.  The local site defined
@@ -572,55 +570,6 @@
     return site.Detach();
 }
 
-///////////////////////////////
-///<summary>
-///Sets the site connection for the current thread.  This
-///function uses thread local storage.
-///</summary>
-void MgSiteConnection::SetCurrentConnection(MgSiteConnection* siteConnection)
-{
-    if (0 == g_threadLocalSiteConnection)
-    {
-        // Perform Double-Checked Locking Optimization.
-        ACE_MT (ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, *ACE_Static_Object_Lock::instance ()));
-        if (0 == g_threadLocalSiteConnection)
-        {
-            if (ACE_OS::thr_keycreate(&g_threadLocalSiteConnection, NULL) < 0)
-            {
-                g_threadLocalSiteConnection = 0;
-            }
-        }
-    }
-
-    if (0 != g_threadLocalSiteConnection)
-    {
-        ACE_OS::thr_setspecific(g_threadLocalSiteConnection, siteConnection);
-    }
-}
-
-///////////////////////////////
-///<summary>
-///Gets the site connection for the current thread which was
-///set previously using SetCurrentConnection.  This
-///function uses thread local storage.
-///</summary>
-MgSiteConnection* MgSiteConnection::GetCurrentConnection()
-{
-    MgSiteConnection* connection = NULL;
-    if (0 != g_threadLocalSiteConnection)
-    {
-        ACE_OS::thr_getspecific(g_threadLocalSiteConnection, (void**) &connection);
-    }
-
-    if (NULL == connection)
-    {
-        // No site connection means that we not have opened the connection to the site server yet.
-        throw new MgConnectionNotOpenException(L"MgSiteConnection.GetCurrentConnection", __LINE__, __WFILE__, NULL, L"", NULL);
-    }
-
-    return connection;
-}
-
 MgUserInformation* MgSiteConnection::GetUserInfo()
 {
     if (NULL == m_connProp.p)

Modified: trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.h
===================================================================
--- trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.h	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Common/MapGuideCommon/Services/SiteConnection.h	2009-10-02 16:28:31 UTC (rev 4277)
@@ -269,33 +269,6 @@
 
     ///////////////////////////////
     /// \brief
-    /// Sets the site connection for the current thread.  This
-    /// function uses thread local storage.
-    ///
-    /// \param siteConnection
-    /// Site connection to assign to the current thread
-    ///
-    /// \return
-    /// Nothing
-    ///
-    static void SetCurrentConnection(MgSiteConnection* siteConnection);
-
-    ///////////////////////////////
-    /// \brief
-    /// Gets the site connection for the current thread which was
-    /// set previously using SetCurrentConnection.  This
-    /// function uses thread local storage.
-    ///
-    /// \return
-    /// Site connection for currently executing thread
-    ///
-    /// \exception MgConnectionNotOpenException if the site connection has not been set
-    ///
-    static MgSiteConnection* GetCurrentConnection();
-
-
-    ///////////////////////////////
-    /// \brief
     /// Gets the user info for this site
     ///
     /// \return

Modified: trunk/MgDev/Server/src/Common/Base/ClientHandler.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Base/ClientHandler.cpp	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Server/src/Common/Base/ClientHandler.cpp	2009-10-02 16:28:31 UTC (rev 4277)
@@ -76,6 +76,7 @@
         // clearing out buffer
     }
 
+    m_SockStream.close_reader();
     m_SockStream.close();
 
     m_pMessageQueue = NULL;
@@ -199,6 +200,8 @@
         stream->WriteObject(mgException);
         stream->WriteStreamEnd();
 
+        m_SockStream.close_writer();
+        m_SockStream.close_reader();
         m_SockStream.close();
     }
 
@@ -258,6 +261,8 @@
 
     mask = ACE_Event_Handler::ALL_EVENTS_MASK | ACE_Event_Handler::DONT_CALL;
     reactor()->remove_handler(this, mask);
+    m_SockStream.close_writer();
+    m_SockStream.close_reader();
     m_SockStream.close();
 
     MgServerManager* pServerManager = MgServerManager::GetInstance();

Modified: trunk/MgDev/Server/src/Common/Base/ServiceOperation.cpp
===================================================================
--- trunk/MgDev/Server/src/Common/Base/ServiceOperation.cpp	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Server/src/Common/Base/ServiceOperation.cpp	2009-10-02 16:28:31 UTC (rev 4277)
@@ -62,6 +62,7 @@
                 m_currConnection->SetSessionId(L"");
             }
         }
+        m_currConnection = NULL;
     }
 
     MgUserInformation::SetCurrentUserInfo(NULL);
@@ -152,6 +153,7 @@
 void MgServiceOperation::Initialize(MgStreamData* data,
     const MgOperationPacket& packet)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::Init()\n" )));
     ACE_ASSERT(NULL != data);
 
@@ -206,6 +208,7 @@
 ///
 bool MgServiceOperation::HandleException(MgException* except)
 {
+    ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex, false));
     ACE_ASSERT(!m_opCompleted);
 
     MG_TRY()
@@ -267,6 +270,7 @@
 
 void MgServiceOperation::EndExecution()
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
 
@@ -276,7 +280,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -311,6 +314,7 @@
 
 void MgServiceOperation::EndExecution(bool value)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
 
@@ -320,7 +324,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -357,6 +360,7 @@
 
 void MgServiceOperation::EndExecution(INT32 value)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
 
@@ -366,7 +370,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -403,6 +406,7 @@
 
 void MgServiceOperation::EndExecution(INT64 value)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
 
@@ -412,7 +416,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -449,6 +452,7 @@
 
 void MgServiceOperation::EndExecution(STRING value)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
 
@@ -458,7 +462,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -495,6 +498,7 @@
 
 void MgServiceOperation::EndExecution(MgSerializable* obj)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     // ACE_ASSERT(NULL != obj);
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
@@ -505,7 +509,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -542,6 +545,7 @@
 
 void MgServiceOperation::EndExecution(MgStringCollection* stringCollection)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     // ACE_ASSERT(NULL != stringCollection);
     ACE_ASSERT(m_argsRead && !m_opCompleted && m_stream != NULL && NULL != m_currConnection);
@@ -552,7 +556,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     MgService* service = GetService();
     assert(NULL != service);
@@ -589,6 +592,7 @@
 
 void MgServiceOperation::EndExecution(MgException* except)
 {
+    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
     ACE_DEBUG((LM_DEBUG, ACE_TEXT("  (%t) MgServiceOperation::EndExecution()\n" )));
     ACE_ASSERT(NULL != except && m_argsRead && !m_opCompleted && m_stream != NULL);
 
@@ -598,7 +602,6 @@
     ACE_ASSERT(NULL != serverStreamData);
     Ptr<MgClientHandler> clientHandler = serverStreamData->GetClientHandler();
     ACE_ASSERT(NULL != clientHandler.p);
-    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, clientHandler.p->m_mutex));
 
     if (NULL != m_currConnection)
     {

Modified: trunk/MgDev/Server/src/Common/Base/ServiceOperation.h
===================================================================
--- trunk/MgDev/Server/src/Common/Base/ServiceOperation.h	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Server/src/Common/Base/ServiceOperation.h	2009-10-02 16:28:31 UTC (rev 4277)
@@ -89,6 +89,7 @@
 private:
 
     bool m_opCompleted;
+    ACE_Recursive_Thread_Mutex m_mutex;
 };
 
 /// Inline Methods

Modified: trunk/MgDev/Server/src/Core/TimedEventHandler.cpp
===================================================================
--- trunk/MgDev/Server/src/Core/TimedEventHandler.cpp	2009-09-30 22:59:49 UTC (rev 4276)
+++ trunk/MgDev/Server/src/Core/TimedEventHandler.cpp	2009-10-02 16:28:31 UTC (rev 4277)
@@ -35,7 +35,6 @@
 ///
 MgTimedEventHandler::~MgTimedEventHandler()
 {
-    MgUserInformation::SetCurrentUserInfo(NULL);
 }
 
 ///////////////////////////////////////////////////////////////////////////////



More information about the mapguide-commits mailing list