| | |
| | | BHCenter center(shm); |
| | | center.Start(); |
| | | |
| | | std::this_thread::sleep_for(100ms); |
| | | Sleep(100ms); |
| | | |
| | | std::atomic<uint64_t> total_count(0); |
| | | std::atomic<ptime> last_time(Now() - seconds(1)); |
| | |
| | | for (auto &t : topics) { |
| | | tlist.add_topic_list(t); |
| | | } |
| | | bool r = client.Subscribe(tlist, timeout); |
| | | MsgCommonReply reply_body; |
| | | bool r = client.Subscribe(tlist, reply_body, timeout); |
| | | if (!r) { |
| | | printf("client subscribe failed.\n"); |
| | | } |
| | |
| | | MsgPublish pub; |
| | | pub.set_topic(topic); |
| | | pub.set_data(data); |
| | | bool r = provider.Publish(pub, timeout); |
| | | bool r = provider.Publish(pub, 0); |
| | | if (!r) { |
| | | static std::atomic<int> an(0); |
| | | int n = ++an; |
| | |
| | | part.push_back(topics[i]); |
| | | threads.Launch(Sub, i, topics); |
| | | } |
| | | std::this_thread::sleep_for(100ms); |
| | | Sleep(100ms); |
| | | for (auto &topic : topics) { |
| | | threads.Launch(Pub, topic); |
| | | } |
| | |
| | | |
| | | std::atomic<int> count(0); |
| | | std::string reply; |
| | | auto onRecv = [&](const std::string &proc_id, const MsgRequestTopicReply &msg) { |
| | | auto onRecv = [&](const BHMsgHead &head, const MsgRequestTopicReply &msg) { |
| | | reply = msg.data(); |
| | | if (++count >= nreq) { |
| | | printf("count: %d\n", count.load()); |
| | |
| | | MsgRequestTopic req; |
| | | req.set_topic(topic); |
| | | req.set_data("data " + std::to_string(i)); |
| | | if (!client.ClientAsyncRequest(req)) { |
| | | std::string msg_id; |
| | | if (!client.ClientAsyncRequest(req, msg_id)) { |
| | | printf("client request failed\n"); |
| | | ++count; |
| | | } |
| | |
| | | ThreadManager clients, servers; |
| | | std::vector<Topic> topics = {"topic1", "topic2"}; |
| | | servers.Launch(Server, "server", topics); |
| | | std::this_thread::sleep_for(100ms); |
| | | Sleep(100ms); |
| | | for (auto &t : topics) { |
| | | clients.Launch(Client, t, 1000 * 1); |
| | | clients.Launch(Client, t, 1000 * 100); |
| | | } |
| | | clients.WaitAll(); |
| | | printf("clients done, server replyed: %ld\n", server_msg_count.load()); |
| | |
| | | }; |
| | | Check(); |
| | | for (int i = 0; i < 3; ++i) { |
| | | std::this_thread::sleep_for(1s); |
| | | Sleep(1s); |
| | | Check(); |
| | | } |
| | | printf("sleep 4\n"); |
| | | std::this_thread::sleep_for(4s); |
| | | Sleep(4s); |
| | | for (int i = 0; i < 2; ++i) { |
| | | std::this_thread::sleep_for(1s); |
| | | Sleep(1s); |
| | | Check(); |
| | | } |
| | | } |
| | | printf("sleep 8\n"); |
| | | std::this_thread::sleep_for(8s); |
| | | Sleep(8s); |
| | | } |
| | | inline int MyMin(int a, int b) |
| | | { |