Applied patch [ 600051 ] DDE and TCP improvements and fixes

By Michael Fielding

As discussed on wx-dev. some fixes and improvements for Interprocess Communication (IPC), using DDE and TCP.

1. DDE buffers were using a global buffer
2. TCP buffers were allocated each time needed, and Request would have caused memory leaks had it been used.

Fixed these both by using a self-resizing buffer in wxConnectionBase. Changed samples and docs to reflect the improved (but backward compatible) internal buffer management. wxConnectionBase could (in future) use wxMemoryBuffer.

3. IPC sample had trouble closing, causing crash, when closing server using window X button.

Because it was (effectively) trying to delete a window in OnExit, when that window was already destroyed. Fixed by making IPCDialog and MyConnection remember if they'd destroyed each other. It's not elegant, but either the connection or the window could be deleted first.

4. Docs for wxDDE... and wxTCP... duplicated eachother, supposed to have same API. Some parts unclear.

Patch removes dde and tcp-specific files (including from tipc.tex and classes.tex), and explains how ipc.h selects for you which one to use based on platform. Some other misc clarifications.

6. Client sample was suffering apparent memory leak because of not deleting connection object, and had a hack in there to do that.

In fact this was due to the derived OnDisconnect not deleting itself, as it does in base class. Mentioned need to do it in docs, fixed sample so that it does.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16907 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2002-09-01 14:48:16 +00:00
parent 1affde0a6b
commit f010ad4812
16 changed files with 226 additions and 182 deletions

View File

@@ -57,7 +57,6 @@ END_EVENT_TABLE()
// global variables
// ----------------------------------------------------------------------------
char ipc_buffer[4000];
MyConnection *the_connection = NULL;
// ============================================================================
@@ -134,6 +133,9 @@ void MyFrame::OnListBoxClick(wxCommandEvent& WXUNUSED(event))
if (listBox)
{
wxString value = listBox->GetStringSelection();
/* Because the_connection only holds one connection, in this sample only
one connection can receive advise messages */
if (the_connection)
{
the_connection->Advise(IPC_ADVISE_NAME, (wxChar *)value.c_str());
@@ -161,6 +163,14 @@ IPCDialogBox::IPCDialogBox(wxWindow *parent, const wxString& title,
Fit();
}
IPCDialogBox::~IPCDialogBox( )
{
// wxWindows exit code destroys dialog before destroying the connection in
// OnExit, so make sure connection won't try to delete the dialog later.
if (m_connection)
m_connection->dialog = NULL;
}
void IPCDialogBox::OnQuit(wxCommandEvent& event)
{
m_connection->Disconnect();
@@ -174,7 +184,7 @@ void IPCDialogBox::OnQuit(wxCommandEvent& event)
wxConnectionBase *MyServer::OnAcceptConnection(const wxString& topic)
{
if ( topic == IPC_TOPIC )
return new MyConnection(ipc_buffer, WXSIZEOF(ipc_buffer));
return new MyConnection();
// unknown topic
return NULL;
@@ -184,8 +194,8 @@ wxConnectionBase *MyServer::OnAcceptConnection(const wxString& topic)
// MyConnection
// ----------------------------------------------------------------------------
MyConnection::MyConnection(char *buf, int size)
: wxConnection(buf, size)
MyConnection::MyConnection()
: wxConnection()
{
dialog = new IPCDialogBox(wxTheApp->GetTopWindow(), "Connection",
wxPoint(100, 100), wxSize(500, 500), this);
@@ -197,7 +207,11 @@ MyConnection::~MyConnection()
{
if (the_connection)
{
dialog->Destroy();
if (dialog)
{
dialog->m_connection = NULL;
dialog->Destroy();
}
the_connection = NULL;
}
}