X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/401eb3dec29c09b9afcc843842cba48b33a5089b..f8d791e0a41f1021a69c3d6320ee6934c0dd7f36:/src/common/sckipc.cpp?ds=inline diff --git a/src/common/sckipc.cpp b/src/common/sckipc.cpp index 634fbd6ee2..49e69e22b3 100644 --- a/src/common/sckipc.cpp +++ b/src/common/sckipc.cpp @@ -346,12 +346,18 @@ wxTCPConnection::wxTCPConnection () : wxConnectionBase() m_codeco = NULL; } -wxTCPConnection::wxTCPConnection(char * WXUNUSED(buffer), int WXUNUSED(size)) +wxTCPConnection::wxTCPConnection(wxChar *buffer, int size) + : wxConnectionBase(buffer, size) { + m_sock = NULL; + m_sockstrm = NULL; + m_codeci = NULL; + m_codeco = NULL; } wxTCPConnection::~wxTCPConnection () { + Disconnect(); wxDELETE(m_codeci); wxDELETE(m_codeco); wxDELETE(m_sockstrm); @@ -371,10 +377,13 @@ void wxTCPConnection::Compress(bool WXUNUSED(on)) // Calls that CLIENT can make. bool wxTCPConnection::Disconnect () { + if ( !GetConnected() ) + return TRUE; // Send the the disconnect message to the peer. m_codeco->Write8(IPC_DISCONNECT); m_sock->Notify(FALSE); m_sock->Close(); + SetConnected(false); return TRUE; } @@ -397,7 +406,7 @@ bool wxTCPConnection::Execute(const wxChar *data, int size, wxIPCFormat format) return TRUE; } -char *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat format) +wxChar *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat format) { if (!m_sock->IsConnected()) return NULL; @@ -415,10 +424,11 @@ char *wxTCPConnection::Request (const wxString& item, int *size, wxIPCFormat for else { size_t s; - char *data = NULL; s = m_codeci->Read32(); - data = new char[s]; + wxChar *data = GetBufferAtLeast( s ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in wxTCPConnection::Request") ); m_sockstrm->Read(data, s); if (size) @@ -546,35 +556,37 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event) { case IPC_EXECUTE: { - char *data; + wxChar *data; size_t size; wxIPCFormat format; format = (wxIPCFormat)codeci->Read8(); size = codeci->Read32(); - data = new char[size]; + data = connection->GetBufferAtLeast( size ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") ); sockstrm->Read(data, size); connection->OnExecute (topic_name, data, size, format); - delete [] data; break; } case IPC_ADVISE: { - char *data; + wxChar *data; size_t size; wxIPCFormat format; item = codeci->ReadString(); format = (wxIPCFormat)codeci->Read8(); size = codeci->Read32(); - data = new char[size]; + data = connection->GetBufferAtLeast( size ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") ); sockstrm->Read(data, size); connection->OnAdvise (topic_name, item, data, size, format); - delete [] data; break; } case IPC_ADVISE_START: @@ -610,13 +622,13 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event) item = codeci->ReadString(); format = (wxIPCFormat)codeci->Read8(); size = codeci->Read32(); - data = new wxChar[size]; + data = connection->GetBufferAtLeast( size ); + wxASSERT_MSG(data != NULL, + _T("Buffer too small in wxTCPEventHandler::Client_OnRequest") ); sockstrm->Read(data, size); connection->OnPoke (topic_name, item, data, size, format); - delete [] data; - break; } case IPC_REQUEST: @@ -627,14 +639,14 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event) format = (wxIPCFormat)codeci->Read8(); int user_size = -1; - char *user_data = connection->OnRequest (topic_name, item, &user_size, format); + wxChar *user_data = connection->OnRequest (topic_name, item, &user_size, format); if (user_data) { codeco->Write8(IPC_REQUEST_REPLY); if (user_size == -1) - user_size = strlen(user_data) + 1; // includes final NUL + user_size = wxStrlen(user_data) + 1; // includes final NUL codeco->Write32(user_size); sockstrm->Write(user_data, user_size); @@ -648,6 +660,7 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event) { sock->Notify(FALSE); sock->Close(); + connection->SetConnected(false); connection->OnDisconnect(); break; }