lichao
2021-05-13 db322f33ba13592f2492317e3f1a070454c97059
src/sendq.cpp
@@ -16,10 +16,12 @@
 * =====================================================================================
 */
#include "sendq.h"
#include "shm_queue.h"
#include "shm_msg_queue.h"
#include <chrono>
int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote remote, Array &arr)
using namespace bhome_shm;
int SendQ::DoSend1Remote(ShmMsgQueue &mq, const Remote remote, Array &arr)
{
   auto FirstNotExpired = [](Array &l) {
      auto Less = [](const TimedMsg &msg, const TimePoint &tp) { return msg.expire() < tp; };
@@ -38,20 +40,24 @@
   }
   auto SendData = [&](Data &d) {
      auto TryLoop = [&](auto &&data) {
         for (int i = 0; i < 1; ++i) {
            if (mq.TrySend(remote, data)) {
               return true;
            }
         }
         return false;
      };
      bool r = false;
      if (d.index() == 0) {
         auto &msg = boost::variant2::get<0>(pos->data().data_);
         r = mq.TrySend(remote, msg);
         r = TryLoop(msg);
         if (r) {
            msg.Release();
         }
      } else {
         auto &content = boost::variant2::get<1>(pos->data().data_);
         MsgI msg;
         if (msg.Make(content)) {
            DEFER1(msg.Release(););
            r = mq.TrySend(remote, msg);
         }
         auto command = boost::variant2::get<1>(pos->data().data_);
         r = TryLoop(command);
      }
      return r;
   };
@@ -65,7 +71,7 @@
   return nprocessed;
}
int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote remote, ArrayList &al)
int SendQ::DoSend1Remote(ShmMsgQueue &mq, const Remote remote, ArrayList &al)
{
   int nsend = 0;
   auto AllSent = [&](Array &arr) {
@@ -76,7 +82,7 @@
   return nsend;
}
bool SendQ::TrySend(bhome_shm::ShmMsgQueue &mq)
bool SendQ::TrySend(ShmMsgQueue &mq)
{
   std::unique_lock<std::mutex> lock(mutex_out_);
   size_t nsend = 0;
@@ -108,4 +114,4 @@
   Collect();
   return !out_.empty();
}
}