]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/socket.cpp
Made code that uses wxArrayPGProperty more STL compliant (still can't use wxVector...
[wxWidgets.git] / src / common / socket.cpp
index 000d89b4648c4371bbacb81f1523136f917d2f3b..95778390a5c75d37ad671eca22729c633eefc610 100644 (file)
@@ -115,7 +115,7 @@ wxDEFINE_EVENT(wxEVT_SOCKET, wxSocketEvent);
 // discard buffer
 #define MAX_DISCARD_SIZE (10 * 1024)
 
-#define wxTRACE_Socket _T("wxSocket")
+#define wxTRACE_Socket wxT("wxSocket")
 
 // --------------------------------------------------------------------------
 // wxWin macros
@@ -533,7 +533,14 @@ wxSocketImpl *wxSocketImpl::Accept(wxSocketBase& wxsocket)
     if ( fd == INVALID_SOCKET )
         return NULL;
 
-    wxSocketImpl * const sock = Create(wxsocket);
+    wxSocketManager * const manager = wxSocketManager::Get();
+    if ( !manager )
+        return NULL;
+
+    wxSocketImpl * const sock = manager->CreateSocket(wxsocket);
+    if ( !sock )
+        return NULL;
+
     sock->m_fd = fd;
     sock->m_peer = wxSockAddressImpl(from.addr, fromlen);
 
@@ -771,7 +778,7 @@ bool wxSocketBase::Initialize()
 void wxSocketBase::Shutdown()
 {
     // we should be initialized
-    wxASSERT_MSG( m_countInit > 0, _T("extra call to Shutdown()") );
+    wxASSERT_MSG( m_countInit > 0, wxT("extra call to Shutdown()") );
     if ( --m_countInit == 0 )
     {
         wxSocketManager * const manager = wxSocketManager::Get();
@@ -841,12 +848,6 @@ wxSocketBase::wxSocketBase(wxSocketFlags flags, wxSocketType type)
 
 wxSocketBase::~wxSocketBase()
 {
-    // Just in case the app called Destroy() *and* then deleted the socket
-    // immediately: don't leave dangling pointers.
-    wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
-    if ( traits )
-        traits->RemoveFromPendingDelete(this);
-
     // Shutdown and close the socket
     if (!m_beingDeleted)
         Close();
@@ -855,8 +856,7 @@ wxSocketBase::~wxSocketBase()
     delete m_impl;
 
     // Free the pushback buffer
-    if (m_unread)
-        free(m_unread);
+    free(m_unread);
 }
 
 bool wxSocketBase::Destroy()
@@ -872,14 +872,13 @@ bool wxSocketBase::Destroy()
     // Suppress events from now on
     Notify(false);
 
-    // schedule this object for deletion
-    wxAppTraits *traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
-    if ( traits )
+    // Schedule this object for deletion instead of destroying it right now if
+    // possible as we may have other events pending for it
+    if ( wxTheApp )
     {
-        // let the traits object decide what to do with us
-        traits->ScheduleForDestroy(this);
+        wxTheApp->ScheduleForDestruction(this);
     }
-    else // no app or no traits
+    else // no app
     {
         // in wxBase we might have no app object at all, don't leak memory
         delete this;
@@ -1745,13 +1744,14 @@ wxSocketServer::wxSocketServer(const wxSockAddress& addr,
                                wxSocketFlags flags)
               : wxSocketBase(flags, wxSOCKET_SERVER)
 {
-    wxLogTrace( wxTRACE_Socket, _T("Opening wxSocketServer") );
+    wxLogTrace( wxTRACE_Socket, wxT("Opening wxSocketServer") );
 
-    m_impl = wxSocketImpl::Create(*this);
+    wxSocketManager * const manager = wxSocketManager::Get();
+    m_impl = manager ? manager->CreateSocket(*this) : NULL;
 
     if (!m_impl)
     {
-        wxLogTrace( wxTRACE_Socket, _T("*** Failed to create m_impl") );
+        wxLogTrace( wxTRACE_Socket, wxT("*** Failed to create m_impl") );
         return;
     }
 
@@ -1773,11 +1773,11 @@ wxSocketServer::wxSocketServer(const wxSockAddress& addr,
         delete m_impl;
         m_impl = NULL;
 
-        wxLogTrace( wxTRACE_Socket, _T("*** CreateServer() failed") );
+        wxLogTrace( wxTRACE_Socket, wxT("*** CreateServer() failed") );
         return;
     }
 
-    wxLogTrace( wxTRACE_Socket, _T("wxSocketServer on fd %d"), m_impl->m_fd );
+    wxLogTrace( wxTRACE_Socket, wxT("wxSocketServer on fd %d"), m_impl->m_fd );
 }
 
 // --------------------------------------------------------------------------
@@ -1843,7 +1843,7 @@ bool wxSocketServer::WaitForAccept(long seconds, long milliseconds)
 
 bool wxSocketBase::GetOption(int level, int optname, void *optval, int *optlen)
 {
-    wxASSERT_MSG( m_impl, _T("Socket not initialised") );
+    wxASSERT_MSG( m_impl, wxT("Socket not initialised") );
 
     SOCKOPTLEN_T lenreal = *optlen;
     if ( getsockopt(m_impl->m_fd, level, optname,
@@ -1858,7 +1858,7 @@ bool wxSocketBase::GetOption(int level, int optname, void *optval, int *optlen)
 bool
 wxSocketBase::SetOption(int level, int optname, const void *optval, int optlen)
 {
-    wxASSERT_MSG( m_impl, _T("Socket not initialised") );
+    wxASSERT_MSG( m_impl, wxT("Socket not initialised") );
 
     return setsockopt(m_impl->m_fd, level, optname,
                       static_cast<const char *>(optval), optlen) == 0;
@@ -1905,7 +1905,8 @@ bool wxSocketClient::DoConnect(const wxSockAddress& remote,
     m_establishing = false;
 
     // Create and set up the new one
-    m_impl = wxSocketImpl::Create(*this);
+    wxSocketManager * const manager = wxSocketManager::Get();
+    m_impl = manager ? manager->CreateSocket(*this) : NULL;
     if ( !m_impl )
         return false;
 
@@ -1987,7 +1988,8 @@ wxDatagramSocket::wxDatagramSocket( const wxSockAddress& addr,
                 : wxSocketBase( flags, wxSOCKET_DATAGRAM )
 {
     // Create the socket
-    m_impl = wxSocketImpl::Create(*this);
+    wxSocketManager * const manager = wxSocketManager::Get();
+    m_impl = manager ? manager->CreateSocket(*this) : NULL;
 
     if (!m_impl)
         return;
@@ -2032,7 +2034,7 @@ wxDatagramSocket& wxDatagramSocket::SendTo( const wxSockAddress& addr,
                                             const void* buf,
                                             wxUint32 nBytes )
 {
-    wxASSERT_MSG( m_impl, _T("Socket not initialised") );
+    wxASSERT_MSG( m_impl, wxT("Socket not initialised") );
 
     m_impl->SetPeer(addr.GetAddress());
     Write(buf, nBytes);
@@ -2072,4 +2074,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)
 wxFORCE_LINK_MODULE( socketiohandler )
 #endif
 
+// same for ManagerSetter in the MSW file
+#ifdef __WXMSW__
+    wxFORCE_LINK_MODULE( mswsocket )
+#endif
+
+// and for OSXManagerSetter in the OS X one
+#ifdef __WXMAC__
+    wxFORCE_LINK_MODULE( osxsocket )
+#endif
+
 #endif // wxUSE_SOCKETS