From 44c2703fbf07a5685d1959f3f72d3ccf91a7f5db Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 21 Sep 2009 14:45:52 +0000 Subject: [PATCH] Restore socket initialization times counter. The change of the counter to a simple boolean in r61985 broke the code which called both Initialize() and Shutdown() multiple (but the same number of) times. As this is the documented correct behaviour, restore the counter to cater for it even if we don't really need it any longer. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61998 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/socket.cpp | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/common/socket.cpp b/src/common/socket.cpp index fb18c2e341..923dff0d49 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -753,8 +753,11 @@ int wxSocketImpl::Write(const void *buffer, int size) namespace { -// flag indicating whether wxSocketManager was already initialized -bool gs_socketInitDone = false; +// counts the number of calls to Initialize() minus the number of calls to +// Shutdown(): we don't really need it any more but it was documented that +// Shutdown() must be called the same number of times as Initialize() and using +// a counter helps us to check it +int gs_socketInitCount = 0; } // anonymous namespace @@ -762,7 +765,7 @@ bool wxSocketBase::IsInitialized() { wxASSERT_MSG( wxIsMainThread(), "unsafe to call from other threads" ); - return gs_socketInitDone; + return gs_socketInitCount != 0; } bool wxSocketBase::Initialize() @@ -770,15 +773,15 @@ bool wxSocketBase::Initialize() wxCHECK_MSG( wxIsMainThread(), false, "must be called from the main thread" ); - if ( !gs_socketInitDone ) + if ( !gs_socketInitCount ) { wxSocketManager * const manager = wxSocketManager::Get(); if ( !manager || !manager->OnInit() ) return false; - - gs_socketInitDone = true; } + gs_socketInitCount++; + return true; } @@ -786,14 +789,15 @@ void wxSocketBase::Shutdown() { wxCHECK_RET( wxIsMainThread(), "must be called from the main thread" ); - wxCHECK_RET( gs_socketInitDone, "unnecessary call to Shutdown()" ); + wxCHECK_RET( gs_socketInitCount > 0, "too many calls to Shutdown()" ); - gs_socketInitDone = false; - - wxSocketManager * const manager = wxSocketManager::Get(); - wxCHECK_RET( manager, "should have a socket manager" ); + if ( !--gs_socketInitCount ) + { + wxSocketManager * const manager = wxSocketManager::Get(); + wxCHECK_RET( manager, "should have a socket manager" ); - manager->OnExit(); + manager->OnExit(); + } } // -------------------------------------------------------------------------- -- 2.45.2