Пример #1
0
void ExtensionRunnerCore::startServer(TProcessorRef processor) {
  {
    boost::lock_guard<boost::mutex> lock(service_start_);
    // A request to stop the service may occur before the thread starts.
    if (service_stopping_) {
      return;
    }

    transport_ = TServerTransportRef(new TServerSocket(path_));
    // Before starting and after stopping the manager, remove stale sockets.
    removeStalePaths(path_);

    // Construct the service's transport, protocol, thread pool.
    auto transport_fac = TTransportFactoryRef(new TBufferedTransportFactory());
    auto protocol_fac = TProtocolFactoryRef(new TBinaryProtocolFactory());

    // Start the Thrift server's run loop.
    server_ = TThreadedServerRef(new TThreadedServer(
        processor, transport_, transport_fac, protocol_fac));
  }

  {
    boost::lock_guard<boost::mutex> lock(service_run_);
    server_->serve();
  }
}
Пример #2
0
void ExtensionRunnerCore::startServer(TProcessorRef processor) {
  auto transport = TServerTransportRef(new TServerSocket(path_));
  // Before starting and after stopping the manager, remove stale sockets.
  removeStalePaths(path_);

  auto transport_fac = TTransportFactoryRef(new TBufferedTransportFactory());
  auto protocol_fac = TProtocolFactoryRef(new TBinaryProtocolFactory());

  // The minimum number of worker threads is 1.
  size_t threads = (FLAGS_worker_threads > 0) ? FLAGS_worker_threads : 1;
  manager_ = ThreadManager::newSimpleThreadManager(threads, 0);
  auto thread_fac = ThriftThreadFactory(new PosixThreadFactory());
  manager_->threadFactory(thread_fac);
  manager_->start();

  // Start the Thrift server's run loop.
  server_ = TThreadPoolServerRef(new TThreadPoolServer(
      processor, transport, transport_fac, protocol_fac, manager_));
  server_->serve();
}