]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/socket.cpp
added Add/InsertTool() (patch 672032)
[wxWidgets.git] / src / common / socket.cpp
index 95669073cd46c8ea8a56b0f01b8e8048e4116bd2..d79c4986c20a72c2309a11a0ab6992c5c248799f 100644 (file)
@@ -76,6 +76,8 @@
     #define PROCESS_EVENTS()
 #endif // wxUSE_GUI/!wxUSE_GUI
 
+#define wxTRACE_Socket _T("wxSocket")
+
 // --------------------------------------------------------------------------
 // wxWin macros
 // --------------------------------------------------------------------------
@@ -104,6 +106,8 @@ public:
 
 public:
   wxSocketState() : wxObject() {}
+
+    DECLARE_NO_COPY_CLASS(wxSocketState)
 };
 
 // ==========================================================================
@@ -777,6 +781,12 @@ bool wxSocketBase::GetPeer(wxSockAddress& addr_man) const
     return FALSE;
 
   peer = GSocket_GetPeer(m_socket);
+
+    // copying a null address would just trigger an assert anyway
+
+  if (!peer)
+    return FALSE;
+
   addr_man.SetAddress(peer);
   GAddress_destroy(peer);
 
@@ -824,11 +834,11 @@ void wxSocketBase::RestoreState()
   wxNode *node;
   wxSocketState *state;
 
-  node = m_states.Last();
+  node = m_states.GetLast();
   if (!node)
     return;
 
-  state = (wxSocketState *)node->Data();
+  state = (wxSocketState *)node->GetData();
 
   m_flags      = state->m_flags;
   m_notify     = state->m_notify;
@@ -1067,26 +1077,32 @@ wxSocketServer::wxSocketServer(wxSockAddress& addr_man,
                                wxSocketFlags flags)
               : wxSocketBase(flags, wxSOCKET_SERVER)
 {
-  // Create the socket
-  m_socket = GSocket_new();
+    wxLogTrace( wxTRACE_Socket, _T("Opening wxSocketServer") );
 
-  if (!m_socket)
-    return;
+    m_socket = GSocket_new();
 
-  // Setup the socket as server
-  GSocket_SetLocal(m_socket, addr_man.GetAddress());
-  if (GSocket_SetServer(m_socket) != GSOCK_NOERROR)
-  {
-    GSocket_destroy(m_socket);
-    m_socket = NULL;
-    return;
-  }
+    if (!m_socket)
+    {
+        wxLogTrace( wxTRACE_Socket, _T("*** GSocket_new failed") );
+        return;
+    }
 
-  GSocket_SetTimeout(m_socket, m_timeout * 1000);
-  GSocket_SetCallback(m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG |
-                                GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG,
-                                wx_socket_callback, (char *)this);
+        // Setup the socket as server
 
+    GSocket_SetLocal(m_socket, addr_man.GetAddress());
+    if (GSocket_SetServer(m_socket) != GSOCK_NOERROR)
+    {
+        GSocket_destroy(m_socket);
+        m_socket = NULL;
+
+        wxLogTrace( wxTRACE_Socket, _T("*** GSocket_SetServer failed") );
+        return;
+    }
+
+    GSocket_SetTimeout(m_socket, m_timeout * 1000);
+    GSocket_SetCallback(m_socket, GSOCK_INPUT_FLAG | GSOCK_OUTPUT_FLAG |
+                                  GSOCK_LOST_FLAG | GSOCK_CONNECTION_FLAG,
+                                  wx_socket_callback, (char *)this);
 }
 
 // --------------------------------------------------------------------------
@@ -1308,3 +1324,5 @@ IMPLEMENT_DYNAMIC_CLASS(wxSocketModule, wxModule)
 
 #endif
   // wxUSE_SOCKETS
+
+// vi:sts=4:sw=4:et