From 0f53806de20f07b0bc15877c7a9b293758acbfa7 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期三, 01 三月 2023 09:20:38 +0800
Subject: [PATCH] bug fixed ps_sub thread join

---
 src/nng_wrap.cpp |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/nng_wrap.cpp b/src/nng_wrap.cpp
index f2c22c4..53a192a 100644
--- a/src/nng_wrap.cpp
+++ b/src/nng_wrap.cpp
@@ -205,12 +205,13 @@
         PRNTVITAG("client_socket faild\n");
         return -1;
     }
-    // set_socket_timeout(sock, timeout_req_rep);
+    set_socket_timeout(sock, 300);
     sub->socket_ = sock;
     sub->t_ = get_thread([](const auto sub){
         while (!sub->t_quit_.load()) {
             char* m{};
-            int m_len = nn_recv(sub->socket_, &m, NN_MSG, NN_DONTWAIT);
+            // int m_len = nn_recv(sub->socket_, &m, NN_MSG, NN_DONTWAIT);
+            int m_len = nn_recv(sub->socket_, &m, NN_MSG, 0);
             if (m_len > 0){
                 string tmp_msg{m, (size_t)m_len};
                 nn_freemsg(m);
@@ -589,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);

--
Gitblit v1.8.0