lichao
2021-04-15 c64c54d8e75b9354dc49a7b6b2d326e7dd59eb37
src/socket.h
@@ -36,7 +36,7 @@
class ShmSocket : private boost::noncopyable
{
   bool SendImpl(const void *valid_remote, const MsgI &imsg, SendQ::OnMsgEvent onExpire = SendQ::OnMsgEvent())
   bool SendImpl(const void *valid_remote, MsgI const &imsg, SendQ::OnMsgEvent onExpire = SendQ::OnMsgEvent())
   {
      // if (!mq().TrySend(*(MQId *) valid_remote, imsg)) {
      send_buffer_.Append(*static_cast<const MQId *>(valid_remote), imsg, onExpire);
@@ -69,7 +69,11 @@
   bool Send(const void *valid_remote, const BHMsgHead &head, const Body &body)
   {
      MsgI msg;
      return msg.Make(shm(), head, body) && SendImpl(valid_remote, msg);
      if (msg.Make(shm(), head, body)) {
         DEFER1(if (msg.IsCounted()) { msg.Release(shm()); });
         return SendImpl(valid_remote, msg);
      }
      return false;
   }
   template <class Body>
@@ -78,6 +82,7 @@
      //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) {
@@ -85,6 +90,8 @@
            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());
      }
      return false;
   }