m_neededreq(0), m_notify_state(FALSE),
m_connected(FALSE), m_establishing(FALSE),
m_reading(FALSE), m_writing(FALSE),
- m_error(FALSE), m_lcount(0), m_timeout(600), m_states(),
+ m_error(FALSE), m_lcount(0), m_timeout(600),
+ m_states(), m_beingDeleted(FALSE),
m_unread(NULL), m_unrd_size(0), m_unrd_cur(0),
m_cbk(NULL), m_cdata(NULL)
{
m_neededreq(0), m_notify_state(FALSE),
m_connected(FALSE), m_establishing(FALSE),
m_reading(FALSE), m_writing(FALSE),
- m_error(FALSE), m_lcount(0), m_timeout(600), m_states(),
+ m_error(FALSE), m_lcount(0), m_timeout(600),
+ m_states(), m_beingDeleted(FALSE),
m_unread(NULL), m_unrd_size(0), m_unrd_cur(0),
m_cbk(NULL), m_cdata(NULL)
{
wxSocketBase::~wxSocketBase()
{
- if (m_unread)
- free(m_unread);
+ // Just in case the app called Destroy() *and* then deleted
+ // the socket immediately: don't leave dangling pointers.
+#if wxUSE_GUI
+ wxPendingDelete.DeleteObject(this);
+#endif
// Shutdown and close the socket
- Close();
+ if (!m_beingDeleted)
+ Close();
// Destroy the GSocket object
if (m_socket)
GSocket_destroy(m_socket);
+
+ // Free the pushback buffer
+ if (m_unread)
+ free(m_unread);
}
-/*
bool wxSocketBase::Destroy()
{
// Delayed destruction: the socket will be deleted during the next
// idle loop iteration. This ensures that all pending events have
// been processed.
-
m_beingDeleted = TRUE;
+
+ // Shutdown and close the socket
Close();
- if ( !wxPendingDelete.Member(this) )
+#if wxUSE_GUI
+ if ( wxPendingDelete.Member(this) )
wxPendingDelete.Append(this);
+#else
+ delete this;
+#endif
return TRUE;
}
-*/
+
// --------------------------------------------------------------------------
// Basic IO operations
if (!m_establishing || !m_socket) // No connection in progress
return FALSE;
- return _Wait(seconds, milliseconds, GSOCK_CONNECTION_FLAG);
+ return _Wait(seconds, milliseconds, GSOCK_CONNECTION_FLAG |
+ GSOCK_LOST_FLAG);
}
// ==========================================================================