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


C++ SelectServer::RemoveTimeout方法代码示例

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


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

示例1: testBackoff

/**
 * Test that backoff works.
 * This is quite brittle and should be fixed at some stage.
 */
void AdvancedTCPConnectorTest::testBackoff() {
  uint16_t port = ReservePort();
  OLA_ASSERT_NE(0, port);
  IPV4SocketAddress target(m_localhost, port);

  // we advance the clock so remove the timeout closure
  m_ss->RemoveTimeout(m_timeout_id);
  m_timeout_id = ola::thread::INVALID_TIMEOUT;

  AdvancedTCPConnector connector(
      m_ss,
      m_tcp_socket_factory.get(),
      TimeInterval(0, CONNECT_TIMEOUT_IN_MS * 1000));

  // 5s per attempt, up to a max of 30
  LinearBackoffPolicy policy(TimeInterval(5, 0), TimeInterval(30, 0));
  connector.AddEndpoint(target, &policy);
  OLA_ASSERT_EQ(1u, connector.EndpointCount());

  // failed_attempts may be 0 or 1, depending on the platform.
  AdvancedTCPConnector::ConnectionState state;
  unsigned int failed_attempts;
  connector.GetEndpointState(target, &state, &failed_attempts);

  OLA_ASSERT_EQ(AdvancedTCPConnector::DISCONNECTED, state);
  OLA_ASSERT_TRUE(failed_attempts == 0 || failed_attempts == 1);

  // the timeout is 500ms, so we advance by 490 and set a 200ms timeout
  m_clock.AdvanceTime(0, 490000);
  m_ss->RunOnce(TimeInterval(0, 200000));

  // should have one failure at this point
  ConfirmState(__LINE__, connector, target,
               AdvancedTCPConnector::DISCONNECTED, 1);

  // the next attempt should be in 5 seconds
  m_clock.AdvanceTime(4, 900000);
  m_ss->RunOnce(TimeInterval(1, 0));

  // wait for the timeout
  m_clock.AdvanceTime(0, 490000);
  m_ss->RunOnce(TimeInterval(0, 200000));

  ConfirmState(__LINE__, connector, target,
               AdvancedTCPConnector::DISCONNECTED, 2);

  // run once more to clean up
  m_ss->RunOnce(TimeInterval(0, 10000));

  // clean up
  connector.RemoveEndpoint(target);
  OLA_ASSERT_EQ(0u, connector.EndpointCount());
}
开发者ID:Jurrie,项目名称:ola,代码行数:57,代码来源:AdvancedTCPConnectorTest.cpp

示例2: testTimeout

/*
 * Timeout tests
 */
void SelectServerTest::testTimeout() {
  // Check a single timeout
  m_ss->RegisterSingleTimeout(
      10,
      ola::NewSingleCallback(this, &SelectServerTest::SingleIncrementTimeout));
  m_ss->RegisterSingleTimeout(
      20,
      ola::NewSingleCallback(this, &SelectServerTest::Terminate));
  m_ss->Run();
  OLA_ASSERT_EQ(1u, m_timeout_counter);

  // Now check a timeout that adds another timeout
  m_timeout_counter = 0;

  m_ss->RegisterSingleTimeout(
      10,
      ola::NewSingleCallback(this, &SelectServerTest::ReentrantTimeout, m_ss));
  m_ss->RegisterSingleTimeout(
      20,
      ola::NewSingleCallback(this, &SelectServerTest::Terminate));
  m_ss->Run();
  OLA_ASSERT_EQ(2u, m_timeout_counter);

  // Check repeating timeouts
  // Some systems (VMs in particular) can't do 10ms resolution so we go for
  // larger numbers here.
  m_timeout_counter = 0;
  m_ss->RegisterRepeatingTimeout(
      100,
      ola::NewCallback(this, &SelectServerTest::IncrementTimeout));
  m_ss->RegisterSingleTimeout(
      980,
      ola::NewSingleCallback(this, &SelectServerTest::Terminate));
  m_ss->Run();
  // This seems to go as low as 7
  std::ostringstream str;
  str << "Timeout counter was " << m_timeout_counter;
  OLA_ASSERT_TRUE_MSG(m_timeout_counter >= 5 && m_timeout_counter <= 9,
                      str.str());

  // Confirm timeouts are removed correctly
  ola::thread::timeout_id timeout1 = m_ss->RegisterSingleTimeout(
      10,
      ola::NewSingleCallback(this, &SelectServerTest::FatalTimeout));
  m_ss->RegisterSingleTimeout(
      20,
      ola::NewSingleCallback(this, &SelectServerTest::Terminate));
  m_ss->RemoveTimeout(timeout1);
  m_ss->Run();
}
开发者ID:queenvictoria,项目名称:ola,代码行数:53,代码来源:SelectServerTest.cpp

示例3: testBackoff

/**
 * Test that backoff works.
 * This is quite brittle and should be fixed at some stage.
 */
void AdvancedTCPConnectorTest::testBackoff() {
  // we advance the clock so remove the timeout closure
  m_ss->RemoveTimeout(m_timeout_id);
  m_timeout_id = ola::thread::INVALID_TIMEOUT;

  AdvancedTCPConnector connector(
      m_ss,
      m_tcp_socket_factory.get(),
      TimeInterval(0, CONNECT_TIMEOUT_IN_MS * 1000));

  // 5s per attempt, up to a max of 30
  LinearBackoffPolicy policy(TimeInterval(5, 0), TimeInterval(30, 0));
  connector.AddEndpoint(m_localhost, SERVER_PORT, &policy);
  CPPUNIT_ASSERT_EQUAL(1u, connector.EndpointCount());

  ConfirmState(__LINE__, connector, m_localhost, SERVER_PORT,
               AdvancedTCPConnector::DISCONNECTED, 0);

  // the timeout is 500ms, so we advance by 490 and set a 200ms timeout
  m_clock.AdvanceTime(0, 490000);
  m_ss->RunOnce(0, 200000);

  // should have one failure at this point
  ConfirmState(__LINE__, connector, m_localhost, SERVER_PORT,
               AdvancedTCPConnector::DISCONNECTED, 1);

  // the next attempt should be in 5 seconds
  m_clock.AdvanceTime(4, 900000);
  m_ss->RunOnce(1, 0);

  // wait for the timeout
  m_clock.AdvanceTime(0, 490000);
  m_ss->RunOnce(0, 200000);

  ConfirmState(__LINE__, connector, m_localhost, SERVER_PORT,
               AdvancedTCPConnector::DISCONNECTED, 2);

  // run once more to clean up
  m_ss->RunOnce(0, 10000);

  // clean up
  connector.RemoveEndpoint(m_localhost, SERVER_PORT);
  CPPUNIT_ASSERT_EQUAL(0u, connector.EndpointCount());
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:48,代码来源:AdvancedTCPConnectorTest.cpp


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