From ed1f486e2c2d8c02d675363d848a3460edfe80e3 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 29 十二月 2020 16:22:34 +0800
Subject: [PATCH] update

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

diff --git a/src/socket/shm_socket.c b/src/socket/shm_socket.c
index f53b520..ddc26fa 100644
--- a/src/socket/shm_socket.c
+++ b/src/socket/shm_socket.c
@@ -30,7 +30,8 @@
 static inline int  _shm_socket_check_key(shm_socket_t *socket) {
    void *tmp_ptr = mm_get_by_key(socket->key);
     if (tmp_ptr!= NULL && tmp_ptr != (void *)1 && !socket->force_bind ) {
-      logger->error("key %d has already been in used!", socket->key);
+      bus_errno = EBUS_KEY_INUSED;
+      logger->error("%s. key = %d ", bus_strerror(bus_errno), socket->key);
       return 0;
     }
     return 1;
@@ -61,7 +62,8 @@
 int shm_close_socket(shm_socket_t *socket) {
   
   int ret;
-
+  
+  logger->debug("shm_close_socket\n");
   switch (socket->socket_type) {
     case SHM_SOCKET_STREAM:
       ret =  _shm_close_stream_socket(socket, true);
@@ -74,7 +76,6 @@
   }
   free(socket);
   SemUtil::remove(socket->mutex);
-  logger->debug("shm_close_socket\n");
   return ret;
 }
 
@@ -112,7 +113,8 @@
   } else {
 
    if(!_shm_socket_check_key(socket)) {
-     return -1;
+     bus_errno = EBUS_KEY_INUSED;
+     return EBUS_KEY_INUSED;
    }
   }
 
@@ -202,7 +204,8 @@
     socket->key = hashtable_alloc_key(hashtable);
   } else {
     if(!_shm_socket_check_key(socket)) {
-      return -1;
+      bus_errno = EBUS_KEY_INUSED;
+      return EBUS_KEY_INUSED;
     }
   }
 
@@ -248,11 +251,11 @@
                 "SHM_SOCKET_STREAM socket");
     exit(1);
   }
-  // hashtable_t *hashtable = mm_get_hashtable();
-  // if(socket->remoteQueue == NULL) {
-  // 	err_msg(errno, "褰撳墠瀹㈡埛绔棤杩炴帴!");
-  // 	return -1;
-  // }
+  hashtable_t *hashtable = mm_get_hashtable();
+  if(socket->remoteQueue == NULL) {
+  	err_msg(errno, "褰撳墠瀹㈡埛绔棤杩炴帴!");
+  	return -1;
+  }
   shm_msg_t dest;
   dest.type = SHM_COMMON_MSG;
   dest.key = socket->key;
@@ -308,7 +311,8 @@
     } else {
 
      if(!_shm_socket_check_key(socket)) {
-        return -1;
+        bus_errno = EBUS_KEY_INUSED;
+        return EBUS_KEY_INUSED;
      }
 
     }
@@ -382,7 +386,8 @@
     } else {
 
       if(!_shm_socket_check_key(socket)) {
-        return -1;
+        bus_errno = EBUS_KEY_INUSED;
+        return EBUS_KEY_INUSED;
       }
     }
 
@@ -533,6 +538,7 @@
   return  shm_sendandrecv_unsafe(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout,  flags);
 }
 
+
 // ============================================================================================================
 
 /**

--
Gitblit v1.8.0