X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4017f5ca49e153e04ffd1c49bc93afd31c1cdf87..6c0487907a89a7ae0fac20adaf2835cf9da6975c:/src/common/socket.cpp diff --git a/src/common/socket.cpp b/src/common/socket.cpp index fb18c2e341..44b408c49c 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(); + } } // -------------------------------------------------------------------------- @@ -2092,7 +2096,7 @@ wxFORCE_LINK_MODULE( socketiohandler ) #endif // and for OSXManagerSetter in the OS X one -#ifdef __WXMAC__ +#ifdef __WXOSX__ wxFORCE_LINK_MODULE( osxsocket ) #endif