From e4130d29e80a40884310481ded90ff845c614f43 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 24 十二月 2020 10:03:14 +0800
Subject: [PATCH] bus force bind

---
 src/socket/shm_socket.c |   60 ++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 38 insertions(+), 22 deletions(-)

diff --git a/src/socket/shm_socket.c b/src/socket/shm_socket.c
index efb3ef7..80674c1 100644
--- a/src/socket/shm_socket.c
+++ b/src/socket/shm_socket.c
@@ -45,6 +45,7 @@
 
 shm_socket_t *shm_open_socket(shm_socket_type_t socket_type) {
 
+  logger->debug("shm_open_socket\n");
   shm_socket_t *socket = (shm_socket_t *)calloc(1, sizeof(shm_socket_t));
   socket->socket_type = socket_type;
   socket->key = -1;
@@ -52,14 +53,15 @@
   socket->dispatch_thread = 0;
   socket->status = SHM_CONN_CLOSED;
   socket->mutex = SemUtil::get(IPC_PRIVATE, 1);
-  logger->debug("shm_open_socket\n");
+  
   return socket;
 }
 
-static int _shm_close_socket(shm_socket_t *socket) {
+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);
@@ -72,16 +74,15 @@
   }
   free(socket);
   SemUtil::remove(socket->mutex);
-  logger->debug("shm_close_socket\n");
   return ret;
 }
 
-int shm_close_socket(shm_socket_t *socket) {
+// int shm_close_socket(shm_socket_t *socket) {
   
-  // _destrory_tmp_recv_socket_((shm_socket_t *)pthread_getspecific(_tmp_recv_socket_key_));
+//   // _destrory_tmp_recv_socket_((shm_socket_t *)pthread_getspecific(_tmp_recv_socket_key_));
  
-  return _shm_close_socket(socket);;
-}
+//   return shm_close_socket(socket);;
+// }
 
 int shm_socket_bind(shm_socket_t *socket, int key) {
   socket->key = key;
@@ -246,11 +247,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;
@@ -391,11 +392,18 @@
   }
 
   if (rv) {
-    void *_buf = malloc(src.size);
-    memcpy(_buf, src.buf, src.size);
-    *buf = _buf;
-    *size = src.size;
-    *key = src.key;
+    if(buf != NULL) {
+      void *_buf = malloc(src.size);
+      memcpy(_buf, src.buf, src.size);
+      *buf = _buf; 
+    }
+   
+    if(size != NULL)
+      *size = src.size;
+
+    if(key != NULL)
+      *key = src.key;
+
     mm_free(src.buf);
     // printf("shm_recvfrom pop after\n");
     return 0;
@@ -411,12 +419,13 @@
   int rv;
   if(tmp_socket == NULL)
     return;
+
   logger->debug("%d destroy tmp socket\n", pthread_self()); 
-  _shm_close_socket((shm_socket_t *)tmp_socket);
+  shm_close_socket((shm_socket_t *)tmp_socket);
   rv =  pthread_setspecific(_tmp_recv_socket_key_, NULL);
   if ( rv != 0) {
-      logger->error(rv, "shm_sendandrecv : pthread_setspecific");
-      exit(1);
+    logger->error(rv, "shm_sendandrecv : pthread_setspecific");
+    exit(1);
   }
 }
 
@@ -438,7 +447,7 @@
 
 
 
-int shm_sendandrecv(shm_socket_t *socket, const void *send_buf,
+int shm_sendandrecv_safe(shm_socket_t *socket, const void *send_buf,
                     const int send_size, const int send_key, void **recv_buf,
                     int *recv_size,  struct timespec *timeout,  int flags) {
   int recv_key;
@@ -508,6 +517,13 @@
   return -1;
 }
 
+int shm_sendandrecv(shm_socket_t *socket, const void *send_buf,
+                    const int send_size, const int send_key, void **recv_buf,
+                    int *recv_size,  struct timespec *timeout,  int flags) {
+  return  shm_sendandrecv_unsafe(socket, send_buf, send_size, send_key,recv_buf, recv_size, timeout,  flags);
+}
+
+
 // ============================================================================================================
 
 /**

--
Gitblit v1.8.0