Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1558

Named Pipe and Anonymous Pipe transport for Windows

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 0.9
    • None
    • C++ - Library
    • Microsoft Windows / Visual Studio

    • Patch Available

    Description

      This patch adds named & anonymous pipe transport for Windows. The new classes do not affect *NIX builds. We've been using this code on Windows & OSX for 6 months and I'm fairly confident in it. It has not been hammered by automated tests and I welcome stress testing to wring out any bugs.

      The TPipe and TPipeServer classes are generally modeled after TSocket and TSocketServer. The server of course uses TPipeServer to set up the server side then instantiates TPipe for communications. The client instantiates TPipe transport for connection to the server.

      Here are some code snippet examples from functions we've built. Variables such as 'pipename' are passed in to the functions. Error handling has been omitted.

      //-----------------------------------------------------------------------
      // ---- Server ----
      //-----------------------------------------------------------------------
      #ifdef _WIN32
      pipename = "\\\\.\\pipe
      " + pipename;
      boost::shared_ptr<TServerTransport> transport(new TPipeServer(pipename, 1024, NumThreads)); //Named pipe
      #else //Mac, *NIX
      unlink(pipename.c_str());
      boost::shared_ptr<TServerTransport> transport(new TServerSocket(pipename));
      #endif

      boost::shared_ptr<TServer> server;
      boost::shared_ptr<MyHandler> handler(new MyHandler());
      boost::shared_ptr<TProcessor> processor(new MyProcessor(handler));
      boost::shared_ptr<TTransportFactory> tfactory(new TBufferedTransportFactory());
      boost::shared_ptr<TProtocolFactory> pfactory(new TBinaryProtocolFactory());

      if(NumThreads <= 1)

      { //Single-threaded server server.reset(new TSimpleServer(processor, transport, tfactory, pfactory)); }

      else

      { //Multi-threaded server boost::shared_ptr<ThreadManager> threadManager = ThreadManager::newSimpleThreadManager(NumThreads); boost::shared_ptr<PlatformThreadFactory> threadFactory = boost::shared_ptr<PlatformThreadFactory>(new PlatformThreadFactory()); threadManager->threadFactory(threadFactory); threadManager->start(); server.reset(new TThreadPoolServer(processor, transport, tfactory, pfactory, threadManager)); }

      printf("Starting the 'server'...\n");
      server->serve();
      printf("done.\n");

      //-----------------------------------------------------------------------
      // ---- Client ----
      //-----------------------------------------------------------------------
      #ifdef _WIN32
      pipename = "\\\\.\\pipe
      " + pipename;
      boost::shared_ptr<TTransport> pipe(new TPipe(pipename));
      transport.reset(new TBufferedTransport(pipe));
      #else //Mac, *nix
      boost::shared_ptr<TTransport> socket(new TSocket(pipename));
      transport.reset(new TBufferedTransport(socket));
      #endif
      boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

      client.reset(new MyClient(protocol));

      Attachments

        1. AnonPipe.patch
          0.5 kB
          Peace C
        2. Pipe_snippets.cpp
          2 kB
          Peace C
        3. Thrift_Named_Pipe_Transport_Windows.patch
          26 kB
          Peace C
        4. Thrift_transport_sample.patch
          55 kB
          Peace C
        5. Thrift-1558_xplatform_pipe_6-5-2012.patch
          27 kB
          Peace C

        Activity

          People

            roger Roger Meier
            peace Peace C
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: