Guest User

Memory leak in apache thrift

a guest
Feb 25th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.59 KB | None | 0 0
  1. // This autogenerated skeleton file illustrates how to build a server.
  2. // You should copy it to another filename to avoid overwriting it.
  3.  
  4. #include "tagger.h"
  5. #include <thrift/protocol/TBinaryProtocol.h>
  6. #include <thrift/server/TSimpleServer.h>
  7. #include <thrift/transport/TServerSocket.h>
  8. #include <thrift/transport/TBufferTransports.h>
  9. #include <thrift/concurrency/ThreadManager.h>
  10. #include <thrift/concurrency/PosixThreadFactory.h>
  11. #include <thrift/server/TThreadPoolServer.h>
  12. #include <thrift/server/TNonblockingServer.h>
  13.  
  14. using namespace ::apache::thrift;
  15. using namespace ::apache::thrift::protocol;
  16. using namespace ::apache::thrift::transport;
  17. using namespace ::apache::thrift::server;
  18. using namespace ::apache::thrift::concurrency;
  19.  
  20. using boost::shared_ptr;
  21.  
  22. class taggerHandler : virtual public taggerIf {
  23. public:
  24.     taggerHandler() {
  25.         this->loadRes();
  26.         printf("server loaded\n");
  27.     // Your initialization goes here
  28.     }
  29.  
  30.     void tagText(std::string& _return, const std::string& text, const std::string& language) {
  31.         // Your implementation goes here
  32.         printf("tagText\n");
  33.         _return = "as";
  34.     }
  35.  
  36.     void manage(std::string& _return, const std::string& parmeters) {
  37.         // Your implementation goes here
  38.         printf("reload\n");
  39.         delete[] this->data;
  40.         this->loadRes();
  41.     }
  42.     private:
  43.         void loadRes() {
  44.             this->data = new char[10240000];
  45.         }
  46.         char *data;
  47.  
  48. };
  49.  
  50. int main(int argc, char **argv) {
  51.     int port = 9091;
  52.     shared_ptr<taggerHandler> handler(new taggerHandler());
  53.     shared_ptr<TProcessor> processor(new taggerProcessor(handler));
  54.     shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
  55.     shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
  56.     //shared_ptr<TProtocolFactory> protocolFactory(new TBufferedTransportFactory());
  57.     shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
  58.  
  59.     shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(15);
  60.     shared_ptr<PosixThreadFactory> threadFactory = shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
  61.     threadManager->threadFactory(threadFactory);
  62.     threadManager->start();
  63.  
  64.     //TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
  65.     //TThreadPoolServer server(processor, serverTransport, transportFactory, protocolFactory, threadManager);//, port, threadManager);
  66.     TNonblockingServer server(processor, protocolFactory, port, threadManager);
  67.     server.serve();
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment