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 |   50 +++++++++++++++++++++++++++++++++-----------------
 1 files changed, 33 insertions(+), 17 deletions(-)

diff --git a/src/socket/shm_socket.c b/src/socket/shm_socket.c
index c1ac3c8..ddc26fa 100644
--- a/src/socket/shm_socket.c
+++ b/src/socket/shm_socket.c
@@ -2,6 +2,7 @@
 #include "hashtable.h"
 #include "logger_factory.h"
 #include <map>
+#include "bus_error.h"
 
 static Logger *logger = LoggerFactory::getLogger();
 
@@ -29,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;
@@ -60,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);
@@ -73,7 +76,6 @@
   }
   free(socket);
   SemUtil::remove(socket->mutex);
-  logger->debug("shm_close_socket\n");
   return ret;
 }
 
@@ -111,7 +113,8 @@
   } else {
 
    if(!_shm_socket_check_key(socket)) {
-     return -1;
+     bus_errno = EBUS_KEY_INUSED;
+     return EBUS_KEY_INUSED;
    }
   }
 
@@ -201,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;
     }
   }
 
@@ -247,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;
@@ -307,7 +311,8 @@
     } else {
 
      if(!_shm_socket_check_key(socket)) {
-        return -1;
+        bus_errno = EBUS_KEY_INUSED;
+        return EBUS_KEY_INUSED;
      }
 
     }
@@ -323,8 +328,9 @@
 
   SHMQueue<shm_msg_t> *remoteQueue;
   if ((remoteQueue = _attach_remote_queue(key)) == NULL) {
-  	logger->error( "shm_sendto failed, the other end has been closed, or has not been opened!");
-    return SHM_SOCKET_ECONNFAILED;
+    bus_errno = EBUS_CLOSED;
+    logger->error("sendto key %d failed, %s", key, bus_strerror(bus_errno));
+    return EBUS_CLOSED;
   }
 
   shm_msg_t dest;
@@ -351,8 +357,16 @@
   } else {
     delete remoteQueue;
     mm_free(dest.buf);
-    logger->error(errno, "sendto key %d failed!", key);
-    return -1;
+    if(errno == EAGAIN) {
+      bus_errno = EBUS_TIMEOUT;
+      logger->error("sendto key %d failed, %s", key, bus_strerror(bus_errno));
+      return EBUS_TIMEOUT;
+    } else {
+      logger->error(errno, "sendto key %d failed!", key);
+      return -1;
+    }
+   
+   
   }
 }
 
@@ -372,7 +386,8 @@
     } else {
 
       if(!_shm_socket_check_key(socket)) {
-        return -1;
+        bus_errno = EBUS_KEY_INUSED;
+        return EBUS_KEY_INUSED;
       }
     }
 
@@ -523,6 +538,7 @@
   return  shm_sendandrecv_unsafe(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout,  flags);
 }
 
+
 // ============================================================================================================
 
 /**
@@ -532,7 +548,7 @@
 
   hashtable_t *hashtable = mm_get_hashtable();
   if (hashtable_get(hashtable, key) == NULL) {
-    logger->error("shm_socket._remote_queue_attach锛歝onnet at key %d  failed!", key);
+    //logger->error("shm_socket._remote_queue_attach锛歝onnet at key %d  failed!", key);
     return NULL;
   }
 

--
Gitblit v1.8.0