| | |
| | | bool ShmMsgQueue::Send(const MQId &remote_id, const Msg &msg, const int timeout_ms) |
| | | { |
| | | Queue *remote = find(MsgQIdToName(remote_id)); |
| | | |
| | | if(!remote) { |
| | | return false; |
| | | } |
| | | msg.AddRef(); |
| | | if (remote->Write(msg, timeout_ms)) { |
| | | return true; |
| | | } else { |
| | | msg.RemoveRef(); |
| | | return false; |
| | | } |
| | | return remote && remote->Write(msg, timeout_ms, [&](){msg.AddRef();}); |
| | | } |
| | | |
| | | bool ShmMsgQueue::Send(const MQId &remote_id, const void *data, const size_t size, const int timeout_ms) |
| | |
| | | // 1 is about 50% faster than 2, maybe cache related. |
| | | |
| | | Msg msg; |
| | | if (msg.Build(shm(), Id(), data, size, false)) { |
| | | if (Send(remote_id, msg, timeout_ms)) { |
| | | if(msg.Build(shm(), Id(), data, size, false)) { |
| | | if(Send(remote_id, msg, timeout_ms)) { |
| | | return true; |
| | | } else { |
| | | if (msg.RemoveRef() == 0) { // works for both refcounted and not counted. |
| | | msg.FreeFrom(shm()); |
| | | } |
| | | msg.Release(shm()); |
| | | } |
| | | } |
| | | return false; |
| | |
| | | { |
| | | Msg msg; |
| | | if (Read(msg, timeout_ms)) { |
| | | DEFER1(if (msg.RemoveRef() == 0) { msg.FreeFrom(shm()); }); |
| | | DEFER1(msg.Release(shm());); |
| | | |
| | | auto ptr = msg.get<char>(); |
| | | if (ptr) { |