From b5ae34d4422399c5d5458d071cca8c9bc89d20bb Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期六, 20 二月 2021 16:27:02 +0800
Subject: [PATCH] status map for close

---
 src/socket/shm_socket.cpp |   48 ++++++++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/socket/shm_socket.cpp b/src/socket/shm_socket.cpp
index 8a131e7..bc2ffb9 100644
--- a/src/socket/shm_socket.cpp
+++ b/src/socket/shm_socket.cpp
@@ -6,6 +6,7 @@
 #include "bus_error.h"
 #include "sole.h"
 #include "shm_mm.h"
+#include "key_def.h"
 
 static Logger *logger = LoggerFactory::getLogger();
 
@@ -109,7 +110,7 @@
 }
 
 
-int shm_socket_close(shm_socket_t *sockt) {
+static int _shm_socket_close_(shm_socket_t *sockt) {
   
   int rv;
   logger->debug("shm_socket_close\n");
@@ -118,17 +119,27 @@
   //   sockt->queue = NULL;
   // }
 
-  pthread_mutex_destroy(&(sockt->mutex) );
-   
+  // hashtable_remove(hashtable, mkey);
 
-  free(sockt);
-
-  auto it =  shmQueueStMap.find(key);
-  if(it != shmQueueStMap.end()) {
-    it->second.status = SHM_QUEUE_ST_CLOSED
-    it->second.closeTime = time(NULL);
+ 
+  if(sockt->key != 0) {
+    auto it =  shmQueueStMap->find(sockt->key);
+    if(it != shmQueueStMap->end()) {
+      it->second.status = SHM_QUEUE_ST_CLOSED;
+      it->second.closeTime = time(NULL);
+    }
   }
+
+ 
+
+  pthread_mutex_destroy(&(sockt->mutex) );
+  free(sockt);
   return 0;
+}
+
+
+int shm_socket_close(shm_socket_t *sockt) {
+  return _shm_socket_close_(sockt);
 }
 
 
@@ -283,7 +294,7 @@
     return;
 
   logger->debug("%d destroy tmp socket\n", pthread_self()); 
-  shm_socket_close((shm_socket_t *)tmp_socket);
+  _shm_socket_close_((shm_socket_t *)tmp_socket);
   rv =  pthread_setspecific(_perthread_socket_key_, NULL);
   if ( rv != 0) {
     logger->error(rv, "shm_sendandrecv : pthread_setspecific");
@@ -520,7 +531,7 @@
     return EBUS_RECVFROM_WRONG_END;
   } 
    
-  shm_socket_close(tmp_socket);  
+  _shm_socket_close_(tmp_socket);  
   return rv;
  
 }
@@ -532,6 +543,7 @@
 
   int rv;
   shm_queue_status_t stRecord;
+  LockFreeQueue<shm_packet_t> *remoteQueue;
   hashtable_t *hashtable = mm_get_hashtable();
 
   if( sockt->queue != NULL) 
@@ -558,7 +570,7 @@
       // 鏍囪key瀵瑰簲鐨勭姸鎬� 锛屼负opened
       stRecord.status = SHM_QUEUE_ST_OPENED;
       stRecord.createTime = time(NULL);
-      shmQueueStMap.insert({sockt->key, stRecord});
+      shmQueueStMap->insert({sockt->key, stRecord});
       
     }
 
@@ -575,15 +587,15 @@
   }
 
   // 妫�鏌ey鏍囪鐨勭姸鎬�
-  auto it =  shmQueueStMap.find(key);
-  if(it != shmQueueStMap.end()) {
+  auto it =  shmQueueStMap->find(key);
+  if(it != shmQueueStMap->end()) {
     if(it->second.status == SHM_QUEUE_ST_CLOSED) {
       // key瀵瑰簲鐨勭姸鎬佹槸鍏抽棴鐨�
       goto ERR_CLOSED;
     }
   }
 
-  LockFreeQueue<shm_packet_t> *remoteQueue = shm_socket_attach_queue(key);
+  remoteQueue = shm_socket_attach_queue(key);
 
   if (remoteQueue == NULL ) {
     goto ERR_CLOSED;
@@ -629,7 +641,7 @@
     // 鏍囪key瀵瑰簲鐨勭姸鎬� 锛屼负opened
     stRecord.status = SHM_QUEUE_ST_OPENED;
     stRecord.createTime = time(NULL);
-    shmQueueStMap.insert({sockt->key, stRecord});
+    shmQueueStMap->insert({sockt->key, stRecord});
     
     if ((rv = pthread_mutex_unlock(&(sockt->mutex))) != 0)
       err_exit(rv, "shm_recvfrom : pthread_mutex_unlock");
@@ -639,8 +651,8 @@
 LABEL_POP:
 
   // 妫�鏌ey鏍囪鐨勭姸鎬�
-  // auto shmQueueMapIter =  shmQueueStMap.find(sockt->key);
-  // if(shmQueueMapIter != shmQueueStMap.end()) {
+  // auto shmQueueMapIter =  shmQueueStMap->find(sockt->key);
+  // if(shmQueueMapIter != shmQueueStMap->end()) {
   //   stRecord = shmQueueMapIter->second;
   //   if(stRecord.status = SHM_QUEUE_ST_CLOSED) {
   //     // key瀵瑰簲鐨勭姸鎬佹槸鍏抽棴鐨�

--
Gitblit v1.8.0