Fixed a memory leak in wxTCPServer
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@6894 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -48,6 +48,7 @@ class WXDLLEXPORT wxClientBase;
|
||||
class WXDLLEXPORT wxConnectionBase: public wxObject
|
||||
{
|
||||
DECLARE_CLASS(wxConnectionBase)
|
||||
|
||||
public:
|
||||
inline wxConnectionBase(void) {}
|
||||
inline ~wxConnectionBase(void) {}
|
||||
@@ -102,8 +103,7 @@ class WXDLLEXPORT wxConnectionBase: public wxObject
|
||||
wxIPCFormat WXUNUSED(format) )
|
||||
{ return FALSE; };
|
||||
|
||||
// Callbacks to BOTH
|
||||
|
||||
// Callbacks to BOTH - override at will
|
||||
// Default behaviour is to delete connection and return TRUE
|
||||
virtual bool OnDisconnect(void) = 0;
|
||||
};
|
||||
@@ -111,28 +111,35 @@ class WXDLLEXPORT wxConnectionBase: public wxObject
|
||||
class WXDLLEXPORT wxServerBase: public wxObject
|
||||
{
|
||||
DECLARE_CLASS(wxServerBase)
|
||||
public:
|
||||
|
||||
public:
|
||||
inline wxServerBase(void) {}
|
||||
inline ~wxServerBase(void) {};
|
||||
virtual bool Create(const wxString& serverName) = 0; // Returns FALSE if can't create server (e.g. port
|
||||
// number is already in use)
|
||||
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) = 0;
|
||||
|
||||
// Returns FALSE on error (e.g. port number is already in use)
|
||||
virtual bool Create(const wxString& serverName) = 0;
|
||||
|
||||
// Callbacks to SERVER - override at will
|
||||
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic) = 0;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxClientBase: public wxObject
|
||||
{
|
||||
DECLARE_CLASS(wxClientBase)
|
||||
|
||||
public:
|
||||
inline wxClientBase(void) {};
|
||||
inline ~wxClientBase(void) {};
|
||||
virtual bool ValidHost(const wxString& host) = 0;
|
||||
virtual wxConnectionBase *MakeConnection(const wxString& host, const wxString& server, const wxString& topic) = 0;
|
||||
// Call this to make a connection.
|
||||
// Returns NULL if cannot.
|
||||
virtual wxConnectionBase *OnMakeConnection(void) = 0; // Tailor this to return own connection.
|
||||
|
||||
virtual bool ValidHost(const wxString& host) = 0;
|
||||
|
||||
// Call this to make a connection. Returns NULL if cannot.
|
||||
virtual wxConnectionBase *MakeConnection(const wxString& host,
|
||||
const wxString& server,
|
||||
const wxString& topic) = 0;
|
||||
|
||||
// Callbacks to CLIENT - override at will
|
||||
virtual wxConnectionBase *OnMakeConnection(void) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@@ -59,6 +59,7 @@ class WXDLLEXPORT wxTCPClient;
|
||||
class WXDLLEXPORT wxTCPConnection: public wxConnectionBase
|
||||
{
|
||||
DECLARE_DYNAMIC_CLASS(wxTCPConnection)
|
||||
|
||||
public:
|
||||
wxTCPConnection(char *buffer, int size);
|
||||
wxTCPConnection();
|
||||
@@ -77,10 +78,11 @@ public:
|
||||
// Calls that both can make
|
||||
virtual bool Disconnect(void);
|
||||
|
||||
// Callbacks to BOTH - override at will
|
||||
// Default behaviour is to delete connection and return TRUE
|
||||
virtual bool OnDisconnect(void) { delete this; return TRUE; }
|
||||
|
||||
// To enable the compressor
|
||||
// To enable the compressor (NOTE: not implemented!)
|
||||
void Compress(bool on);
|
||||
|
||||
protected:
|
||||
@@ -112,9 +114,14 @@ public:
|
||||
wxTCPServer();
|
||||
virtual ~wxTCPServer();
|
||||
|
||||
// Returns FALSE if can't create server (e.g. port number is already in use)
|
||||
virtual bool Create(const wxString& server_name);
|
||||
// Returns FALSE on error (e.g. port number is already in use)
|
||||
virtual bool Create(const wxString& serverName);
|
||||
|
||||
// Callbacks to SERVER - override at will
|
||||
virtual wxConnectionBase *OnAcceptConnection(const wxString& topic);
|
||||
|
||||
protected:
|
||||
wxSocketServer *m_server;
|
||||
};
|
||||
|
||||
class wxTCPClient: public wxClientBase
|
||||
@@ -126,13 +133,13 @@ public:
|
||||
virtual ~wxTCPClient();
|
||||
|
||||
virtual bool ValidHost(const wxString& host);
|
||||
// Call this to make a connection.
|
||||
// Returns NULL if cannot.
|
||||
|
||||
// Call this to make a connection. Returns NULL if cannot.
|
||||
virtual wxConnectionBase *MakeConnection(const wxString& host,
|
||||
const wxString& server,
|
||||
const wxString& topic);
|
||||
|
||||
// Tailor this to return own connection.
|
||||
// Callbacks to CLIENT - override at will
|
||||
virtual wxConnectionBase *OnMakeConnection();
|
||||
};
|
||||
|
||||
|
@@ -200,28 +200,51 @@ wxConnectionBase *wxTCPClient::OnMakeConnection()
|
||||
|
||||
wxTCPServer::wxTCPServer () : wxServerBase()
|
||||
{
|
||||
m_server = NULL;
|
||||
}
|
||||
|
||||
bool wxTCPServer::Create(const wxString& server_name)
|
||||
bool wxTCPServer::Create(const wxString& serverName)
|
||||
{
|
||||
wxSocketServer *server;
|
||||
// Destroy previous server, if any
|
||||
if (m_server)
|
||||
{
|
||||
m_server->SetClientData(NULL);
|
||||
m_server->Destroy();
|
||||
m_server = NULL;
|
||||
}
|
||||
|
||||
// wxIPV4address defaults to INADDR_ANY:0
|
||||
wxIPV4address addr;
|
||||
addr.Service(server_name);
|
||||
addr.Service(serverName);
|
||||
|
||||
// Create a socket listening on specified port
|
||||
server = new wxSocketServer(addr, SCKIPC_FLAGS);
|
||||
server->SetEventHandler(*gs_handler, _SERVER_ONREQUEST_ID);
|
||||
server->SetClientData(this);
|
||||
server->SetNotify(wxSOCKET_CONNECTION_FLAG);
|
||||
server->Notify(TRUE);
|
||||
// Create a socket listening on the specified port
|
||||
m_server = new wxSocketServer(addr, SCKIPC_FLAGS);
|
||||
|
||||
if (m_server->Ok())
|
||||
{
|
||||
m_server->SetEventHandler(*gs_handler, _SERVER_ONREQUEST_ID);
|
||||
m_server->SetClientData(this);
|
||||
m_server->SetNotify(wxSOCKET_CONNECTION_FLAG);
|
||||
m_server->Notify(TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_server->Destroy();
|
||||
m_server = NULL;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
wxTCPServer::~wxTCPServer()
|
||||
{
|
||||
if (m_server)
|
||||
{
|
||||
m_server->SetClientData(NULL);
|
||||
m_server->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
wxConnectionBase *wxTCPServer::OnAcceptConnection( const wxString& WXUNUSED(topic) )
|
||||
@@ -555,7 +578,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
|
||||
void wxTCPEventHandler::Server_OnRequest(wxSocketEvent &event)
|
||||
{
|
||||
wxSocketServer *server = (wxSocketServer *) event.GetSocket();
|
||||
wxTCPServer *ipcserv = (wxTCPServer *) event.GetClientData();
|
||||
wxTCPServer *ipcserv = (wxTCPServer *) server->GetClientData();
|
||||
|
||||
// This socket is being deleted; skip this event
|
||||
if (!ipcserv)
|
||||
|
Reference in New Issue
Block a user