From 3931f83205f153f2bc7fc36d1a894cdc3f14b4db Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期三, 21 四月 2021 16:52:51 +0800 Subject: [PATCH] change node socket to vector; try lock free queue. --- utest/api_test.cpp | 21 ++++++++++++--------- 1 files changed, 12 insertions(+), 9 deletions(-) diff --git a/utest/api_test.cpp b/utest/api_test.cpp index 58c73c6..766c0f8 100644 --- a/utest/api_test.cpp +++ b/utest/api_test.cpp @@ -19,7 +19,7 @@ #include "util.h" #include <atomic> -using namespace bhome::msg; +using namespace bhome_msg; namespace { @@ -66,7 +66,7 @@ const int proc_id_len, const void *data, const int data_len, - BHServerCallbackTag *tag) + void *src) { // printf("ServerProc: "); // DEFER1(printf("\n");); @@ -76,7 +76,7 @@ reply.set_data(" reply: " + request.data()); std::string s(reply.SerializeAsString()); // printf("%s", reply.data().c_str()); - BHServerCallbackReply(tag, s.data(), s.size()); + BHSendReply(src, s.data(), s.size()); ++Status().nserved_; } } @@ -155,7 +155,7 @@ printf("maxsec: %ld\n", CountSeconds(max_time)); bool reg = false; - for (int i = 0; i < 10 && !reg; ++i) { + for (int i = 0; i < 3 && !reg; ++i) { ProcInfo proc; proc.set_proc_id("demo_client"); proc.set_public_info("public info of demo_client. etc..."); @@ -167,6 +167,9 @@ BHFree(reply, reply_len); Sleep(1s); + } + if (!reg) { + return; } const std::string topic_ = "topic_"; @@ -204,7 +207,7 @@ for (int i = 0; i < 1; ++i) { MsgPublish pub; pub.set_topic(topic_ + std::to_string(i)); - pub.set_data("pub_data_" + std::string(1024 * 1024, 'a')); + pub.set_data("pub_data_" + std::string(1024 * 1, 'a')); std::string s(pub.SerializeAsString()); BHPublish(s.data(), s.size(), 0); // Sleep(1s); @@ -241,7 +244,7 @@ MsgStatus last; while (*run) { auto &st = Status(); - std::this_thread::sleep_for(1s); + Sleep(1s, false); printf("nreq: %8ld, spd %8ld | failed: %8ld | nsrv: %8ld, spd %8ld | nreply: %8ld, spd %8ld\n", st.nrequest_.load(), st.nrequest_ - last.nrequest_, st.nfailed_.load(), @@ -253,7 +256,7 @@ auto hb = [](std::atomic<bool> *run) { while (*run) { Sleep(1s, false); - bool r = BHHeartBeatEasy(1000); + bool r = BHHeartbeatEasy(1000); printf("heartbeat: %s\n", r ? "ok" : "failed"); } }; @@ -270,8 +273,8 @@ int same = 0; int64_t last = 0; - while (last < nreq * ncli && same < 3) { - Sleep(1s); + while (last < nreq * ncli && same < 2) { + Sleep(1s, false); auto cur = Status().nreply_.load(); if (last == cur) { ++same; -- Gitblit v1.8.0