* Remoted classes implement this method to process incoming messages.
*
* @param in incoming DDF message
- * @return DDF message response
+ * @param out stream to write outgoing DDF message to
*/
- virtual DDF receive(const DDF& in)=0;
+ virtual void receive(const DDF& in, std::ostream& out)=0;
};
#if defined (_MSC_VER)
*/
virtual DDF send(const DDF& in)=0;
- virtual DDF receive(const DDF& in);
+ virtual void receive(const DDF& in, std::ostream& out);
// Remoted classes register and unregister for messages using these methods.
// Registration returns any existing listeners, allowing message hooking.
return (i==m_listenerMap.end()) ? NULL : i->second;
}
-DDF ListenerService::receive(const DDF &in)
+void ListenerService::receive(const DDF &in, ostream& out)
{
if (!in.name())
throw ListenerException("Incoming message with no destination address rejected.");
else if (!strcmp("ping",in.name())) {
- DDF out=DDF(NULL).integer(in.integer() + 1);
- return out;
+ DDF outmsg=DDF(NULL).integer(in.integer() + 1);
+ DDFJanitor jan(outmsg);
+ out << outmsg;
}
Remoted* dest=lookup(in.name());
if (!dest)
throw ListenerException("No destination registered for incoming message addressed to ($1).",params(1,in.name()));
- return dest->receive(in);
+ dest->receive(in, out);
}
{
Category& log = Category::getInstance("shibd.Listener");
- DDF out;
- DDFJanitor jout(out);
+ ostringstream sink;
#ifdef WIN32
u_long len;
#else
is >> in;
// Dispatch the message.
- out=m_listener->receive(in);
+ m_listener->receive(in, sink);
}
catch (XMLToolingException& e) {
log.error("error processing incoming message: %s", e.what());
- out=DDF("exception").string(e.toString().c_str());
+ DDF out=DDF("exception").string(e.toString().c_str());
+ DDFJanitor jout(out);
+ sink << out;
}
catch (exception& e) {
log.error("error processing incoming message: %s", e.what());
ListenerException ex(e.what());
- out=DDF("exception").string(ex.toString().c_str());
+ DDF out=DDF("exception").string(ex.toString().c_str());
+ DDFJanitor jout(out);
+ sink << out;
}
#ifndef _DEBUG
catch (...) {
log.error("unexpected error processing incoming message");
ListenerException ex("An unexpected error occurred while processing an incoming message.");
- out=DDF("exception").string(ex.toString().c_str());
+ DDF out=DDF("exception").string(ex.toString().c_str());
+ DDFJanitor jout(out);
+ sink << out;
}
#endif
// Return whatever's available.
- ostringstream xmlout;
- xmlout << out;
- string response(xmlout.str());
+ string response(sink.str());
int outlen = response.length();
len = htonl(outlen);
if (m_listener->send(m_sock,(char*)&len,sizeof(len)) != sizeof(len)) {