当前位置: 首页>>代码示例>>C++>>正文


C++ TEventBase::tryRunAfterDelay方法代码示例

本文整理汇总了C++中TEventBase::tryRunAfterDelay方法的典型用法代码示例。如果您正苦于以下问题:C++ TEventBase::tryRunAfterDelay方法的具体用法?C++ TEventBase::tryRunAfterDelay怎么用?C++ TEventBase::tryRunAfterDelay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TEventBase的用法示例。


在下文中一共展示了TEventBase::tryRunAfterDelay方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sst

TEST(ThriftServer, CallbackOrderingTest) {
  apache::thrift::TestThriftServerFactory<TestInterface> factory;
  auto server = factory.create();
  auto serverHandler = std::make_shared<TestServerEventHandler>();


  TProcessorBase::addProcessorEventHandlerFactory(serverHandler);
  server->setServerEventHandler(serverHandler);

  ScopedServerThread sst(server);
  TEventBase base;
  std::shared_ptr<TAsyncSocket> socket(
    TAsyncSocket::newSocket(&base, *sst.getAddress()));

  TestServiceAsyncClient client(
    std::unique_ptr<HeaderClientChannel,
                    apache::thrift::async::TDelayedDestruction::Destructor>(
                      new HeaderClientChannel(socket)));

  client.noResponse([](ClientReceiveState&& state){}, 10000);
  base.tryRunAfterDelay([&](){
    socket->closeNow();
  }, 1);
  base.tryRunAfterDelay([&](){
    base.terminateLoopSoon();
  }, 20);
  base.loopForever();
  serverHandler->check();
  TProcessorBase::removeProcessorEventHandlerFactory(serverHandler);
}
开发者ID:nemith,项目名称:fbthrift,代码行数:30,代码来源:ThriftServerTest.cpp

示例2: runTest

void runTest(std::function<void(HeaderClientChannel* channel)> setup) {
  ScopedServerThread sst(getServer());
  TEventBase base;
  auto channel = getClientChannel(&base, *sst.getAddress());
  setup(channel.get());
  TestServiceAsyncClient client(std::move(channel));
  Countdown c(3, [&base](){base.terminateLoopSoon();});

  client.sendResponse([&base,&client,&c](ClientReceiveState&& state) {
    EXPECT_FALSE(state.isException());
    EXPECT_TRUE(state.isSecurityActive());
    std::string res;
    try {
      TestServiceAsyncClient::recv_sendResponse(res, state);
    } catch(const std::exception&) {
      EXPECT_TRUE(false);
    }
    EXPECT_EQ(res, "10");
    c.down();
  }, 10);


  // fail on time out
  base.tryRunAfterDelay([] {EXPECT_TRUE(false);}, 5000);

  base.tryRunAfterDelay([&client,&base,&c] {
    client.sendResponse([&base,&c](ClientReceiveState&& state) {
      EXPECT_FALSE(state.isException());
      EXPECT_TRUE(state.isSecurityActive());
      std::string res;
      try {
        TestServiceAsyncClient::recv_sendResponse(res, state);
      } catch(const std::exception&) {
        EXPECT_TRUE(false);
      }
      EXPECT_EQ(res, "10");
      c.down();
    }, 10);
    client.sendResponse([&base,&c](ClientReceiveState&& state) {
      EXPECT_FALSE(state.isException());
      EXPECT_TRUE(state.isSecurityActive());
      std::string res;
      try {
        TestServiceAsyncClient::recv_sendResponse(res, state);
      } catch(const std::exception&) {
        EXPECT_TRUE(false);
      }
      EXPECT_EQ(res, "10");
      c.down();
    }, 10);
  }, 1);

  base.loopForever();
}
开发者ID:andrianyablonskyy,项目名称:fbthrift,代码行数:54,代码来源:SecurityTest.cpp

示例3: sst

TEST(Duplex, DuplexTest) {
  enum {START=1, COUNT=10, INTERVAL=5};
  ScopedServerThread sst(getServer());
  TEventBase base;

  std::shared_ptr<TAsyncSocket> socket(
    TAsyncSocket::newSocket(&base, *sst.getAddress()));

  auto duplexChannel =
     std::make_shared<DuplexChannel>(DuplexChannel::Who::CLIENT, socket);
  DuplexServiceAsyncClient client(duplexChannel->getClientChannel());

  bool success = false;
  ThriftServer clients_server(duplexChannel->getServerChannel());
  clients_server.setInterface(std::make_shared<DuplexClientInterface>(
      START, COUNT, success));
  clients_server.serve();

  client.registerForUpdates([](ClientReceiveState&& state) {
    EXPECT_FALSE(state.isException());
    bool res = DuplexServiceAsyncClient::recv_registerForUpdates(state);
    EXPECT_TRUE(res);
  }, START, COUNT, INTERVAL);

  // fail on time out
  base.tryRunAfterDelay([] {EXPECT_TRUE(false);}, 5000);

  base.loopForever();

  EXPECT_TRUE(success);
}
开发者ID:LonelyPale,项目名称:fbthrift,代码行数:31,代码来源:DuplexTest.cpp

示例4: sst

TEST(ThriftServer, IdleTimeoutAfterTest) {
  ScopedServerThread sst(getServer());

  TEventBase base;

  std::shared_ptr<TAsyncSocket> socket(
    TAsyncSocket::newSocket(&base, *sst.getAddress()));

  auto client_channel = HeaderClientChannel::newChannel(socket);
  auto client_channelp = client_channel.get();
  CloseChecker checker;

  client_channel->setCloseCallback(&checker);
  TestServiceAsyncClient client(std::move(client_channel));
  std::string ret;
  client.sync_sendResponse(ret, 20);

  EXPECT_FALSE(checker.getClosed());

  base.tryRunAfterDelay([&base](){
      base.terminateLoopSoon();
    }, 200);
  base.loopForever();
  EXPECT_TRUE(checker.getClosed());
  client_channelp->setCloseCallback(nullptr);
}
开发者ID:LonelyPale,项目名称:fbthrift,代码行数:26,代码来源:Cpp2TimeoutTest.cpp

示例5: duplexTest

void duplexTest(const apache::thrift::SecurityMech mech) {
  enum {START=1, COUNT=3, INTERVAL=1};
  ScopedServerThread duplexsst(getDuplexServer());
  TEventBase base;
  std::shared_ptr<TAsyncSocket> socket(
    TAsyncSocket::newSocket(&base, *duplexsst.getAddress()));

  auto duplexChannel =
      std::make_shared<DuplexChannel>(DuplexChannel::Who::CLIENT, socket);
  enableSecurity(duplexChannel->getClientChannel().get(), mech);
  DuplexServiceAsyncClient client(duplexChannel->getClientChannel());

  bool success = false;
  ThriftServer clients_server(duplexChannel->getServerChannel());
  clients_server.setInterface(std::make_shared<DuplexClientInterface>(
      START, COUNT, success));
  clients_server.serve();

  client.registerForUpdates([](ClientReceiveState&& state) {
    EXPECT_FALSE(state.isException());
    EXPECT_TRUE(state.isSecurityActive());
    try {
      bool res = DuplexServiceAsyncClient::recv_registerForUpdates(state);
      EXPECT_TRUE(res);
    } catch (const std::exception&) {
      EXPECT_TRUE(false);
    }
  }, START, COUNT, INTERVAL);

  // fail on time out
  base.tryRunAfterDelay([] {EXPECT_TRUE(false);}, 5000);

  base.loopForever();

  EXPECT_TRUE(success);
}
开发者ID:andrianyablonskyy,项目名称:fbthrift,代码行数:36,代码来源:SecurityTest.cpp


注:本文中的TEventBase::tryRunAfterDelay方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。