本文整理汇总了C++中SelectServer::Run方法的典型用法代码示例。如果您正苦于以下问题:C++ SelectServer::Run方法的具体用法?C++ SelectServer::Run怎么用?C++ SelectServer::Run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SelectServer
的用法示例。
在下文中一共展示了SelectServer::Run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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();
}
示例2: testRemoveWriteWhenReadable
/*
* Check that RemoveWriteDescriptor is reentrant.
* Similar to the case above, but this removes & deletes the descriptor from
* within the OnRead callback of the same descriptor.
*/
void SelectServerTest::testRemoveWriteWhenReadable() {
// Ownership is transferred to the SelectServer.
LoopbackDescriptor *loopback = new LoopbackDescriptor();
loopback->Init();
loopback->SetOnData(NewCallback(
this, &SelectServerTest::ReadDataAndRemove,
static_cast<ConnectedDescriptor*>(loopback)));
loopback->SetOnWritable(NewCallback(this, &SelectServerTest::NullHandler));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(loopback));
OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(loopback));
OLA_ASSERT_EQ(2, connected_read_descriptor_count->Get());
OLA_ASSERT_EQ(1, write_descriptor_count->Get());
OLA_ASSERT_EQ(0, read_descriptor_count->Get());
// Send some data to make this descriptor readable.
uint8_t data[] = {'a'};
loopback->Send(data, arraysize(data));
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());
}
示例3: main
/*
* Main.
*/
int main(int argc, char **argv) {
ola::AppInit(&argc, argv, "[ options ]", "Ja Rule Admin Tool");
auto_ptr<UID> controller_uid(UID::FromString(FLAGS_controller_uid));
if (!controller_uid.get()) {
OLA_WARN << "Invalid Controller UID: '" << FLAGS_controller_uid << "'";
exit(ola::EXIT_USAGE);
}
if (controller_uid->IsBroadcast()) {
OLA_WARN << "The controller UID should not be a broadcast UID";
exit(ola::EXIT_USAGE);
}
SelectServer ss;
WidgetManager widget_manager(*controller_uid);
InputHandler input_handler(&ss, *controller_uid, &widget_manager);
USBDeviceManager manager(
&ss, NewCallback(&widget_manager, &WidgetManager::WidgetEvent));
if (!manager.Start()) {
exit(ola::EXIT_UNAVAILABLE);
}
ss.Run();
return ola::EXIT_OK;
}
示例4: SocketServerClose
/**
* Generic method to test server initiated close
*/
void SocketTest::SocketServerClose(ConnectedDescriptor *socket,
ConnectedDescriptor *socket2) {
OLA_ASSERT_NOT_NULL(socket);
socket->SetOnData(ola::NewCallback(
this, &SocketTest::Receive,
static_cast<ConnectedDescriptor*>(socket)));
socket->SetOnClose(
ola::NewSingleCallback(this, &SocketTest::TerminateOnClose));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(socket));
OLA_ASSERT_TRUE(socket2);
socket2->SetOnData(ola::NewCallback(
this, &SocketTest::ReceiveSendAndClose,
static_cast<ConnectedDescriptor*>(socket2)));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(socket2));
ssize_t bytes_sent = socket->Send(
static_cast<const uint8_t*>(test_cstring),
sizeof(test_cstring));
OLA_ASSERT_EQ(static_cast<ssize_t>(sizeof(test_cstring)), bytes_sent);
m_ss->Run();
m_ss->RemoveReadDescriptor(socket);
m_ss->RemoveReadDescriptor(socket2);
delete socket2;
}
示例5: testIOQueueUDPSend
/*
* Test UDP sockets with an IOQueue work correctly.
* The client connects and the server sends some data. The client checks the
* data matches and then closes the connection.
*/
void SocketTest::testIOQueueUDPSend() {
IPV4SocketAddress socket_address(IPV4Address::Loopback(), 9010);
UDPSocket socket;
OLA_ASSERT_TRUE(socket.Init());
OLA_ASSERT_FALSE(socket.Init());
OLA_ASSERT_TRUE(socket.Bind(socket_address));
OLA_ASSERT_FALSE(socket.Bind(socket_address));
socket.SetOnData(
ola::NewCallback(this, &SocketTest::UDPReceiveAndSend, &socket));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&socket));
UDPSocket client_socket;
OLA_ASSERT_TRUE(client_socket.Init());
OLA_ASSERT_FALSE(client_socket.Init());
client_socket.SetOnData(
ola::NewCallback(
this, &SocketTest::UDPReceiveAndTerminate,
static_cast<UDPSocket*>(&client_socket)));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&client_socket));
IOQueue output;
output.Write(static_cast<const uint8_t*>(test_cstring), sizeof(test_cstring));
ssize_t bytes_sent = client_socket.SendTo(&output, socket_address);
OLA_ASSERT_EQ(static_cast<ssize_t>(sizeof(test_cstring)), bytes_sent);
m_ss->Run();
m_ss->RemoveReadDescriptor(&socket);
m_ss->RemoveReadDescriptor(&client_socket);
}
示例6: testPauseAndResume
/**
* Check pausing doesn't mark the channel as bad.
*/
void HealthCheckedConnectionTest::testPauseAndResume() {
MockHealthCheckedConnection connection(&socket,
&m_ss,
heartbeat_interval,
options,
&m_clock);
socket.SetOnData(
NewCallback(&connection, &MockHealthCheckedConnection::ReadData));
connection.Setup();
m_ss.AddReadDescriptor(&socket);
connection.Setup();
m_ss.RegisterSingleTimeout(
TimeInterval(1, 0),
NewSingleCallback(this,
&HealthCheckedConnectionTest::PauseReading,
&connection));
m_ss.RegisterSingleTimeout(
TimeInterval(3, 0),
NewSingleCallback(this,
&HealthCheckedConnectionTest::ResumeReading,
&connection));
m_ss.Run();
OLA_ASSERT_TRUE(connection.ChannelOk());
}
示例7: testTCPSocketServerClose
/*
* Test TCP sockets work correctly.
* The client connects and the server then sends some data and closes the
* connection.
*/
void SocketTest::testTCPSocketServerClose() {
IPV4SocketAddress socket_address(IPV4Address::Loopback(), 0);
ola::network::TCPSocketFactory socket_factory(
ola::NewCallback(this, &SocketTest::NewConnectionSendAndClose));
TCPAcceptingSocket socket(&socket_factory);
OLA_ASSERT_TRUE_MSG(socket.Listen(socket_address),
"Check for another instance of olad running");
OLA_ASSERT_FALSE(socket.Listen(socket_address));
GenericSocketAddress local_address = socket.GetLocalAddress();
OLA_ASSERT_EQ(static_cast<uint16_t>(AF_INET), local_address.Family());
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&socket));
// The client socket checks the response and terminates on close
TCPSocket *client_socket = TCPSocket::Connect(local_address);
OLA_ASSERT_NOT_NULL(client_socket);
client_socket->SetOnData(ola::NewCallback(
this, &SocketTest::Receive,
static_cast<ConnectedDescriptor*>(client_socket)));
client_socket->SetOnClose(
ola::NewSingleCallback(this, &SocketTest::TerminateOnClose));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(client_socket));
m_ss->Run();
m_ss->RemoveReadDescriptor(&socket);
m_ss->RemoveReadDescriptor(client_socket);
delete client_socket;
}
示例8: testRemoveOthersWhenWriteable
/*
* Check that we don't invalid iterators by removing descriptors during an
* on_Write callback.
*/
void SelectServerTest::testRemoveOthersWhenWriteable() {
Descriptors read_set, write_set, delete_set;
LoopbackDescriptor loopback1, loopback2, loopback3;
loopback1.Init();
loopback2.Init();
loopback3.Init();
OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback1));
OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback2));
OLA_ASSERT_TRUE(m_ss->AddWriteDescriptor(&loopback3));
write_set.insert(&loopback1);
write_set.insert(&loopback2);
write_set.insert(&loopback3);
loopback1.SetOnWritable(NewCallback(
this, &SelectServerTest::NullHandler));
loopback2.SetOnWritable(NewCallback(
this,
&SelectServerTest::RemoveAndDeleteDescriptors,
read_set, write_set, delete_set));
loopback3.SetOnWritable(NewCallback(
this, &SelectServerTest::NullHandler));
OLA_ASSERT_EQ(3, write_descriptor_count->Get());
OLA_ASSERT_EQ(1, connected_read_descriptor_count->Get());
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());
}
示例9: testNonBlockingConnect
/*
* Test non-blocking TCP connects work correctly.
*/
void TCPConnectorTest::testNonBlockingConnect() {
ola::network::TCPSocketFactory socket_factory(
ola::NewCallback(this, &TCPConnectorTest::AcceptedConnection));
TCPAcceptingSocket listening_socket(&socket_factory);
IPV4SocketAddress listen_address(m_localhost, 0);
OLA_ASSERT_TRUE_MSG(listening_socket.Listen(listen_address),
"Failed to listen");
GenericSocketAddress addr = listening_socket.GetLocalAddress();
OLA_ASSERT_TRUE(addr.IsValid());
// calling listen a second time should fail
OLA_ASSERT_FALSE(listening_socket.Listen(listen_address));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&listening_socket));
// now attempt a non-blocking connect
// because we're connecting to the localhost this may run this callback
// immediately.
TCPConnector connector(m_ss);
TimeInterval connect_timeout(0, CONNECT_TIMEOUT_IN_MS * 1000);
TCPConnector::TCPConnectionID id = connector.Connect(
addr.V4Addr(),
connect_timeout,
ola::NewSingleCallback(this, &TCPConnectorTest::OnConnect));
OLA_ASSERT_TRUE(id);
m_ss->Run();
OLA_ASSERT_EQ(0u, connector.ConnectionsPending());
m_ss->RemoveReadDescriptor(&listening_socket);
}
示例10: testRemoveOthersWhenReadable
/*
* Check that we don't invalid iterators by removing descriptors during an
* on_read callback.
*/
void SelectServerTest::testRemoveOthersWhenReadable() {
Descriptors read_set, write_set, delete_set;
LoopbackDescriptor loopback1, loopback2, loopback3;
loopback1.Init();
loopback2.Init();
loopback3.Init();
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback1));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback2));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&loopback3));
read_set.insert(&loopback1);
read_set.insert(&loopback2);
read_set.insert(&loopback3);
loopback2.SetOnClose(NewSingleCallback(
this,
&SelectServerTest::RemoveAndDeleteDescriptors,
read_set, write_set, delete_set));
OLA_ASSERT_EQ(0, write_descriptor_count->Get());
OLA_ASSERT_EQ(4, connected_read_descriptor_count->Get());
loopback2.CloseClient();
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());
}
示例11: main
/*
* Startup the server.
*/
int main(int argc, char *argv[]) {
std::ostringstream help_msg;
help_msg <<
"The OLA SLP client.\n"
"\n"
"Examples:\n"
" " << argv[0] << " register service:myserv.x://myhost.com\n"
" " << argv[0] << " findsrvs service:myserv.x\n"
" " << argv[0] << " findsrvs service:myserv.x";
ola::AppInit(&argc, argv, "[options] command-and-arguments", help_msg.str());
vector<string> args;
for (int i = 1; i < argc; i++) {
args.push_back(argv[i]);
}
auto_ptr<Command> command(CreateCommand(args));
if (!command.get()) {
ola::DisplayUsage();
exit(ola::EXIT_OK);
}
ola::slp::SLPClientWrapper client_wrapper;
if (!client_wrapper.Setup())
exit(1);
SelectServer *ss = client_wrapper.GetSelectServer();
command->SetTermination(NewCallback(ss, &SelectServer::Terminate));
if (!command->Execute(client_wrapper.GetClient()))
exit(1);
ss->Run();
}
示例12: testUDPSocket
/*
* Test UDP sockets work correctly.
* The client connects and the server sends some data. The client checks the
* data matches and then closes the connection.
*/
void SocketTest::testUDPSocket() {
IPV4SocketAddress socket_address(IPV4Address::Loopback(), 0);
UDPSocket socket;
OLA_ASSERT_TRUE(socket.Init());
OLA_ASSERT_FALSE(socket.Init());
OLA_ASSERT_TRUE(socket.Bind(socket_address));
OLA_ASSERT_FALSE(socket.Bind(socket_address));
IPV4SocketAddress local_address;
OLA_ASSERT_TRUE(socket.GetSocketAddress(&local_address));
OLA_ASSERT_EQ(static_cast<uint16_t>(AF_INET), local_address.Family());
socket.SetOnData(
ola::NewCallback(this, &SocketTest::UDPReceiveAndSend, &socket));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&socket));
UDPSocket client_socket;
OLA_ASSERT_TRUE(client_socket.Init());
OLA_ASSERT_FALSE(client_socket.Init());
client_socket.SetOnData(
ola::NewCallback(
this, &SocketTest::UDPReceiveAndTerminate,
static_cast<UDPSocket*>(&client_socket)));
OLA_ASSERT_TRUE(m_ss->AddReadDescriptor(&client_socket));
ssize_t bytes_sent = client_socket.SendTo(
static_cast<const uint8_t*>(test_cstring),
sizeof(test_cstring),
local_address);
OLA_ASSERT_EQ(static_cast<ssize_t>(sizeof(test_cstring)), bytes_sent);
m_ss->Run();
m_ss->RemoveReadDescriptor(&socket);
m_ss->RemoveReadDescriptor(&client_socket);
}
示例13: testSameThreadCallback
/**
* Check that a callback from the SelectServer thread executes.
*/
void SelectServerThreadTest::testSameThreadCallback() {
TestThread test_thread(&m_ss, ola::thread::Thread::Self());
m_ss.Execute(
ola::NewSingleCallback(&test_thread, &TestThread::TestCallback));
OLA_ASSERT_FALSE(test_thread.CallbackRun());
m_ss.Run();
OLA_ASSERT_TRUE(test_thread.CallbackRun());
}
示例14: testDifferentThreadCallback
/*
* Check that a callback from a different thread is executed in the
* SelectServer thread.
*/
void SelectServerThreadTest::testDifferentThreadCallback() {
TestThread test_thread(&m_ss, ola::thread::Thread::Self());
test_thread.Start();
OLA_ASSERT_FALSE(test_thread.CallbackRun());
m_ss.Run();
test_thread.Join();
OLA_ASSERT_TRUE(test_thread.CallbackRun());
}
示例15: testFailedEcho
/*
* Check that method that fail return correctly
*/
void RpcChannelTest::testFailedEcho() {
m_request.set_data("foo");
m_stub->FailedEcho(
&m_controller,
&m_request,
&m_reply,
NewSingleCallback(this, &RpcChannelTest::FailedEchoComplete));
m_ss.Run();
}