| | |
| | | #include "util.h" |
| | | #include <atomic> |
| | | |
| | | using namespace bhome::msg; |
| | | using namespace bhome_msg; |
| | | |
| | | namespace |
| | | { |
| | |
| | | const int proc_id_len, |
| | | const void *data, |
| | | const int data_len, |
| | | BHServerCallbackTag *tag) |
| | | void *src) |
| | | { |
| | | // printf("ServerProc: "); |
| | | // DEFER1(printf("\n");); |
| | |
| | | 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_; |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | namespace |
| | | { |
| | | struct CCC { |
| | | }; |
| | | void F(CCC &&c) {} |
| | | |
| | | template <class... T> |
| | | void Pass(T &&...t) |
| | | { |
| | | F(std::forward<decltype(t)>(t)...); |
| | | } |
| | | |
| | | } // namespace |
| | | BOOST_AUTO_TEST_CASE(ApiTest) |
| | | { |
| | | auto max_time = std::chrono::steady_clock::time_point::max(); |
| | |
| | | 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..."); |
| | |
| | | |
| | | BHFree(reply, reply_len); |
| | | Sleep(1s); |
| | | } |
| | | if (!reg) { |
| | | return; |
| | | } |
| | | |
| | | const std::string topic_ = "topic_"; |
| | |
| | | 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); |
| | |
| | | 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"); |
| | | } |
| | | }; |