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


C++ SelectServer类代码示例

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


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

示例1: SelectServer

/*
 * Setup the select server
 */
void AdvancedTCPConnectorTest::setUp() {
  m_tcp_socket_factory.reset(new ola::network::TCPSocketFactory(
      ola::NewCallback(this, &AdvancedTCPConnectorTest::OnConnect)));
  m_connected_socket = NULL;
  ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR);

  m_ss = new SelectServer(NULL, &m_clock);
  m_timeout_id = m_ss->RegisterSingleTimeout(
        ABORT_TIMEOUT_IN_MS,
        ola::NewSingleCallback(this, &AdvancedTCPConnectorTest::Timeout));
  OLA_ASSERT_TRUE(m_timeout_id);
}
开发者ID:basileus,项目名称:ola,代码行数:15,代码来源:AdvancedTCPConnectorTest.cpp

示例2: LoopbackDescriptor

/*
 * Check that RemoveWriteDescriptor is reentrant.
 * We use the Execute() method to close a write descriptor during the same
 * cycle in which it becomes writeable. See
 * https://github.com/OpenLightingProject/ola/pull/429 for details.
 */
void SelectServerTest::testRemoveWriteWhenOtherReadable() {
  Descriptors read_set, write_set, delete_set;
  LoopbackDescriptor *loopback = new LoopbackDescriptor();
  loopback->Init();
  loopback->SetOnWritable(NewCallback(this, &SelectServerTest::NullHandler));

  write_set.insert(loopback);
  delete_set.insert(loopback);

  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(loopback));
  OLA_ASSERT_EQ(1, write_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  m_ss->Execute(NewSingleCallback(
      this, &SelectServerTest::RemoveAndDeleteDescriptors,
      read_set, write_set, delete_set));

  m_ss->Run();
  OLA_ASSERT_EQ(0, write_descriptor_count->Get());
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
}
开发者ID:Jurrie,项目名称:ola,代码行数:27,代码来源:SelectServerTest.cpp

示例3: SelectServer

/*
 * Setup the select server
 */
void SocketTest::setUp() {
  m_ss = new SelectServer();
  m_timeout_closure = ola::NewSingleCallback(this, &SocketTest::Timeout);
  OLA_ASSERT_TRUE(m_ss->RegisterSingleTimeout(ABORT_TIMEOUT_IN_MS,
                                              m_timeout_closure));

#if _WIN32
  WSADATA wsa_data;
  int result = WSAStartup(MAKEWORD(2, 0), &wsa_data);
  OLA_ASSERT_EQ(result, 0);
#endif  // _WIN32
}
开发者ID:Keeper-of-the-Keys,项目名称:ola,代码行数:15,代码来源:SocketTest.cpp

示例4: testDoubleAddAndRemove

/*
 * Confirm we can't add the same descriptor twice.
 */
void SelectServerTest::testDoubleAddAndRemove() {
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());  // internal socket
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, write_descriptor_count->Get());

  LoopbackDescriptor loopback_socket;
  loopback_socket.Init();

  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback_socket));
  OLA_ASSERT_EQ(2, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, write_descriptor_count->Get());

  OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback_socket));
  OLA_ASSERT_EQ(2, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  OLA_ASSERT_EQ(1, write_descriptor_count->Get());

  m_ss->RemoveReadDescriptor(&loopback_socket);
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  OLA_ASSERT_EQ(1, write_descriptor_count->Get());

  m_ss->RemoveWriteDescriptor(&loopback_socket);
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, write_descriptor_count->Get());

  // Trying to remove a second time shouldn't crash
  m_ss->RemoveReadDescriptor(&loopback_socket);
  m_ss->RemoveWriteDescriptor(&loopback_socket);
}
开发者ID:queenvictoria,项目名称:ola,代码行数:35,代码来源:SelectServerTest.cpp

示例5: testRemoteEndClose

/*
 * Confirm we correctly detect the remote end closing the connection.
 */
void SelectServerTest::testRemoteEndClose() {
  Descriptors read_set, write_set, delete_set;
  LoopbackDescriptor loopback;
  loopback.Init();

  read_set.insert(&loopback);

  loopback.SetOnClose(NewSingleCallback(
      this, &SelectServerTest::RemoveAndDeleteDescriptors,
      read_set, write_set, delete_set));

  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback));
  OLA_ASSERT_EQ(2, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());

  // now the Write end closes
  loopback.CloseClient();

  m_ss->Run();
  OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
  OLA_ASSERT_EQ(0, read_descriptor_count->Get());
}
开发者ID:Jurrie,项目名称:ola,代码行数:25,代码来源:SelectServerTest.cpp

示例6: CPPUNIT_ASSERT

/*
 * Setup the select server
 */
void AdvancedTCPConnectorTest::setUp() {
  m_tcp_socket_factory.reset(new ola::network::TCPSocketFactory(
      ola::NewCallback(this, &AdvancedTCPConnectorTest::OnConnect)));
  m_connected_socket = NULL;
  ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR);

  string localhost_str = "127.0.0.1";
  CPPUNIT_ASSERT(IPV4Address::FromString(localhost_str, &m_localhost));

  m_ss = new SelectServer(NULL, &m_clock);
  m_timeout_id = m_ss->RegisterSingleTimeout(
        ABORT_TIMEOUT_IN_MS,
        ola::NewSingleCallback(this, &AdvancedTCPConnectorTest::Timeout));
  CPPUNIT_ASSERT(m_timeout_id);
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:18,代码来源:AdvancedTCPConnectorTest.cpp

示例7: testAddRemoveReadDescriptor

/*
 * Check AddReadDescriptor/RemoveReadDescriptor works correctly and that the
 * export map is updated.
 */
void SelectServerTest::testAddRemoveReadDescriptor() {
  LoopbackDescriptor bad_socket;
  IntegerVariable *connected_socket_count =
    m_map->GetIntegerVar(PollerInterface::K_CONNECTED_DESCRIPTORS_VAR);
  IntegerVariable *socket_count =
    m_map->GetIntegerVar(PollerInterface::K_READ_DESCRIPTOR_VAR);
  OLA_ASSERT_EQ(1, connected_socket_count->Get());  // internal socket
  OLA_ASSERT_EQ(0, socket_count->Get());
  // adding and removin a non-connected socket should fail
  OLA_ASSERT_FALSE(m_ss->AddReadDescriptor(&bad_socket));
  OLA_ASSERT_FALSE(m_ss->RemoveReadDescriptor(&bad_socket));

  LoopbackDescriptor loopback_socket;
  loopback_socket.Init();
  OLA_ASSERT_EQ(1, connected_socket_count->Get());
  OLA_ASSERT_EQ(0, socket_count->Get());
  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback_socket));
  // Adding a second time should fail
  OLA_ASSERT_FALSE(m_ss->AddReadDescriptor(&loopback_socket));
  OLA_ASSERT_EQ(2, connected_socket_count->Get());
  OLA_ASSERT_EQ(0, socket_count->Get());

  // Add a udp socket
  UDPSocket udp_socket;
  OLA_ASSERT_TRUE(udp_socket.Init());
  OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&udp_socket));
  OLA_ASSERT_FALSE(m_ss->AddReadDescriptor(&udp_socket));
  OLA_ASSERT_EQ(2, connected_socket_count->Get());
  OLA_ASSERT_EQ(1, socket_count->Get());

  // Check remove works
  OLA_ASSERT_TRUE(m_ss->RemoveReadDescriptor(&loopback_socket));
  OLA_ASSERT_EQ(1, connected_socket_count->Get());
  OLA_ASSERT_EQ(1, socket_count->Get());
  OLA_ASSERT_TRUE(m_ss->RemoveReadDescriptor(&udp_socket));
  OLA_ASSERT_EQ(1, connected_socket_count->Get());
  OLA_ASSERT_EQ(0, socket_count->Get());

  // Remove again should fail
  OLA_ASSERT_FALSE(m_ss->RemoveReadDescriptor(&loopback_socket));
}
开发者ID:basileus,项目名称:ola,代码行数:45,代码来源:SelectServerTest.cpp

示例8: SelectServer

/*
 * Setup the select server
 */
void AdvancedTCPConnectorTest::setUp() {
  m_tcp_socket_factory.reset(new ola::network::TCPSocketFactory(
      ola::NewCallback(this, &AdvancedTCPConnectorTest::OnConnect)));
  m_connected_socket = NULL;

  m_ss = new SelectServer(NULL, &m_clock);
  m_timeout_id = m_ss->RegisterSingleTimeout(
        ABORT_TIMEOUT_IN_MS,
        ola::NewSingleCallback(this, &AdvancedTCPConnectorTest::Timeout));
  OLA_ASSERT_TRUE(m_timeout_id);

#if _WIN32
  WSADATA wsa_data;
  int result = WSAStartup(MAKEWORD(2, 0), &wsa_data);
  OLA_ASSERT_EQ(result, 0);
#endif
}
开发者ID:Jurrie,项目名称:ola,代码行数:20,代码来源:AdvancedTCPConnectorTest.cpp

示例9: AcceptedConnection

/*
 * Accept a new TCP connection.
 */
void AdvancedTCPConnectorTest::AcceptedConnection(TCPSocket *new_socket) {
  OLA_ASSERT_NOT_NULL(new_socket);
  GenericSocketAddress address = new_socket->GetPeerAddress();
  OLA_ASSERT_TRUE(address.Family() == AF_INET);
  OLA_INFO << "Connection from " << address;

  // terminate the ss when this connection is closed
  new_socket->SetOnClose(
    ola::NewSingleCallback(this, &AdvancedTCPConnectorTest::TerminateOnClose));
  m_ss->AddReadDescriptor(new_socket, true);
}
开发者ID:basileus,项目名称:ola,代码行数:14,代码来源:AdvancedTCPConnectorTest.cpp

示例10: AcceptedConnection

/*
 * Accept a new TCP connection.
 */
void AdvancedTCPConnectorTest::AcceptedConnection(TcpSocket *new_socket) {
  CPPUNIT_ASSERT(new_socket);
  IPV4Address address;
  uint16_t port;
  CPPUNIT_ASSERT(new_socket->GetPeer(&address, &port));
  OLA_INFO << "Connection from " << address << ":" << port;

  // terminate the ss when this connection is closed
  new_socket->SetOnClose(
    ola::NewSingleCallback(this, &AdvancedTCPConnectorTest::TerminateOnClose));
  m_ss->AddReadDescriptor(new_socket, true);
}
开发者ID:huyanming,项目名称:open-lighting,代码行数:15,代码来源:AdvancedTCPConnectorTest.cpp

示例11: DeviceDisconnected

void LogicReader::DeviceDisconnected(U64 device) {
  OLA_FATAL << "Device " << device << " disconnected";

  MutexLocker lock(&m_mu);
  if (device != m_device_id) {
    return;
  }
  m_device_id = 0;
  m_logic = NULL;

  m_ss->Terminate();
}
开发者ID:FloEdelmann,项目名称:ola,代码行数:12,代码来源:logic-rdm-sniffer.cpp

示例12: UDPReceiveAndTerminate

/*
 * Receive some data and check it.
 */
void SocketTest::UDPReceiveAndTerminate(UDPSocket *socket) {
  IPV4Address expected_address;
  OLA_ASSERT_TRUE(IPV4Address::FromString("127.0.0.1", &expected_address));

  IPV4SocketAddress source;

  uint8_t buffer[sizeof(test_cstring) + 10];
  ssize_t data_read = sizeof(buffer);
  socket->RecvFrom(buffer, &data_read, &source);
  OLA_ASSERT_EQ(static_cast<ssize_t>(sizeof(test_cstring)), data_read);
  OLA_ASSERT_EQ(expected_address, source.Host());
  m_ss->Terminate();
}
开发者ID:Keeper-of-the-Keys,项目名称:ola,代码行数:16,代码来源:SocketTest.cpp

示例13: SocketClosed

 void SocketClosed(TCPSocket *socket) {
   OLA_INFO << "Socket @ " << socket << " was closed";
   vector<TCPSocket*>::iterator iter = m_sockets.begin();
   for (; iter != m_sockets.end(); ++iter) {
     if (*iter == socket) {
       m_ss.RemoveReadDescriptor(socket);
       socket->Close();
       delete socket;
       m_sockets.erase(iter);
       break;
     }
   }
 }
开发者ID:nomis52,项目名称:glowing-wookie,代码行数:13,代码来源:master.cpp

示例14: NewConnectionSend

/*
 * Accept a new connection and send some test data
 */
void SocketTest::NewConnectionSend(TCPSocket *new_socket) {
  OLA_ASSERT_TRUE(new_socket);
  GenericSocketAddress address = new_socket->GetPeerAddress();
  OLA_ASSERT_TRUE(address.Family() == AF_INET);
  OLA_INFO << "Connection from " << address;
  ssize_t bytes_sent = new_socket->Send(
      static_cast<const uint8_t*>(test_cstring),
      sizeof(test_cstring));
  OLA_ASSERT_EQ(static_cast<ssize_t>(sizeof(test_cstring)), bytes_sent);
  new_socket->SetOnClose(ola::NewSingleCallback(this,
                                               &SocketTest::TerminateOnClose));
  m_ss->AddReadDescriptor(new_socket, true);
}
开发者ID:Keeper-of-the-Keys,项目名称:ola,代码行数:16,代码来源:SocketTest.cpp

示例15: main

/*
 * Main
 */
int main(int argc, char *argv[]) {
  ola::InitLogging(ola::OLA_LOG_INFO, ola::OLA_LOG_STDERR);

  udp_socket.SetOnData(ola::NewCallback(&SocketReady));
  if (!udp_socket.Init()) {
    OLA_WARN << "Failed to init";
    return 1;
  }
  if (!udp_socket.Bind(6038)) {
    OLA_WARN << "Failed to bind";
    return 1;
  }
  if (!udp_socket.EnableBroadcast()) {
    OLA_WARN << "Failed to enabl bcast";
    return 1;
  }

  ss.AddSocket(&udp_socket);

  ss.Run();
  return 0;
}
开发者ID:Jazeido,项目名称:ola,代码行数:25,代码来源:kinet.cpp


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