本文整理汇总了C++中IOService::run方法的典型用法代码示例。如果您正苦于以下问题:C++ IOService::run方法的具体用法?C++ IOService::run怎么用?C++ IOService::run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IOService
的用法示例。
在下文中一共展示了IOService::run方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printf
TEST_F(RPCTest, test_30_client_shutdown_halfway) {
IOService service;
printf("%d\n", test_port);
test_count = 10000;
min_success = std::numeric_limits<int>::max();
max_success = -1;
EchoServer::Ptr server = EchoServer::create<EchoServer>(&service, "127.0.0.1", test_port);
server->bind_and_listen();
Thread* run_thrs[12];
for (int i = 0; i < 12; i++) {
run_thrs[i] = new Thread([&service](){service.run(); LOG_DEBUG("run thread exiting");});
}
Thread* client_thrs[30];
for (int i = 0; i < 30; i++) {
client_thrs[i] = new Thread(std::bind(client_thread));
}
sleep(1);
server->shutdown();
server.reset();
for (int i = 0; i < 30; i++) {
client_thrs[i]->join();
delete client_thrs[i];
}
for (int i = 0; i < 12; i++) {
run_thrs[i]->join();
delete run_thrs[i];
}
LOG_INFO("min %d max %d", min_success, max_success);
}
示例2: main
int main(int argc, char* argv[])
{
string server_address;
short server_port;
int num_of_robot;
int login_opt = 0;
GetParam(server_address, server_port, num_of_robot, login_opt);
IOService io;
for (int i = 0; i < num_of_robot; i++)
{
std::shared_ptr<LogicClient> robot = std::make_shared<LogicClient>(&io, i);
//RobotsManager::GetInstance().AddRobot(robot);
robot->SetServAddress(server_address, server_port);
robot->ConnectToServer();
sleep(1);
}
io.run();
return 0;
}
示例3: context
TEST_F(RPCTest, base_rpcclient) {
IOService service;
EchoServer::Ptr server = EchoServer::create<EchoServer>(&service, "127.0.0.1", test_port);
server->bind_and_listen();
BaseRPCClient::Ptr client = BaseRPCClient::create<BaseRPCClient>(&service, "127.0.0.1", test_port);
bool done = false;
Context::Ptr context(new Context());
context->request.set_size(sizeof(int));
*(reinterpret_cast<int*>(context->request.content_ptr())) = 0x01020304;
LOG_DEBUG("%p", context.get());
client->async_request(context, [client, context, &done](const BaseRPCClient::ClientResult& cr) {
EXPECT_EQ((int)cr, BaseRPCClient::ClientResult::SUCCESS);
LOG_DEBUG("%p", context.get());
EXPECT_EQ(context->response.content_length(), sizeof(int));
int c = *(reinterpret_cast<const int*>(context->response.content_ptr()));
EXPECT_EQ(c, 0x01020304);
done = true;
stop_server();
client->shutdown();
});
service.run();
EXPECT_EQ(done, true);
}