From 9045f528b9b6f21f0d15475d2dffd49bb51598fc Mon Sep 17 00:00:00 2001 From: zhangmeng <775834166@qq.com> Date: 星期一, 26 十二月 2022 09:16:03 +0800 Subject: [PATCH] optimize cpu --- src/nng_wrap.cpp | 12 +++++++----- src/nng_wrap.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/nng_wrap.cpp b/src/nng_wrap.cpp index c3b835f..c64e424 100644 --- a/src/nng_wrap.cpp +++ b/src/nng_wrap.cpp @@ -590,20 +590,22 @@ if (!w) return -1; - *src = malloc(sizeof(uint64_t)); - *(uint64_t*)(*src) = key; + *src = malloc(sizeof(key)); + memcpy(*src, &key, sizeof(key)); return w->mode; } -int send_reply(const void* src, const void* msg, const int msg_len, void* arg/*=NULL*/){ +int send_reply(void* src, const void* msg, const int msg_len, void* arg/*=NULL*/){ _rr* rep = (_rr*)arg; if (!rep) rep = singleton<_rr>(); struct work* w{}; { - auto key = *(static_cast<uint64_t*>(const_cast<void*>(src))); - free(const_cast<void*>(src)); + uint64_t key; + memcpy(&key, src, sizeof(key)); + // auto key = *(static_cast<uint64_t*>(const_cast<void*>(src))); + free(src); lock_guard<mutex> l{rep->mtx_msg_}; auto iter = rep->works_.find(key); diff --git a/src/nng_wrap.h b/src/nng_wrap.h index 6d82afb..73dc670 100644 --- a/src/nng_wrap.h +++ b/src/nng_wrap.h @@ -28,7 +28,7 @@ void** reply, int* reply_len, const int to_ms, void* arg=NULL); int start_reply(const std::string& url, const int port, void* arg=NULL); int read_request(void** src, std::string* msg, const int to_ms, void* arg=NULL); -int send_reply(const void* src, const void* msg, const int msg_len, void* arg=NULL); +int send_reply(void* src, const void* msg, const int msg_len, void* arg=NULL); } -- Gitblit v1.8.0