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
{
wxASSERT_MSG( wxIsMainThread(), "unsafe to call from other threads" );
- return gs_socketInitDone;
+ return gs_socketInitCount != 0;
}
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;
}
{
wxCHECK_RET( wxIsMainThread(), "must be called from the main thread" );
- wxCHECK_RET( gs_socketInitDone, "unnecessary call to Shutdown()" );
-
- gs_socketInitDone = false;
+ wxCHECK_RET( gs_socketInitCount > 0, "too many calls to Shutdown()" );
- 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();
+ }
}
// --------------------------------------------------------------------------
{
wxSocketReadGuard read(this);
+ // Peek() should never block
+ wxSocketWaitModeChanger changeFlags(this, wxSOCKET_NOWAIT);
+
m_lcount = DoRead(buffer, nbytes);
Pushback(buffer, m_lcount);
#endif
// and for OSXManagerSetter in the OS X one
-#ifdef __WXMAC__
+#ifdef __WXOSX__
wxFORCE_LINK_MODULE( osxsocket )
#endif