From c64c54d8e75b9354dc49a7b6b2d326e7dd59eb37 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期四, 15 四月 2021 19:32:16 +0800 Subject: [PATCH] add api; fix send, socknode mem leak. --- utest/utest.cpp | 28 ++++++++++++++-------------- 1 files changed, 14 insertions(+), 14 deletions(-) diff --git a/utest/utest.cpp b/utest/utest.cpp index 817cbaf..12d4396 100644 --- a/utest/utest.cpp +++ b/utest/utest.cpp @@ -99,7 +99,7 @@ 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)); @@ -113,7 +113,8 @@ 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"); } @@ -149,7 +150,7 @@ 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; @@ -169,7 +170,7 @@ 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); } @@ -217,7 +218,7 @@ 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()); @@ -229,7 +230,8 @@ 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; } @@ -274,9 +276,9 @@ 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()); @@ -302,18 +304,16 @@ }; 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) { -- Gitblit v1.8.0