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

@@ -30,7 +30,6 @@
// Settings common to both executables: determines whether
// we're using TCP/IP or real DDE.
#include "ddesetup.h"
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
@@ -56,7 +55,6 @@ END_EVENT_TABLE()
// globals
// ----------------------------------------------------------------------------
char ipc_buffer[4000];
wxListBox *the_list = NULL;
MyConnection *the_connection = NULL;
@@ -119,16 +117,11 @@ bool MyApp::OnInit()
int MyApp::OnExit()
{
if (the_connection)
{
the_connection->Disconnect();
delete the_connection;
the_connection = NULL;
}
// will delete the connection too
// Update: Seems it didn't delete the_connection, because there's a leak.
// Deletion is now explicitly done a few lines up.
// another Update: in fact it's because OnDisconnect should delete it, but
// it wasn't
delete my_client;
@@ -203,11 +196,6 @@ wxConnectionBase *MyClient::OnMakeConnection()
return new MyConnection;
}
MyConnection::MyConnection()
: wxConnection(ipc_buffer, WXSIZEOF(ipc_buffer))
{
}
bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, char *data, int size, wxIPCFormat format)
{
if (the_list)
@@ -221,10 +209,13 @@ bool MyConnection::OnAdvise(const wxString& topic, const wxString& item, char *d
bool MyConnection::OnDisconnect()
{
// when connection is terminated, quit whole program
wxWindow *win = wxTheApp->GetTopWindow();
if ( win )
win->Destroy();
return TRUE;
// delete self
the_connection = NULL;
return wxConnection::OnDisconnect();
}