| | |
| | | template <class Body> |
| | | bool Send(const void *valid_remote, const BHMsgHead &head, const Body &body, const int timeout_ms, const RecvCB &cb) |
| | | { |
| | | auto DoSend = [&](MsgI &msg) { return mq().Send(*static_cast<const MQId *>(valid_remote), msg, timeout_ms, [&]() { async_cbs_->Add(head.msg_id(), cb); }); }; |
| | | auto DoSend = [&](MsgI &msg) { return mq().Send(*static_cast<const MQId *>(valid_remote), msg, timeout_ms, [&]() { per_msg_cbs_->Add(head.msg_id(), cb); }); }; |
| | | MsgI msg; |
| | | return msg.Make(shm(), head, body) && SendImpl(msg, timeout_ms, DoSend); |
| | | } |
| | |
| | | reply.swap(msg); |
| | | reply_head.Swap(&head); |
| | | st->cv.notify_one(); |
| | | } else { |
| | | } else { // ignore |
| | | } |
| | | }; |
| | | |
| | | std::unique_lock<std::mutex> lk(st->mutex); |
| | | bool sendok = Send(remote, head, body, timeout_ms, OnRecv); |
| | | if (!sendok) { |
| | | printf("send timeout\n"); |
| | | } |
| | | if (sendok && st->cv.wait_until(lk, endtime) == std::cv_status::no_timeout) { |
| | | return true; |
| | | } else { |
| | |
| | | } |
| | | }; |
| | | |
| | | Synced<AsyncCBs> async_cbs_; |
| | | Synced<AsyncCBs> per_msg_cbs_; |
| | | }; |
| | | |
| | | #endif // end of include guard: SOCKET_GWTJHBPO |