THRIFT-928. cpp: Thrift Server Client Stats

Add the ability for Thrift servers to monitor client connections.  It is
activated by #including server/TClientInfo.h and creating 1) a
TClientInfoCallHandler passed to the processor with setEventHandler()
and 2) a TClientInforServerHandler passed to the server with
setServerEventHandler().

The result vector, showing active connections, provides client address
and the thrift call it is executing (or last executed), the time
connected, and the number of calls made since connection.

git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@1005139 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TSimpleServer.cpp b/lib/cpp/src/server/TSimpleServer.cpp
index 394ce21..438a587 100644
--- a/lib/cpp/src/server/TSimpleServer.cpp
+++ b/lib/cpp/src/server/TSimpleServer.cpp
@@ -63,13 +63,18 @@
       outputTransport = outputTransportFactory_->getTransport(client);
       inputProtocol = inputProtocolFactory_->getProtocol(inputTransport);
       outputProtocol = outputProtocolFactory_->getProtocol(outputTransport);
+      void* connectionContext = NULL;
       if (eventHandler_ != NULL) {
-        eventHandler_->clientBegin(inputProtocol, outputProtocol);
+        connectionContext = eventHandler_->createContext(inputProtocol, outputProtocol);
       }
       try {
-        while (processor_->process(inputProtocol, outputProtocol)) {
-          // Peek ahead, is the remote side closed?
-          if (!inputTransport->peek()) {
+        for (;;) {
+          if (eventHandler_ != NULL) {
+            eventHandler_->processContext(connectionContext, client);
+          }
+          if (!processor_->process(inputProtocol, outputProtocol, connectionContext) ||
+              // Peek ahead, is the remote side closed?
+              !inputProtocol->getTransport()->peek()) {
             break;
           }
         }
@@ -79,7 +84,7 @@
         cerr << "TSimpleServer exception: " << tx.what() << endl;
       }
       if (eventHandler_ != NULL) {
-        eventHandler_->clientEnd(inputProtocol, outputProtocol);
+        eventHandler_->deleteContext(connectionContext, inputProtocol, outputProtocol);
       }
       inputTransport->close();
       outputTransport->close();