Bugfix: Exception for invalid messages wasn't properly dealt with.

This commit is contained in:
Gunnar Beutner 2012-04-30 08:22:30 +02:00
parent 7e2b8d90a5
commit 7e4788720d
4 changed files with 12 additions and 16 deletions

View File

@ -27,7 +27,7 @@ ConfigObject::ConfigObject(const string& type, const string& name)
void ConfigObject::SetHive(const ConfigHive::WeakPtr& hive)
{
if (m_Hive.lock())
throw InvalidArgumentException();
throw InvalidArgumentException("Config object already has a parent hive.");
m_Hive = hive;
OnPropertyChanged += bind_weak(&ConfigObject::PropertyChangedHandler, shared_from_this());

View File

@ -76,7 +76,7 @@ bool Dictionary::GetPropertyDictionary(string key, Dictionary::Ptr *value)
dictionary = dynamic_pointer_cast<Dictionary>(data.GetObject());
if (dictionary == NULL)
throw InvalidArgumentException();
throw InvalidArgumentException("Property is not a dictionary.");
*value = dictionary;

View File

@ -128,7 +128,7 @@ void EndpointManager::SendMulticastRequest(Endpoint::Ptr sender, const JsonRpcRe
string method;
if (!request.GetMethod(&method))
throw InvalidArgumentException();
throw InvalidArgumentException("Message is missing the 'method' property.");
for (list<Endpoint::Ptr>::iterator i = m_Endpoints.begin(); i != m_Endpoints.end(); i++)
{

View File

@ -19,26 +19,22 @@ void JsonRpcClient::SendMessage(const Message& message)
int JsonRpcClient::DataAvailableHandler(const EventArgs& ea)
{
Message message;
bool message_read;
while (true) {
try {
message_read = Netstring::ReadMessageFromFIFO(GetRecvQueue(), &message);
Message message;
if (Netstring::ReadMessageFromFIFO(GetRecvQueue(), &message)) {
NewMessageEventArgs nea;
nea.Source = shared_from_this();
nea.Message = message;
OnNewMessage(nea);
}
} catch (const Exception& ex) {
cerr << "Exception while reading from JSON-RPC client: " << ex.GetMessage() << endl;
Application::Log("Exception while processing message from JSON-RPC client: " + ex.GetMessage());
Close();
return 1;
}
if (!message_read)
break;
NewMessageEventArgs nea;
nea.Source = shared_from_this();
nea.Message = message;
OnNewMessage(nea);
}
return 0;