stricter reply code checking: verify that we get the expected reply, not just that we don't get IPC_FAIL

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56817 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-11-17 11:08:38 +00:00
parent e536b75069
commit d730bd8a68

View File

@@ -53,20 +53,22 @@
namespace
{
// Message codes
// Message codes (don't change them to avoid breaking the existing code using
// wxIPC protocol!)
enum IPCCode
{
IPC_EXECUTE = 1,
IPC_REQUEST,
IPC_POKE,
IPC_ADVISE_START,
IPC_ADVISE_REQUEST,
IPC_ADVISE,
IPC_ADVISE_STOP,
IPC_REQUEST_REPLY,
IPC_FAIL,
IPC_CONNECT,
IPC_DISCONNECT
IPC_EXECUTE = 1,
IPC_REQUEST = 2,
IPC_POKE = 3,
IPC_ADVISE_START = 4,
IPC_ADVISE_REQUEST = 5,
IPC_ADVISE = 6,
IPC_ADVISE_STOP = 7,
IPC_REQUEST_REPLY = 8,
IPC_FAIL = 9,
IPC_CONNECT = 10,
IPC_DISCONNECT = 11,
IPC_MAX
};
} // anonymous namespace
@@ -576,8 +578,8 @@ const void *wxTCPConnection::Request(const wxString& item,
IPCOutput(m_streams).Write(IPC_REQUEST, item, format);
int ret = m_streams->Read8();
if ( ret == IPC_FAIL )
const int ret = m_streams->Read8();
if ( ret != IPC_REQUEST_REPLY )
return NULL;
return m_streams->ReadData(this, size);
@@ -605,11 +607,9 @@ bool wxTCPConnection::StartAdvise(const wxString& item)
IPCOutput(m_streams).Write(IPC_ADVISE_START, item);
int ret = m_streams->Read8();
if (ret != IPC_FAIL)
return true;
else
return false;
const int ret = m_streams->Read8();
return ret == IPC_ADVISE_START;
}
bool wxTCPConnection::StopAdvise (const wxString& item)
@@ -619,12 +619,9 @@ bool wxTCPConnection::StopAdvise (const wxString& item)
IPCOutput(m_streams).Write(IPC_ADVISE_STOP, item);
int ret = m_streams->Read8();
const int ret = m_streams->Read8();
if (ret != IPC_FAIL)
return true;
else
return false;
return ret == IPC_ADVISE_STOP;
}
// Calls that SERVER can make
@@ -797,6 +794,11 @@ void wxTCPEventHandler::Client_OnRequest(wxSocketEvent &event)
connection->OnDisconnect();
break;
case IPC_FAIL:
wxLogDebug("Unexpected IPC_FAIL received");
error = true;
break;
default:
wxLogDebug("Unknown message code %d received.", msg);
error = true;