From 5bb28835d06e27dbd960916c9fb11a555fc5a9bc Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期一, 26 四月 2021 14:24:29 +0800 Subject: [PATCH] add shared lib target. --- src/sendq.cpp | 37 +++++++++++++++++++++++++++---------- 1 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/sendq.cpp b/src/sendq.cpp index 242f8de..5b57d72 100644 --- a/src/sendq.cpp +++ b/src/sendq.cpp @@ -19,7 +19,7 @@ #include "shm_queue.h" #include <chrono> -int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote &remote, Array &arr) +int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote remote, Array &arr) { auto FirstNotExpired = [](Array &l) { auto Less = [](const TimedMsg &msg, const TimePoint &tp) { return msg.expire() < tp; }; @@ -30,25 +30,42 @@ for (auto it = arr.begin(); it != pos; ++it) { auto &info = it->data(); if (info.on_expire_) { - info.on_expire_(info.msg_); + info.on_expire_(info.data_); } - info.msg_.Release(mq.shm()); + if (info.data_.index() == 0) { + boost::variant2::get<0>(info.data_).Release(); + } } - int n = mq.TrySendAll(*(MQId *) remote.data(), MsgIter(pos), MsgIter(arr.end())); - for (int i = 0; i < n; ++i) { - auto &msg = pos->data().msg_; - if (msg.IsCounted()) { - msg.Release(mq.shm()); + auto SendData = [&](Data &d) { + bool r = false; + if (d.index() == 0) { + auto &msg = boost::variant2::get<0>(pos->data().data_); + r = mq.TrySend(remote, 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); + } } + return r; + }; + + while (pos != arr.end() && SendData(pos->data().data_)) { ++pos; } + int nprocessed = std::distance(arr.begin(), pos); arr.erase(arr.begin(), pos); - return n; + return nprocessed; } -int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote &remote, ArrayList &al) +int SendQ::DoSend1Remote(bhome_shm::ShmMsgQueue &mq, const Remote remote, ArrayList &al) { int nsend = 0; auto AllSent = [&](Array &arr) { -- Gitblit v1.8.0