Added Destroy()
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -134,6 +134,7 @@ protected:
|
|||||||
unsigned long m_timeout; // IO timeout value
|
unsigned long m_timeout; // IO timeout value
|
||||||
wxList m_states; // Stack of states
|
wxList m_states; // Stack of states
|
||||||
bool m_interrupt; // Interrupt ongoing wait operations
|
bool m_interrupt; // Interrupt ongoing wait operations
|
||||||
|
bool m_beingDeleted; // Marked for delayed deletion
|
||||||
|
|
||||||
// Pushback buffer
|
// Pushback buffer
|
||||||
char *m_unread; // Pushback buffer
|
char *m_unread; // Pushback buffer
|
||||||
@@ -147,9 +148,10 @@ protected:
|
|||||||
public:
|
public:
|
||||||
wxSocketBase();
|
wxSocketBase();
|
||||||
virtual ~wxSocketBase();
|
virtual ~wxSocketBase();
|
||||||
virtual bool Close();
|
virtual bool Destroy();
|
||||||
|
|
||||||
// Base IO
|
// Base IO
|
||||||
|
virtual bool Close();
|
||||||
wxSocketBase& Peek(char* buffer, wxUint32 nbytes);
|
wxSocketBase& Peek(char* buffer, wxUint32 nbytes);
|
||||||
wxSocketBase& Read(char* buffer, wxUint32 nbytes);
|
wxSocketBase& Read(char* buffer, wxUint32 nbytes);
|
||||||
wxSocketBase& Write(const char *buffer, wxUint32 nbytes);
|
wxSocketBase& Write(const char *buffer, wxUint32 nbytes);
|
||||||
|
@@ -92,7 +92,8 @@ wxSocketBase::wxSocketBase(wxSockFlags _flags, wxSockType _type) :
|
|||||||
m_neededreq(0), m_notify_state(FALSE),
|
m_neededreq(0), m_notify_state(FALSE),
|
||||||
m_connected(FALSE), m_establishing(FALSE),
|
m_connected(FALSE), m_establishing(FALSE),
|
||||||
m_reading(FALSE), m_writing(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_unread(NULL), m_unrd_size(0), m_unrd_cur(0),
|
||||||
m_cbk(NULL), m_cdata(NULL)
|
m_cbk(NULL), m_cdata(NULL)
|
||||||
{
|
{
|
||||||
@@ -105,7 +106,8 @@ wxSocketBase::wxSocketBase() :
|
|||||||
m_neededreq(0), m_notify_state(FALSE),
|
m_neededreq(0), m_notify_state(FALSE),
|
||||||
m_connected(FALSE), m_establishing(FALSE),
|
m_connected(FALSE), m_establishing(FALSE),
|
||||||
m_reading(FALSE), m_writing(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_unread(NULL), m_unrd_size(0), m_unrd_cur(0),
|
||||||
m_cbk(NULL), m_cdata(NULL)
|
m_cbk(NULL), m_cdata(NULL)
|
||||||
{
|
{
|
||||||
@@ -113,33 +115,45 @@ wxSocketBase::wxSocketBase() :
|
|||||||
|
|
||||||
wxSocketBase::~wxSocketBase()
|
wxSocketBase::~wxSocketBase()
|
||||||
{
|
{
|
||||||
if (m_unread)
|
// Just in case the app called Destroy() *and* then deleted
|
||||||
free(m_unread);
|
// the socket immediately: don't leave dangling pointers.
|
||||||
|
#if wxUSE_GUI
|
||||||
|
wxPendingDelete.DeleteObject(this);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Shutdown and close the socket
|
// Shutdown and close the socket
|
||||||
|
if (!m_beingDeleted)
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
// Destroy the GSocket object
|
// Destroy the GSocket object
|
||||||
if (m_socket)
|
if (m_socket)
|
||||||
GSocket_destroy(m_socket);
|
GSocket_destroy(m_socket);
|
||||||
|
|
||||||
|
// Free the pushback buffer
|
||||||
|
if (m_unread)
|
||||||
|
free(m_unread);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
bool wxSocketBase::Destroy()
|
bool wxSocketBase::Destroy()
|
||||||
{
|
{
|
||||||
// Delayed destruction: the socket will be deleted during the next
|
// Delayed destruction: the socket will be deleted during the next
|
||||||
// idle loop iteration. This ensures that all pending events have
|
// idle loop iteration. This ensures that all pending events have
|
||||||
// been processed.
|
// been processed.
|
||||||
|
|
||||||
m_beingDeleted = TRUE;
|
m_beingDeleted = TRUE;
|
||||||
|
|
||||||
|
// Shutdown and close the socket
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
if ( !wxPendingDelete.Member(this) )
|
#if wxUSE_GUI
|
||||||
|
if ( wxPendingDelete.Member(this) )
|
||||||
wxPendingDelete.Append(this);
|
wxPendingDelete.Append(this);
|
||||||
|
#else
|
||||||
|
delete this;
|
||||||
|
#endif
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------
|
// --------------------------------------------------------------------------
|
||||||
// Basic IO operations
|
// Basic IO operations
|
||||||
|
Reference in New Issue
Block a user