lichao
2021-04-16 94a455aba299af5ffe476560d859dfd007cd5467
src/socket.h
@@ -66,32 +66,24 @@
   size_t Pending() const { return mq().Pending(); }
   template <class Body>
   bool Send(const void *valid_remote, const BHMsgHead &head, const Body &body)
   bool Send(const void *valid_remote, const BHMsgHead &head, const Body &body, const RecvCB &cb = RecvCB())
   {
      MsgI msg;
      if (msg.Make(shm(), head, body)) {
         DEFER1(if (msg.IsCounted()) { msg.Release(shm()); });
         return SendImpl(valid_remote, msg);
      }
      return false;
   }
   template <class Body>
   bool Send(const void *valid_remote, const BHMsgHead &head, const Body &body, const RecvCB &cb)
   {
      //TODO send_buffer_ need flag, and remove callback on expire.
      MsgI msg;
      if (msg.Make(shm(), head, body)) {
         DEFER1(if (msg.IsCounted()) { msg.Release(shm()); });
         std::string msg_id(head.msg_id());
         per_msg_cbs_->Add(msg_id, cb);
         auto onExpireRemoveCB = [this, msg_id](MsgI const &msg) {
            RecvCB cb_no_use;
            per_msg_cbs_->Find(msg_id, cb_no_use);
         };
         return SendImpl(valid_remote, msg, onExpireRemoveCB);
         if (!cb) {
            return SendImpl(valid_remote, msg);
         } else {
            per_msg_cbs_->Add(msg_id, cb);
            auto onExpireRemoveCB = [this, msg_id](MsgI const &msg) {
               RecvCB cb_no_use;
               per_msg_cbs_->Find(msg_id, cb_no_use);
            };
            return SendImpl(valid_remote, msg, onExpireRemoveCB);
         }
      } else {
         printf("out of mem?, avail: %ld\n", shm().get_free_memory());
         SetLastError(ENOMEM, "Out of mem");
      }
      return false;
   }