More boosification of thrift driver, server, transport and protocol code

Modified TestServer to use thread-pool manager 


	


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664737 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/transport/TBufferedTransport.h b/lib/cpp/src/transport/TBufferedTransport.h
index b8153fe..922754e 100644
--- a/lib/cpp/src/transport/TBufferedTransport.h
+++ b/lib/cpp/src/transport/TBufferedTransport.h
@@ -1,11 +1,15 @@
 #ifndef T_BUFFERED_TRANSPORT_H
 #define T_BUFFERED_TRANSPORT_H
 
-#include "transport/TTransport.h"
+#include <transport/TTransport.h>
 #include <string>
 
+#include <boost/shared_ptr.hpp>
+
 namespace facebook { namespace thrift { namespace transport { 
 
+using namespace boost;
+
 /**
  * Buffered transport. For reads it will read more data than is requested
  * and will serve future data out of a local buffer. For writes, data is
@@ -15,7 +19,7 @@
  */
 class TBufferedTransport : public TTransport {
  public:
-  TBufferedTransport(TTransport* transport) :
+  TBufferedTransport(shared_ptr<TTransport> transport) :
     transport_(transport),
     rBufSize_(512), rPos_(0), rLen_(0),
     wBufSize_(512), wLen_(0) {
@@ -23,7 +27,7 @@
     wBuf_ = new uint8_t[wBufSize_];
   }
 
-  TBufferedTransport(TTransport* transport, uint32_t sz) :
+  TBufferedTransport(shared_ptr<TTransport> transport, uint32_t sz) :
     transport_(transport),
     rBufSize_(sz), rPos_(0), rLen_(0),
     wBufSize_(sz), wLen_(0) {
@@ -31,7 +35,7 @@
     wBuf_ = new uint8_t[wBufSize_];
   }
 
-  TBufferedTransport(TTransport* transport, uint32_t rsz, uint32_t wsz) :
+  TBufferedTransport(shared_ptr<TTransport> transport, uint32_t rsz, uint32_t wsz) :
     transport_(transport),
     rBufSize_(rsz), rPos_(0), rLen_(0),
     wBufSize_(wsz), wLen_(0) {
@@ -67,7 +71,7 @@
   void flush();
 
  protected:
-  TTransport* transport_;
+  shared_ptr<TTransport> transport_;
   uint8_t* rBuf_;
   uint32_t rBufSize_;
   uint32_t rPos_;
diff --git a/lib/cpp/src/transport/TChunkedTransport.h b/lib/cpp/src/transport/TChunkedTransport.h
index 16f9e0e..0fe8d75 100644
--- a/lib/cpp/src/transport/TChunkedTransport.h
+++ b/lib/cpp/src/transport/TChunkedTransport.h
@@ -1,11 +1,14 @@
 #ifndef T_CHUNKED_TRANSPORT_H
 #define T_CHUNKED_TRANSPORT_H
 
-#include "transport/TTransport.h"
+#include <transport/TTransport.h>
 #include <string>
+#include <boost/shared_ptr.hpp>
 
 namespace facebook { namespace thrift { namespace transport { 
 
+using namespace boost;
+
 /**
  * Chunked transport. All writes go into an in-memory buffer until flush is
  * called, at which point the transport writes the length of the entire
@@ -16,7 +19,7 @@
  */
 class TChunkedTransport : public TTransport {
  public:
-  TChunkedTransport(TTransport* transport) :
+  TChunkedTransport(shared_ptr<TTransport> transport) :
     transport_(transport),
     rPos_(0), rLen_(0),
     wBufSize_(512), wLen_(0) {
@@ -24,7 +27,7 @@
     wBuf_ = new uint8_t[wBufSize_];
   }
 
-  TChunkedTransport(TTransport* transport, uint32_t sz) :
+  TChunkedTransport(shared_ptr<TTransport> transport, uint32_t sz) :
     transport_(transport),
     rPos_(0), rLen_(0),
     wBufSize_(sz), wLen_(0) {
@@ -60,7 +63,7 @@
   void flush();
 
  protected:
-  TTransport* transport_;
+  shared_ptr<TTransport> transport_;
   uint8_t* rBuf_;
   uint32_t rPos_;
   uint32_t rLen_;
diff --git a/lib/cpp/src/transport/TServerSocket.cc b/lib/cpp/src/transport/TServerSocket.cc
index 21230d9..003ddec 100644
--- a/lib/cpp/src/transport/TServerSocket.cc
+++ b/lib/cpp/src/transport/TServerSocket.cc
@@ -4,9 +4,12 @@
 
 #include "transport/TSocket.h"
 #include "transport/TServerSocket.h"
+#include <boost/shared_ptr.hpp>
 
 namespace facebook { namespace thrift { namespace transport { 
 
+using namespace boost;
+
 TServerSocket::TServerSocket(int port) :
   port_(port), serverSocket_(0), acceptBacklog_(1024) {}
 
@@ -64,7 +67,7 @@
   // The socket is now listening!
 }
 
-TTransport* TServerSocket::acceptImpl() {
+shared_ptr<TTransport> TServerSocket::acceptImpl() {
   if (serverSocket_ <= 0) {
     throw TTransportException(TTX_NOT_OPEN, "TServerSocket not listening");
   }
@@ -80,7 +83,7 @@
     throw TTransportException(TTX_UNKNOWN, "ERROR:" + errno);
   }
 
-  return new TSocket(clientSocket);
+  return shared_ptr<TTransport>(new TSocket(clientSocket));
 }
 
 void TServerSocket::close() {
diff --git a/lib/cpp/src/transport/TServerSocket.h b/lib/cpp/src/transport/TServerSocket.h
index c18a8d2..619a366 100644
--- a/lib/cpp/src/transport/TServerSocket.h
+++ b/lib/cpp/src/transport/TServerSocket.h
@@ -1,7 +1,8 @@
 #ifndef T_SERVER_SOCKET_H
 #define T_SERVER_SOCKET_H
 
-#include "transport/TServerTransport.h"
+#include <transport/TServerTransport.h>
+#include <boost/shared_ptr.hpp>
 
 namespace facebook { namespace thrift { namespace transport { 
 
@@ -22,7 +23,7 @@
   void close();
 
  protected:
-  TTransport* acceptImpl();
+  shared_ptr<TTransport> acceptImpl();
 
  private:
 
diff --git a/lib/cpp/src/transport/TServerTransport.h b/lib/cpp/src/transport/TServerTransport.h
index 9bf74d1..f51e88c 100644
--- a/lib/cpp/src/transport/TServerTransport.h
+++ b/lib/cpp/src/transport/TServerTransport.h
@@ -3,9 +3,12 @@
 
 #include "transport/TTransport.h"
 #include "transport/TTransportException.h"
+#include <boost/shared_ptr.hpp>
 
 namespace facebook { namespace thrift { namespace transport { 
 
+using namespace boost;
+
 /**
  * Server transport framework. A server needs to have some facility for
  * creating base transports to read/write from.
@@ -34,8 +37,8 @@
    * @return A new TTransport object
    * @throws TTransportException if there is an error
    */
-  TTransport* accept() {
-    TTransport* result = acceptImpl();
+  shared_ptr<TTransport> accept() {
+    shared_ptr<TTransport> result = acceptImpl();
     if (result == NULL) {
       throw TTransportException("accept() may not return NULL");
     }
@@ -56,7 +59,7 @@
    * @return A newly allocated TTransport object
    * @throw TTransportException If an error occurs
    */
-  virtual TTransport* acceptImpl() = 0;
+  virtual shared_ptr<TTransport> acceptImpl() = 0;
 
 };