From 36e6a35a886252516f168b90f7a9a7c1c5177312 Mon Sep 17 00:00:00 2001 From: lichao <lichao@aiotlink.com> Date: 星期六, 08 五月 2021 15:57:01 +0800 Subject: [PATCH] center alloc node queue; node just find them. --- src/socket.h | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/socket.h b/src/socket.h index 08a4b0a..981677f 100644 --- a/src/socket.h +++ b/src/socket.h @@ -48,6 +48,7 @@ typedef std::function<void(ShmSocket &sock)> IdleCB; ShmSocket(Shm &shm, const MQId id, const int len); + ShmSocket(Shm &shm, const bool create_or_else_find, const MQId id, const int len); ShmSocket(Shm &shm, const int len = 12); ~ShmSocket(); static bool Remove(SharedMemory &shm, const MQId id) { return Queue::Remove(shm, id); } @@ -142,6 +143,7 @@ template <class... Rest> bool SendImpl(const MQId remote, Rest &&...rest) { + // TODO send alloc request, and pack later, higher bit means alloc? send_buffer_.Append(remote, std::forward<decltype(rest)>(rest)...); return true; } @@ -151,14 +153,15 @@ std::atomic<bool> run_; Queue mq_; - class AsyncCBs + template <class Key> + class CallbackRecords { - std::unordered_map<std::string, RecvCB> store_; + std::unordered_map<Key, RecvCB> store_; public: bool empty() const { return store_.empty(); } - bool Store(const std::string &id, RecvCB &&cb) { return store_.emplace(id, std::move(cb)).second; } - bool Pick(const std::string &id, RecvCB &cb) + bool Store(const Key &id, RecvCB &&cb) { return store_.emplace(id, std::move(cb)).second; } + bool Pick(const Key &id, RecvCB &cb) { auto pos = store_.find(id); if (pos != store_.end()) { @@ -171,9 +174,9 @@ } }; - Synced<AsyncCBs> per_msg_cbs_; + Synced<CallbackRecords<std::string>> per_msg_cbs_; + SendQ send_buffer_; - // Synced<SendQ> send_buffer_; }; #endif // end of include guard: SOCKET_GWTJHBPO -- Gitblit v1.8.0