X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/26a25f9523218117ab718b684ff514ad420b5aee..008a56c968ed7e0694e32e93c2dbf95dde2ba5c8:/src/common/sckipc.cpp diff --git a/src/common/sckipc.cpp b/src/common/sckipc.cpp index 372c1d627e..4151df7172 100644 --- a/src/common/sckipc.cpp +++ b/src/common/sckipc.cpp @@ -260,7 +260,7 @@ bool wxTCPServer::Create(const wxString& serverName) { // ensure that the file doesn't exist as otherwise calling socket() would // fail - int rc = remove(serverName); + int rc = remove(serverName.fn_str()); if ( rc < 0 && errno != ENOENT ) { delete addr; @@ -321,7 +321,7 @@ wxTCPServer::~wxTCPServer() #ifdef __UNIX_LIKE__ if ( !m_filename.empty() ) { - if ( !remove(m_filename) ) + if ( remove(m_filename.fn_str()) != 0 ) { wxLogDebug(_T("Stale AF_UNIX file '%s' left."), m_filename.c_str()); } @@ -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; }