| | |
| | | Super(len, alloc) {} |
| | | using Super::capacity; |
| | | using Super::size; |
| | | template <class Iter, class OnWrite> |
| | | int Write(Iter begin, Iter end, const int timeout_ms, const OnWrite &onWrite) |
| | | { |
| | | auto endtime = MSFromNow(timeout_ms); |
| | | auto timedWritePred = [this, endtime](Guard &lock) { |
| | | return (cond_write_.timed_wait(lock, endtime, [&]() { return !this->full(); })); |
| | | }; |
| | | return WriteAllOnCond(begin, end, timedWritePred, onWrite); |
| | | } |
| | | |
| | | template <class OnWrite> |
| | | bool Write(const D &buf, const int timeout_ms, const OnWrite &onWrite) { return Write(&buf, (&buf) + 1, timeout_ms, onWrite); } |
| | | bool Write(const D &buf, const int timeout_ms) |
| | | { |
| | | return Write(buf, timeout_ms, [](const D &buf) {}); |
| | | } |
| | | |
| | | template <class Iter, class OnWrite> |
| | | int TryWrite(Iter begin, Iter end, const OnWrite &onWrite) |
| | |
| | | bool TryRecv(MsgI &msg) { return data()->TryRead(msg); } |
| | | template <class OnData> |
| | | int TryRecvAll(OnData const &onData) { return data()->TryReadAll(onData); } |
| | | static Queue *FindRemote(SharedMemory &shm, const MQId &remote_id); |
| | | static bool Send(SharedMemory &shm, const MQId &remote_id, const MsgI &msg, const int timeout_ms, OnSend const &onsend = OnSend()); |
| | | static Queue *Find(SharedMemory &shm, const MQId &remote_id); |
| | | // static bool Send(SharedMemory &shm, const MQId &remote_id, const MsgI &msg, const int timeout_ms, OnSend const &onsend = OnSend()); |
| | | static bool TrySend(SharedMemory &shm, const MQId &remote_id, const MsgI &msg, OnSend const &onsend = OnSend()); |
| | | template <class Iter> |
| | | static int TrySendAll(SharedMemory &shm, const MQId &remote_id, const Iter begin, const Iter end, OnSend const &onsend = OnSend()) |
| | | { |
| | | Queue *remote = FindRemote(shm, remote_id); |
| | | Queue *remote = Find(shm, remote_id); |
| | | if (remote) { |
| | | if (onsend) { |
| | | return remote->TryWrite(begin, end, [&onsend](const MsgI &msg) { onsend(); msg.AddRef(); }); |
| | |
| | | } |
| | | } |
| | | |
| | | template <class... Rest> |
| | | bool Send(const MQId &remote_id, Rest const &...rest) { return Send(shm(), remote_id, rest...); } |
| | | // template <class... Rest> |
| | | // bool Send(const MQId &remote_id, Rest const &...rest) { return Send(shm(), remote_id, rest...); } |
| | | template <class... Rest> |
| | | bool TrySend(const MQId &remote_id, Rest const &...rest) { return TrySend(shm(), remote_id, rest...); } |
| | | template <class... Rest> |