Reworked outgoing messages to optimize for pre-serialized case.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Thu, 25 Jan 2007 02:37:01 +0000 (02:37 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Thu, 25 Jan 2007 02:37:01 +0000 (02:37 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2143 cb58f699-b61c-0410-a6fe-9272a202ed29

shibsp/remoting/ListenerService.h
shibsp/remoting/impl/ListenerService.cpp
shibsp/remoting/impl/SocketListener.cpp

index fe88d53..3a9ed9d 100644 (file)
@@ -47,9 +47,9 @@ namespace shibsp {
          * 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)
@@ -83,7 +83,7 @@ namespace shibsp {
          */
         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.
index c33086c..9261662 100644 (file)
@@ -82,18 +82,19 @@ Remoted* ListenerService::lookup(const char *address) const
     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);
 }
index f32fc45..864e5cb 100644 (file)
@@ -446,8 +446,7 @@ bool ServerThread::job()
 {
     Category& log = Category::getInstance("shibd.Listener");
 
-    DDF out;
-    DDFJanitor jout(out);
+    ostringstream sink;
 #ifdef WIN32
     u_long len;
 #else
@@ -480,29 +479,33 @@ bool ServerThread::job()
         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)) {