| | |
| | | |
| | | auto Client = [&](const std::string &topic, const int nreq) { |
| | | SocketRequest client(shm); |
| | | std::atomic<int> count(0); |
| | | std::string reply; |
| | | auto onRecv = [&](const std::string &rep) { |
| | | reply = rep; |
| | | if (++count >= nreq) { |
| | | printf("count: %d\n", count.load()); |
| | | } |
| | | }; |
| | | client.StartWorker(onRecv, 1); |
| | | boost::timer::auto_cpu_timer timer; |
| | | for (int i = 0; i < nreq; ++i) { |
| | | if (!client.SyncRequest(topic, "data " + std::to_string(i), reply, 1000)) { |
| | | if (!client.AsyncRequest(topic, "data " + std::to_string(i), 1000)) { |
| | | printf("client request failed\n"); |
| | | } |
| | | // if (!client.SyncRequest(topic, "data " + std::to_string(i), reply, 1000)) { |
| | | // printf("client request failed\n"); |
| | | // } else { |
| | | // ++count; |
| | | // } |
| | | } |
| | | printf("request %s %d done ", topic.c_str(), nreq); |
| | | while (count.load() < nreq) { |
| | | std::this_thread::yield(); |
| | | } |
| | | client.Stop(); |
| | | }; |
| | | auto Server = [&](const std::string &name, const std::vector<std::string> &topics) { |
| | | SocketReply server(shm); |
| | |
| | | servers.Launch(Server, "server", topics); |
| | | std::this_thread::sleep_for(100ms); |
| | | for (auto &t : topics) { |
| | | clients.Launch(Client, t, 1000 * 100); |
| | | clients.Launch(Client, t, 1000 * 1000); |
| | | } |
| | | clients.WaitAll(); |
| | | run = false; |