lichao
2021-04-26 bcd780993c176b93f7393607f8003adf66e6676a
src/topic_node.cpp
@@ -44,9 +44,10 @@
   }
   // recv msgs to avoid memory leak.
   auto default_ignore_msg = [](ShmSocket &sock, MsgI &imsg, BHMsgHead &head) { return true; };
   for (auto &p : sockets_) {
      p->Start(default_ignore_msg);
   }
   SockNode().Start(default_ignore_msg);
   // for (auto &p : sockets_) {
   //    p->Start(default_ignore_msg);
   // }
}
TopicNode::~TopicNode()
@@ -89,7 +90,7 @@
   AddId(SockSub().id());
   AddId(SockPub().id());
   auto head(InitMsgHead(GetType(body), body.proc().proc_id()));
   auto head(InitMsgHead(GetType(body), body.proc().proc_id(), ssn()));
   AddRoute(head, sock.id());
   auto CheckResult = [this](MsgI &msg, BHMsgHead &head, MsgCommonReply &rbody) {
@@ -129,7 +130,7 @@
   MsgUnregister body;
   body.mutable_proc()->Swap(&proc);
   auto head(InitMsgHead(GetType(body), body.proc().proc_id()));
   auto head(InitMsgHead(GetType(body), body.proc().proc_id(), ssn()));
   AddRoute(head, sock.id());
   auto CheckResult = [this](MsgI &msg, BHMsgHead &head, MsgCommonReply &rbody) {
@@ -165,7 +166,7 @@
   MsgHeartbeat body;
   body.mutable_proc()->Swap(&proc);
   auto head(InitMsgHead(GetType(body), body.proc().proc_id()));
   auto head(InitMsgHead(GetType(body), body.proc().proc_id(), ssn()));
   AddRoute(head, sock.id());
   if (timeout_ms == 0) {
@@ -195,7 +196,7 @@
   }
   auto &sock = SockNode();
   BHMsgHead head(InitMsgHead(GetType(query), proc_id()));
   BHMsgHead head(InitMsgHead(GetType(query), proc_id(), ssn()));
   AddRoute(head, sock.id());
   MsgI reply;
@@ -217,7 +218,7 @@
   MsgRegisterRPC body;
   body.mutable_topics()->Swap(&topics);
   auto head(InitMsgHead(GetType(body), proc_id()));
   auto head(InitMsgHead(GetType(body), proc_id(), ssn()));
   AddRoute(head, sock.id());
   if (timeout_ms == 0) {
@@ -242,7 +243,7 @@
      MsgRequestTopicReply reply_body;
      if (rcb(head.proc_id(), req, reply_body)) {
         BHMsgHead reply_head(InitMsgHead(GetType(reply_body), proc_id(), head.msg_id()));
         BHMsgHead reply_head(InitMsgHead(GetType(reply_body), proc_id(), ssn(), head.msg_id()));
         for (int i = 0; i < head.route_size() - 1; ++i) {
            reply_head.add_route()->Swap(head.mutable_route(i));
@@ -311,7 +312,7 @@
   if (!p || p->route.empty()) {
      return false;
   }
   BHMsgHead head(InitMsgHead(GetType(body), proc_id(), p->msg_id));
   BHMsgHead head(InitMsgHead(GetType(body), proc_id(), ssn(), p->msg_id));
   for (unsigned i = 0; i < p->route.size() - 1; ++i) {
      head.add_route()->Swap(&p->route[i]);
   }
@@ -348,7 +349,7 @@
   auto SendTo = [this, msg_id](const BHAddress &addr, const MsgRequestTopic &req, const RequestResultCB &cb) {
      auto &sock = SockClient();
      BHMsgHead head(InitMsgHead(GetType(req), proc_id(), msg_id));
      BHMsgHead head(InitMsgHead(GetType(req), proc_id(), ssn(), msg_id));
      AddRoute(head, sock.id());
      head.set_topic(req.topic());
@@ -388,7 +389,8 @@
      BHAddress addr;
      if (ClientQueryRPCTopic(request.topic(), addr, timeout_ms)) {
         BHMsgHead head(InitMsgHead(GetType(request), proc_id()));
         printf("node: %ld, topic dest: %ld\n", SockNode().id(), addr.mq_id());
         BHMsgHead head(InitMsgHead(GetType(request), proc_id(), ssn()));
         AddRoute(head, sock.id());
         head.set_topic(request.topic());
@@ -460,7 +462,7 @@
   try {
      auto &sock = SockPub();
      BHMsgHead head(InitMsgHead(GetType(pub), proc_id()));
      BHMsgHead head(InitMsgHead(GetType(pub), proc_id(), ssn()));
      AddRoute(head, sock.id());
      if (timeout_ms == 0) {
@@ -494,7 +496,7 @@
      MsgSubscribe sub;
      sub.mutable_topics()->Swap(&topics);
      BHMsgHead head(InitMsgHead(GetType(sub), proc_id()));
      BHMsgHead head(InitMsgHead(GetType(sub), proc_id(), ssn()));
      AddRoute(head, sock.id());
      if (timeout_ms == 0) {
         return sock.Send(BHTopicBusAddress(), head, sub);