]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/socket.cpp
Added DoSetSize and DoMoveWindow to generic wxStaticLine.
[wxWidgets.git] / src / common / socket.cpp
index 003bd9dbcfb3afccda8e45f3cf037ae82951ccc5..95669073cd46c8ea8a56b0f01b8e8048e4116bd2 100644 (file)
@@ -110,6 +110,44 @@ public:
 // wxSocketBase
 // ==========================================================================
 
 // wxSocketBase
 // ==========================================================================
 
+// --------------------------------------------------------------------------
+// Initialization and shutdown
+// --------------------------------------------------------------------------
+
+// FIXME-MT: all this is MT-unsafe, of course, we should protect all accesses
+//           to m_countInit with a crit section
+size_t wxSocketBase::m_countInit = 0;
+
+bool wxSocketBase::IsInitialized()
+{
+    return m_countInit > 0;
+}
+
+bool wxSocketBase::Initialize()
+{
+    if ( !m_countInit++ )
+    {
+        if ( !GSocket_Init() )
+        {
+            m_countInit--;
+
+            return FALSE;
+        }
+    }
+
+    return TRUE;
+}
+
+void wxSocketBase::Shutdown()
+{
+    // we should be initialized
+    wxASSERT_MSG( m_countInit, _T("extra call to Shutdown()") );
+    if ( !--m_countInit )
+    {
+        GSocket_Cleanup();
+    }
+}
+
 // --------------------------------------------------------------------------
 // Ctor and dtor
 // --------------------------------------------------------------------------
 // --------------------------------------------------------------------------
 // Ctor and dtor
 // --------------------------------------------------------------------------
@@ -145,6 +183,13 @@ void wxSocketBase::Init()
   m_cbk          = NULL;
   m_cdata        = NULL;
 #endif // WXWIN_COMPATIBILITY
   m_cbk          = NULL;
   m_cdata        = NULL;
 #endif // WXWIN_COMPATIBILITY
+
+  if ( !IsInitialized() )
+  {
+      // this Initialize() will be undone by wxSocketModule::OnExit(), all the
+      // other calls to it should be matched by a call to Shutdown()
+      Initialize();
+  }
 }
 
 wxSocketBase::wxSocketBase()
 }
 
 wxSocketBase::wxSocketBase()
@@ -862,9 +907,10 @@ char *wxSocketBase::CallbackData(char *data)
 // decoupled from wx_socket_callback and thus they suffer from a variety
 // of problems. Avoid them where possible and use events instead.
 
 // decoupled from wx_socket_callback and thus they suffer from a variety
 // of problems. Avoid them where possible and use events instead.
 
-static void LINKAGEMODE wx_socket_callback(GSocket * WXUNUSED(socket),
-                                           GSocketEvent notification,
-                                           char *cdata)
+extern "C"
+void LINKAGEMODE wx_socket_callback(GSocket * WXUNUSED(socket),
+                                    GSocketEvent notification,
+                                    char *cdata)
 {
   wxSocketBase *sckobj = (wxSocketBase *)cdata;
 
 {
   wxSocketBase *sckobj = (wxSocketBase *)cdata;
 
@@ -1241,11 +1287,21 @@ wxDatagramSocket& wxDatagramSocket::SendTo( wxSockAddress& addr,
 
 class WXDLLEXPORT wxSocketModule : public wxModule
 {
 
 class WXDLLEXPORT wxSocketModule : public wxModule
 {
-  DECLARE_DYNAMIC_CLASS(wxSocketModule)
-
 public:
 public:
-  bool OnInit() { return GSocket_Init() != 0; }
-  void OnExit() { GSocket_Cleanup(); }
+    virtual bool OnInit()
+    {
+        // wxSocketBase will call GSocket_Init() itself when/if needed
+        return TRUE;
+    }
+
+    virtual void OnExit()
+    {
+        if ( wxSocketBase::IsInitialized() )
+            wxSocketBase::Shutdown();
+    }
+
+private:
+    DECLARE_DYNAMIC_CLASS(wxSocketModule)
 };
 
 IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)
 };
 
 IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)