| | |
| | | #include "timed_queue.h" |
| | | #include <deque> |
| | | #include <functional> |
| | | #include <mutex> |
| | | #include <string> |
| | | #include <unordered_map> |
| | | |
| | |
| | | static TimePoint Now() { return TimedMsg::Clock::now(); } |
| | | void Append(const Remote &addr, const MsgI &msg, const TimePoint &expire, OnMsgEvent onExpire) |
| | | { |
| | | //TODO simple queue, organize later ? |
| | | |
| | | msg.AddRef(); |
| | | store_[addr].emplace_back(TimedMsg(expire, MsgInfo{msg, onExpire})); |
| | | TimedMsg tmp(expire, MsgInfo{msg, onExpire}); |
| | | std::unique_lock<std::mutex> lock(mutex_); |
| | | in_[addr].emplace_back(std::move(tmp)); |
| | | } |
| | | typedef std::deque<TimedMsg> MsgList; |
| | | typedef std::unordered_map<Remote, MsgList> Store; |
| | | class MsgIter |
| | | { |
| | | MsgList::iterator iter_; |
| | | |
| | | Store store_; |
| | | public: |
| | | MsgIter(MsgList::iterator iter) : |
| | | iter_(iter) {} |
| | | MsgIter &operator++() { return ++iter_, *this; } |
| | | bool operator==(const MsgIter &a) { return iter_ == a.iter_; } |
| | | MsgI &operator*() { return iter_->data().msg_; } |
| | | }; |
| | | std::mutex mutex_; |
| | | Store in_; |
| | | Store out_; |
| | | }; |
| | | |
| | | #endif // end of include guard: SENDQ_IWKMSK7M |