From 9b9dd8cc7d3a6fd05750d4f41720cf6094780551 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 26 十一月 2020 16:46:14 +0800
Subject: [PATCH] update

---
 src/socket/net_mod_socket.c         |  502 +++++++++++++++++++---------
 src/socket/net_mod_socket_wrapper.h |  126 ++++++
 src/socket/net_mod_socket_io.h      |    2 
 src/socket/net_mod_socket.h         |  134 +++++++
 src/socket/net_mod_socket_wrapper.c |  193 ++++++++++-
 src/socket/net_mod_socket_io.c      |   21 
 6 files changed, 759 insertions(+), 219 deletions(-)

diff --git a/src/socket/net_mod_socket.c b/src/socket/net_mod_socket.c
index 9058272..f55e439 100644
--- a/src/socket/net_mod_socket.c
+++ b/src/socket/net_mod_socket.c
@@ -24,105 +24,43 @@
 }
 
 
-void  NetModSocket::init_req_rep_req_resp_pool()
-{
-  /* Initially, there are no connected descriptors */
-  int i;
-  req_resp_pool.maxi = -1;                   //line:conc:echoservers:beginempty
-  for (i = 0; i < OPEN_MAX; i++) {
-    req_resp_pool.conns[i].fd = -1; 
-    req_resp_pool.conns[i].events = 0;      
-  }
-
+/**
+ * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int NetModSocket::bind(int port) {
+  return shmModSocket.bind(port);
 }
 
-int NetModSocket::connect( net_node_t *node) {
-  std::map<std::string, int>::iterator mapIter;
-  int connfd;
-  int i;
-  char mapKey[256];
-  char portstr[32];
-
-  sprintf(mapKey, "%s:%d", node->host, node->port);
-  mapIter =  req_resp_pool.connectionMap.find(mapKey);
-  if( mapIter != req_resp_pool.connectionMap.end()) {
-    connfd = mapIter->second;
-// printf("hit: %s\n", mapKey);
-  } else {
-// printf("mis: %s\n", mapKey);     
-    sprintf(portstr, "%d", node->port);
-// printf("open before: %s\n", mapKey); 
-    connfd = open_clientfd(node->host, portstr);
-// printf("open after: %s\n", mapKey); 
-    if(connfd < 0) {
-      LoggerFactory::getLogger()->error(errno, "connect %s:%d ", node->host, node->port);
-      return -1;
-    }
-    req_resp_pool.connectionMap.insert({mapKey, connfd});
-  }
-
-  
-  for (i = 0; i < OPEN_MAX; i++) { /* Find an available slot */
-    if (req_resp_pool.conns[i].fd < 0)
-    {
-      /* Add connected descriptor to the req_resp_pool */
-      req_resp_pool.conns[i].fd = connfd;  
-               
-      req_resp_pool.conns[i].events = POLLIN;
-      /* Add the descriptor to descriptor set */
-      break;
-    }
-  }
-
-  if (i > req_resp_pool.maxi)      
-      req_resp_pool.maxi = i;   
-
-  if (i == OPEN_MAX) {
-    /* Couldn't find an empty slot */
-    LoggerFactory::getLogger()->error(errno, "add_client error: Too many clients");
-    return -1;
-  }
-
-  
-  return connfd;
+/**
+ * 寮哄埗缁戝畾绔彛鍒皊ocket, 閫傜敤浜庣▼搴忛潪姝e父鍏抽棴鐨勬儏鍐典笅锛岄噸鍚▼搴忕粦瀹氬師鏉ヨ繕娌¢噴鏀剧殑key
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int NetModSocket::force_bind( int port) {
+  return shmModSocket.force_bind(port);
 }
-
-void NetModSocket::close_connect(int connfd) {
-  int i;
-  char mapKey[256];
-  std::map<std::string, int>::iterator map_iter;
-  if(close(connfd) != 0) {
-    LoggerFactory::getLogger()->error(errno, "NetModSocket::close_connect close");
-  }
- 
-
-  for (i = 0; i <= req_resp_pool.maxi; i++) {
-    if(req_resp_pool.conns[i].fd == connfd) {
-      req_resp_pool.conns[i].fd = -1;
-    }
-  }
-
-  for ( map_iter = req_resp_pool.connectionMap.begin(); map_iter != req_resp_pool.connectionMap.end(); ) {
-    if(connfd == map_iter->second) {
-// std::cout << "map_iter->first==" << map_iter->first << std::endl;
-     map_iter = req_resp_pool.connectionMap.erase(map_iter);
-    } else {
-      ++map_iter;
-    }
-  }
-
-  LoggerFactory::getLogger()->debug( "closed %d\n", connfd);
-
-}
-
 
 int NetModSocket::sendandrecv(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
   net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) {
+  _sendandrecv_(node_arr,  arrlen, send_buf,send_size, recv_arr, recv_arr_size, -1);
+}
+int NetModSocket::sendandrecv_timout(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int  timeout) {
+  _sendandrecv_(node_arr,  arrlen, send_buf,send_size, recv_arr, recv_arr_size, timeout);
+}
+int NetModSocket::sendandrecv_nowait(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) {
+   _sendandrecv_(node_arr,  arrlen, send_buf,send_size, recv_arr, recv_arr_size, 0);
+
+}
+
+int NetModSocket::_sendandrecv_(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int  timeout = 5 * 1000) {
 
   int i, n, recv_size,  connfd;
   net_node_t *node;
   void *recv_buf;
-  int  timeout = 5 * 1000;
+  
   net_mod_request_head_t request_head = {};
  
   int n_req = 0, n_recv_suc = 0, n_resp;
@@ -240,82 +178,6 @@
      
 }
 
-int NetModSocket::write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size) {
- 
-  int buf_size;
-  char *buf;
-  int  max_buf_size;
-  if((buf = (char *)malloc(MAXBUF)) == NULL) {
-    LoggerFactory::getLogger()->error(errno, "NetModSocket::NetModSocket malloc");
-    exit(1);
-  } else {
-    max_buf_size = MAXBUF;
-  }
-
-  buf_size = send_size + NET_MODE_REQUEST_HEAD_LENGTH;
-  if(max_buf_size < buf_size) {
-    
-    if((buf = (char *)realloc(buf, buf_size)) == NULL) {
-      LoggerFactory::getLogger()->error(errno, "NetModSocket::write_request  realloc buf");
-      exit(1);
-    } else {
-      max_buf_size = buf_size;
-    }
-  }
-
-  memcpy(buf, NetModSocket::encode_request_head(request_head), NET_MODE_REQUEST_HEAD_LENGTH);
-  memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH, send_buf, send_size);
-
-  if(rio_writen(clientfd, buf, buf_size) != buf_size ) {
-    LoggerFactory::getLogger()->error(errno, "NetModSocket::write_request  rio_writen");
-    free(buf);
-    return -1;
-  }
-  free(buf);
-  return 0;
-}
-
-/**
- * @return 0 鎴愬姛, 1 瀵规柟娌℃湁瀵瑰簲鐨刱ey, -1 缃戠粶閿欒
- *
- */
-int NetModSocket::read_response(int connfd, net_mod_recv_msg_t *recv_msg) {
-  int recv_size;
-  void *recv_buf;
-  char response_head_bs[NET_MODE_RESPONSE_HEAD_LENGTH];
- 
-  net_mod_response_head_t response_head;
-  if ( rio_readn(connfd, response_head_bs, NET_MODE_RESPONSE_HEAD_LENGTH) !=  NET_MODE_RESPONSE_HEAD_LENGTH) {
-    LoggerFactory::getLogger()->error(errno, "NetModSocket::read_response  rio_readnb response_head");
-    
-    return -1;
-  }
-
-  response_head =  NetModSocket::decode_response_head(response_head_bs);
-// printf(">>>> read_response %s\n", response_head.host);
-  if(response_head.code != 0) {
-    // 瀵规柟娌℃湁瀵瑰簲鐨刱ey
-    return 1;
-  }
-
-  recv_buf = malloc(response_head.content_length);
-  if(recv_buf == NULL) {
-    LoggerFactory::getLogger()->error(errno, "NetModSocket::send malloc recv_buf");
-    exit(1);
-  }
-  if ( (recv_size = rio_readn(connfd, recv_buf, response_head.content_length) ) !=  response_head.content_length) {
-    LoggerFactory::getLogger()->error(errno, "NetModSocket::read_response  rio_readnb recv_buf");
-    
-    return -1;
-  }
-
-  strcpy( recv_msg->host, response_head.host);
-  recv_msg->port = response_head.port;
-  recv_msg->key = response_head.key;
-  recv_msg->content = recv_buf;
-  recv_msg->content_length = recv_size;
-  return 0;
-}
 
 int NetModSocket::sendandrecv_safe(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
   net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) {
@@ -508,6 +370,139 @@
   return nsuc;
 }
 
+
+/**
+ * 鍙戦�佷俊鎭�
+ * @port 鍙戦�佺粰璋�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+ */
+int NetModSocket::sendto(const void *buf, const int size, const int port){
+  return shmModSocket.sendto(buf, size,port);
+}
+
+// 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇
+int NetModSocket::sendto_timeout(const void *buf, const int size, const int port, int sec, int nsec){
+  struct timespec timeout = {sec, nsec};
+  return shmModSocket.sendto_timeout(buf, size, port, &timeout);
+}
+
+// 鍙戦�佷俊鎭珛鍒昏繑鍥炪��
+int NetModSocket::sendto_nowait(const void *buf, const int size, const int port){
+  return shmModSocket.sendto_nowait(buf, size,port);
+}
+
+/**
+ * 鎺ユ敹淇℃伅
+ * @port 浠庤皝鍝噷鏀跺埌鐨勪俊鎭�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int NetModSocket::recvfrom(void **buf, int *size, int *port) {
+  return shmModSocket.recvfrom(buf, size, port);
+}
+// 鎺ュ彈淇℃伅瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int NetModSocket::recvfrom_timeout(void **buf, int *size, int *port, int sec, int nsec){
+  struct timespec timeout = {sec, nsec};
+  return shmModSocket.recvfrom_timeout(buf, size, port, &timeout);
+}
+
+int NetModSocket::recvfrom_nowait(void **buf, int *size, int *port){
+  return shmModSocket.recvfrom_nowait(buf, size, port);
+}
+
+/**
+ * 鍙戦�佽姹備俊鎭苟绛夊緟鎺ユ敹搴旂瓟
+ * @port 鍙戦�佺粰璋�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int NetModSocket::sendandrecv( const void *send_buf, const int send_size, const int port, void **recv_buf, int *recv_size){
+  return shmModSocket.sendandrecv(send_buf, send_size, port, recv_buf, recv_size);
+}
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int NetModSocket::sendandrecv_timeout( const void *send_buf, const int send_size, const int port, void **recv_buf, int *recv_size, int sec, int nsec){
+  struct timespec timeout = {sec, nsec};
+  return shmModSocket.sendandrecv_timeout(send_buf, send_size, port, recv_buf, recv_size, &timeout);
+}
+int NetModSocket::sendandrecv_nowait( const void *send_buf, const int send_size, const int port, void **recv_buf, int *recv_size) {
+  return shmModSocket.sendandrecv_nowait(send_buf, send_size, port, recv_buf, recv_size);
+}
+
+
+/**
+ * 鍚姩bus
+ * 
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int  NetModSocket::start_bus() {
+  return shmModSocket.start_bus();
+}
+
+/**
+ * 璁㈤槄鎸囧畾涓婚
+ * @topic 涓婚
+ * @size 涓婚闀垮害
+ * @port 鎬荤嚎绔彛
+ */
+int  NetModSocket::sub( void *topic, int size, int port){
+  return shmModSocket.sub((char *)topic,  size,  port);
+}
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  NetModSocket::sub_timeout( void *topic, int size, int port, int sec, int nsec){
+  struct timespec timeout = {sec, nsec};
+  return shmModSocket.sub_timeout((char *)topic,  size,  port, &timeout);
+}
+int  NetModSocket::sub_nowait( void *topic, int size, int port){
+  return shmModSocket.sub_nowait((char *)topic,  size,  port);
+}
+
+
+
+/**
+ * 鍙栨秷璁㈤槄鎸囧畾涓婚
+ * @topic 涓婚
+ * @size 涓婚闀垮害
+ * @port 鎬荤嚎绔彛
+ */
+int  NetModSocket::desub( void *topic, int size, int port){
+  return shmModSocket.desub((char *)topic,  size,  port);
+}
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  NetModSocket::desub_timeout( void *topic, int size, int port, int sec, int nsec){
+  struct timespec timeout = {sec, nsec};
+  return shmModSocket.desub_timeout((char *)topic,  size,  port, &timeout);
+}
+int  NetModSocket::desub_nowait( void *topic, int size, int port){
+  return shmModSocket.desub_nowait((char *)topic,  size,  port);
+}
+
+
+
+/**
+ * 鍙戝竷涓婚
+ * @topic 涓婚
+ * @content 涓婚鍐呭
+ * @port 鎬荤嚎绔彛
+ */
+int  NetModSocket::pub( char *topic, int topic_size, void *content, int content_size, int port){
+  return shmModSocket.pub(topic, topic_size, content, content_size, port);
+}
+//  瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  NetModSocket::pub_timeout( char *topic, int topic_size, void *content, int content_size, int port, int sec, int nsec){
+  struct timespec timeout = {sec, nsec};
+  return shmModSocket.pub_timeout(topic, topic_size, content, content_size, port, &timeout);
+}
+int  NetModSocket::pub_nowait( char *topic, int topic_size, void *content, int content_size, int port){
+  return shmModSocket.pub_nowait(topic, topic_size, content, content_size, port);
+}
+
+
+/**
+ * 鑾峰彇soket绔彛鍙�
+ */
+int NetModSocket::get_port() {
+  return shmModSocket.get_port();
+}
+
+
 void NetModSocket::free_recv_msg_arr(net_mod_recv_msg_t * arr, size_t size) {
 
   for(int i =0; i< size; i++) {
@@ -516,6 +511,183 @@
   free(arr);
 }
 
+
+
+
+//======================================================================================
+
+
+
+int NetModSocket::write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size) {
+ 
+  int buf_size;
+  char *buf;
+  int  max_buf_size;
+  if((buf = (char *)malloc(MAXBUF)) == NULL) {
+    LoggerFactory::getLogger()->error(errno, "NetModSocket::NetModSocket malloc");
+    exit(1);
+  } else {
+    max_buf_size = MAXBUF;
+  }
+
+  buf_size = send_size + NET_MODE_REQUEST_HEAD_LENGTH;
+  if(max_buf_size < buf_size) {
+    
+    if((buf = (char *)realloc(buf, buf_size)) == NULL) {
+      LoggerFactory::getLogger()->error(errno, "NetModSocket::write_request  realloc buf");
+      exit(1);
+    } else {
+      max_buf_size = buf_size;
+    }
+  }
+
+  memcpy(buf, NetModSocket::encode_request_head(request_head), NET_MODE_REQUEST_HEAD_LENGTH);
+  memcpy(buf + NET_MODE_REQUEST_HEAD_LENGTH, send_buf, send_size);
+
+  if(rio_writen(clientfd, buf, buf_size) != buf_size ) {
+    LoggerFactory::getLogger()->error(errno, "NetModSocket::write_request  rio_writen");
+    free(buf);
+    return -1;
+  }
+  free(buf);
+  return 0;
+}
+
+/**
+ * @return 0 鎴愬姛, 1 瀵规柟娌℃湁瀵瑰簲鐨刱ey, -1 缃戠粶閿欒
+ *
+ */
+int NetModSocket::read_response(int connfd, net_mod_recv_msg_t *recv_msg) {
+  int recv_size;
+  void *recv_buf;
+  char response_head_bs[NET_MODE_RESPONSE_HEAD_LENGTH];
+ 
+  net_mod_response_head_t response_head;
+  if ( rio_readn(connfd, response_head_bs, NET_MODE_RESPONSE_HEAD_LENGTH) !=  NET_MODE_RESPONSE_HEAD_LENGTH) {
+    LoggerFactory::getLogger()->error(errno, "NetModSocket::read_response  rio_readnb response_head");
+    
+    return -1;
+  }
+
+  response_head =  NetModSocket::decode_response_head(response_head_bs);
+// printf(">>>> read_response %s\n", response_head.host);
+  if(response_head.code != 0) {
+    // 瀵规柟娌℃湁瀵瑰簲鐨刱ey
+    return 1;
+  }
+
+  recv_buf = malloc(response_head.content_length);
+  if(recv_buf == NULL) {
+    LoggerFactory::getLogger()->error(errno, "NetModSocket::send malloc recv_buf");
+    exit(1);
+  }
+  if ( (recv_size = rio_readn(connfd, recv_buf, response_head.content_length) ) !=  response_head.content_length) {
+    LoggerFactory::getLogger()->error(errno, "NetModSocket::read_response  rio_readnb recv_buf");
+    
+    return -1;
+  }
+
+  strcpy( recv_msg->host, response_head.host);
+  recv_msg->port = response_head.port;
+  recv_msg->key = response_head.key;
+  recv_msg->content = recv_buf;
+  recv_msg->content_length = recv_size;
+  return 0;
+}
+
+
+
+
+void  NetModSocket::init_req_rep_req_resp_pool()
+{
+  /* Initially, there are no connected descriptors */
+  int i;
+  req_resp_pool.maxi = -1;                   //line:conc:echoservers:beginempty
+  for (i = 0; i < OPEN_MAX; i++) {
+    req_resp_pool.conns[i].fd = -1; 
+    req_resp_pool.conns[i].events = 0;      
+  }
+
+}
+
+int NetModSocket::connect( net_node_t *node) {
+  std::map<std::string, int>::iterator mapIter;
+  int connfd;
+  int i;
+  char mapKey[256];
+  char portstr[32];
+
+  sprintf(mapKey, "%s:%d", node->host, node->port);
+  mapIter =  req_resp_pool.connectionMap.find(mapKey);
+  if( mapIter != req_resp_pool.connectionMap.end()) {
+    connfd = mapIter->second;
+// printf("hit: %s\n", mapKey);
+  } else {
+// printf("mis: %s\n", mapKey);     
+    sprintf(portstr, "%d", node->port);
+// printf("open before: %s\n", mapKey); 
+    connfd = open_clientfd(node->host, portstr);
+// printf("open after: %s\n", mapKey); 
+    if(connfd < 0) {
+      LoggerFactory::getLogger()->error(errno, "connect %s:%d ", node->host, node->port);
+      return -1;
+    }
+    req_resp_pool.connectionMap.insert({mapKey, connfd});
+  }
+
+  
+  for (i = 0; i < OPEN_MAX; i++) { /* Find an available slot */
+    if (req_resp_pool.conns[i].fd < 0)
+    {
+      /* Add connected descriptor to the req_resp_pool */
+      req_resp_pool.conns[i].fd = connfd;  
+               
+      req_resp_pool.conns[i].events = POLLIN;
+      /* Add the descriptor to descriptor set */
+      break;
+    }
+  }
+
+  if (i > req_resp_pool.maxi)      
+      req_resp_pool.maxi = i;   
+
+  if (i == OPEN_MAX) {
+    /* Couldn't find an empty slot */
+    LoggerFactory::getLogger()->error(errno, "add_client error: Too many clients");
+    return -1;
+  }
+
+  
+  return connfd;
+}
+
+void NetModSocket::close_connect(int connfd) {
+  int i;
+  char mapKey[256];
+  std::map<std::string, int>::iterator map_iter;
+  if(close(connfd) != 0) {
+    LoggerFactory::getLogger()->error(errno, "NetModSocket::close_connect close");
+  }
+ 
+
+  for (i = 0; i <= req_resp_pool.maxi; i++) {
+    if(req_resp_pool.conns[i].fd == connfd) {
+      req_resp_pool.conns[i].fd = -1;
+    }
+  }
+
+  for ( map_iter = req_resp_pool.connectionMap.begin(); map_iter != req_resp_pool.connectionMap.end(); ) {
+    if(connfd == map_iter->second) {
+// std::cout << "map_iter->first==" << map_iter->first << std::endl;
+     map_iter = req_resp_pool.connectionMap.erase(map_iter);
+    } else {
+      ++map_iter;
+    }
+  }
+
+  LoggerFactory::getLogger()->debug( "closed %d\n", connfd);
+
+}
 /**
   uint32_t mod;
   char host[NI_MAXHOST];
diff --git a/src/socket/net_mod_socket.h b/src/socket/net_mod_socket.h
index 0988f1b..80e98cc 100644
--- a/src/socket/net_mod_socket.h
+++ b/src/socket/net_mod_socket.h
@@ -87,23 +87,52 @@
   int read_response(int clientfd, net_mod_recv_msg_t *recv_msg);
   int write_request(int clientfd, net_mod_request_head_t &request_head, void *send_buf, int send_size);
 
+  int _sendandrecv_(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, 
+    net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout);
 
 public:
 	
   NetModSocket();
   ~NetModSocket();
 
+
   /**
+   * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓�
+   * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+  */
+  int bind( int port);
+
+  /**
+   * 寮哄埗缁戝畾绔彛鍒皊ocket, 閫傜敤浜庣▼搴忛潪姝e父鍏抽棴鐨勬儏鍐典笅锛岄噸鍚▼搴忕粦瀹氬師鏉ヨ繕娌¢噴鏀剧殑key
+   * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+  */
+  int force_bind( int port);
+
+  /**
+   * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅浼氫竴鐩寸瓑寰�
    * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂閫佽姹傛秷鎭紝鑺傜偣鐨勮繑鍥炰俊鎭眹鎬诲苟瀛樺偍鍦╮ecv_arr涓�
    * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
    * @send_buf 鍙戦�佺殑娑堟伅锛孈send_size 璇ユ秷鎭綋鐨勯暱搴�
    * @recv_arr 杩斿洖鐨勫簲绛旀秷鎭粍锛孈recv_arr_size 璇ユ暟缁勯暱搴�
    * @return 鎴愬姛鍙戦�佺殑鑺傜偣鐨勪釜鏁�
-   * 浼樼偣锛氭棤闃诲锛屾�ц兘濂�
-   * 缂虹偣锛氫笉鏄嚎绋嬪畨鍏ㄧ殑
+   * 浼樼偣锛�1鏌愪釜鑺傜偣鐨勬晠闅滀笉浼氶樆濉炲叾浠栬妭鐐广��2鎬ц兘濂�
+   * 缂虹偣锛氫笉鏄嚎绋嬪畨鍏ㄧ殑, 鍗充笉鑳芥湁涓や釜浠ヤ笂鐨勭嚎绋嬪悓鏃朵娇鐢ㄨ繖涓璞$殑鏂规硶
    */
-  int sendandrecv(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, 
-  	net_mod_recv_msg_t ** recv_arr, int *recv_arr_size);
+  int sendandrecv(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+    net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ;
+  /**
+   * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅绛夊緟timeout鐨勬椂闂村悗杩斿洖
+   * @timeout 绛夊緟鏃堕棿锛屽崟浣嶆槸鍗冨垎涔嬩竴绉�
+  */
+  int sendandrecv_timout(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+    net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int  timeout);
+
+  /**
+   * 涓嶇瓑寰呯珛鍗宠繑鍥�
+   * @timeout 绛夊緟鏃堕棿锛屽崟浣嶆槸鍗冨垎涔嬩竴绉�
+  */
+  int sendandrecv_nowait(net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+    net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ;
 
   /**
    * 鍔熻兘鍚宻endandrecv
@@ -114,13 +143,86 @@
   int sendandrecv_safe(net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, 
     net_mod_recv_msg_t ** recv_arr, int *recv_arr_size);
 
-  /**
-   * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 
-   * @arr 娑堟伅缁�
-   * @size 娑堟伅缁勭殑闀垮害
-   */
-  static void  free_recv_msg_arr(net_mod_recv_msg_t * arr, size_t size);
+ 
 
+
+
+
+  /**
+   * 鍙戦�佷俊鎭�
+   * @port 鍙戦�佺粰璋�
+   * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+   */
+  int sendto( const void *buf, const int size, const int port);
+  // 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇
+  int sendto_timeout( const void *buf, const int size, const int port, int sec, int nsec);
+  // 鍙戦�佷俊鎭珛鍒昏繑鍥炪��
+  int sendto_nowait( const void *buf, const int size, const int port);
+
+  /**
+   * 鎺ユ敹淇℃伅
+   * @port 浠庤皝鍝噷鏀跺埌鐨勪俊鎭�
+   * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+  */
+  int recvfrom( void **buf, int *size, int *port);
+  // 鎺ュ彈淇℃伅瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+  int recvfrom_timeout( void **buf, int *size, int *port, int sec, int nsec);
+  int recvfrom_nowait( void **buf, int *size, int *port);
+
+  /**
+   * 鏈湴鍙戦�佽姹備俊鎭苟绛夊緟鎺ユ敹搴旂瓟
+   * @port 鍙戦�佺粰璋�
+   * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+  */
+  int sendandrecv( const void *send_buf, const int send_size, const int send_port, void **recv_buf, int *recv_size) ;
+  // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+  int sendandrecv_timeout( const void *send_buf, const int send_size, const int send_port, void **recv_buf, int *recv_size, int sec, int nsec) ;
+  int sendandrecv_nowait( const void *send_buf, const int send_size, const int send_port, void **recv_buf, int *recv_size) ;
+
+
+  /**
+   * 鍚姩bus
+   * 
+   * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+  */
+  int  start_bus();
+
+  /**
+   * 璁㈤槄鎸囧畾涓婚
+   * @topic 涓婚
+   * @size 涓婚闀垮害
+   * @port 鎬荤嚎绔彛
+   */
+  int  sub( void *topic, int size, int port);
+  // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+  int  sub_timeout( void *topic, int size, int port, int sec, int nsec);
+  int  sub_nowait( void *topic, int size, int port);
+
+
+  /**
+   * 鍙栨秷璁㈤槄鎸囧畾涓婚
+   * @topic 涓婚,涓婚涓虹┖鏃跺彇娑堝叏閮ㄨ闃�
+   * @size 涓婚闀垮害
+   * @port 鎬荤嚎绔彛
+   */
+  int  desub( void *topic, int size, int port);
+  // 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+  int  desub_timeout( void *topic, int size, int port, int sec, int nsec);
+  int  desub_nowait( void *topic, int size, int port);
+
+  /**
+   * 鍙戝竷涓婚
+   * @topic 涓婚
+   * @content 涓婚鍐呭
+   * @port 鎬荤嚎绔彛
+   */
+  int  pub( char *topic, int topic_size, void *content, int content_size, int port);
+  //  瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+  int  pub_timeout( char *topic, int topic_size, void *content, int content_size, int port, int sec, int nsec);
+  int  pub_nowait( char *topic, int topic_size, void *content, int content_size, int port);
+
+
+  
    /**
    * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭�
    * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
@@ -129,6 +231,18 @@
    * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟
    */
   int pub(net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size);
+
+  /**
+   * 鑾峰彇soket绔彛鍙�
+   */
+  int get_port() ;
+
+   /**
+   * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 
+   * @arr 娑堟伅缁�
+   * @size 娑堟伅缁勭殑闀垮害
+   */
+  static void free_recv_msg_arr(net_mod_recv_msg_t * arr, size_t size);
  
 
 };
diff --git a/src/socket/net_mod_socket_io.c b/src/socket/net_mod_socket_io.c
index 631d30a..8981690 100644
--- a/src/socket/net_mod_socket_io.c
+++ b/src/socket/net_mod_socket_io.c
@@ -2,14 +2,13 @@
 #include "socket_io.h"
 #include <stdint.h> 
 
-ssize_t rio_readpkgb(rio_t *rp, char *usrbuf, size_t maxlen)
+ssize_t rio_read_until_sep(rio_t *rp, char *usrbuf, size_t maxlen, const char *sep)
 {
   int n, rc;
   char c;
   char *bufp = usrbuf;
-  int pkg_sep_i = 0;
-  int pkg_sep_len = strlen(PKG_SEP);
-  const char * pkg_sep = PKG_SEP;
+  int sep_i = 0;
+  int sep_len = strlen(sep);
 
   for (n = 0; n < maxlen; n++)
   {
@@ -18,15 +17,15 @@
       
       *bufp++ = c;
       
-      if(c == *(pkg_sep + pkg_sep_i)) {
-        pkg_sep_i++;
-        if(pkg_sep_i == pkg_sep_len) {
+      if(c == *(sep + sep_i)) {
+        sep_i++;
+        if(sep_i == sep_len) {
              
           break;
         } 
       } else {
 
-        pkg_sep_i = 0;
+        sep_i = 0;
       }
 
     }
@@ -41,9 +40,9 @@
       return -1;    /* Error */
   }
 
-  if(pkg_sep_i == pkg_sep_len) {
-    *(bufp - pkg_sep_len) = 0;
-    return n - pkg_sep_len;
+  if(sep_i == sep_len) {
+    *(bufp - sep_len) = 0;
+    return n - sep_len;
   } else {
     return -1;
   }
diff --git a/src/socket/net_mod_socket_io.h b/src/socket/net_mod_socket_io.h
index 7b41b04..201908b 100644
--- a/src/socket/net_mod_socket_io.h
+++ b/src/socket/net_mod_socket_io.h
@@ -5,7 +5,7 @@
 
 #define PKG_SEP "\r\n\r\n"
 
-ssize_t rio_readpkgb(rio_t *rp, char *usrbuf, size_t maxlen);
+ssize_t rio_read_until_sep(rio_t *rp, char *usrbuf, size_t maxlen, char * sep);
 int is_little_endian();
 void swap_bytes(void *pv, size_t n);
 uint16_t swap_uint16( uint16_t val ) ;
diff --git a/src/socket/net_mod_socket_wrapper.c b/src/socket/net_mod_socket_wrapper.c
index a0e052f..6776b36 100644
--- a/src/socket/net_mod_socket_wrapper.c
+++ b/src/socket/net_mod_socket_wrapper.c
@@ -1,4 +1,8 @@
 #include "net_mod_socket_wrapper.h"
+
+
+
+
 /**
  * 鍒涘缓
  */
@@ -11,24 +15,189 @@
 /**
  * 鍏抽棴
  */
-void net_mod_socket_close(void *_sockt) {
-	net_mod_socket_t *sockt = (net_mod_socket_t *)_sockt;
+void net_mod_socket_close(void *_socket) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
 	delete sockt->sockt;
 	free(sockt);
 }
+ 
+
 
 /**
+ * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int net_mod_socket_bind(void * _socket, int port){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->bind(port);
+}
+
+/**
+ * 寮哄埗缁戝畾绔彛鍒皊ocket, 閫傜敤浜庣▼搴忛潪姝e父鍏抽棴鐨勬儏鍐典笅锛岄噸鍚▼搴忕粦瀹氬師鏉ヨ繕娌¢噴鏀剧殑key
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int net_mod_socket_force_bind(void * _socket, int port) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->force_bind(port);
+}
+/**
+ * 鍙戦�佷俊鎭�
+ * @port 鍙戦�佺粰璋�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+ */
+int net_mod_socket_sendto(void *_socket, const void *buf, const int size, const int port) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sendto(buf, size, port);
+}
+// 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇
+int net_mod_socket_sendto_timeout(void *_socket, const void *buf, const int size, const int port, int sec, int nsec){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sendto_timeout(buf, size, port, sec, nsec);
+}
+// 鍙戦�佷俊鎭珛鍒昏繑鍥炪��
+int net_mod_socket_sendto_nowait(void *_socket, const void *buf, const int size, const int port){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sendto_nowait(buf, size, port);
+}
+
+/**
+ * 鎺ユ敹淇℃伅
+ * @port 浠庤皝鍝噷鏀跺埌鐨勪俊鎭�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int net_mod_socket_recvfrom(void *_socket, void **buf, int *size, int *port){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->recvfrom(buf, size, port);
+}
+// 鎺ュ彈淇℃伅瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int net_mod_socket_recvfrom_timeout(void *_socket, void **buf, int *size, int *port, int sec, int nsec){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->recvfrom_timeout(buf, size, port, sec, nsec);
+}
+int net_mod_socket_recvfrom_nowait(void *_socket, void **buf, int *size, int *port){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->recvfrom_nowait(buf, size, port);
+}
+
+
+  
+/**
+ * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅浼氫竴鐩寸瓑寰�
  * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂閫佽姹傛秷鎭紝鑺傜偣鐨勮繑鍥炰俊鎭眹鎬诲苟瀛樺偍鍦╮ecv_arr涓�
  * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
  * @send_buf 鍙戦�佺殑娑堟伅锛孈send_size 璇ユ秷鎭綋鐨勯暱搴�
  * @recv_arr 杩斿洖鐨勫簲绛旀秷鎭粍锛孈recv_arr_size 璇ユ暟缁勯暱搴�
  * @return 鎴愬姛鍙戦�佺殑鑺傜偣鐨勪釜鏁�
+ * 浼樼偣锛�1鏌愪釜鑺傜偣鐨勬晠闅滀笉浼氶樆濉炲叾浠栬妭鐐广��2鎬ц兘濂�
+ * 缂虹偣锛氫笉鏄嚎绋嬪畨鍏ㄧ殑, 鍗充笉鑳芥湁涓や釜浠ヤ笂鐨勭嚎绋嬪悓鏃朵娇鐢ㄨ繖涓璞$殑鏂规硶
  */
-int net_mod_socket_sendandrecv(void *_sockt, net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, 
-	net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) {
-	net_mod_socket_t *sockt = (net_mod_socket_t *)_sockt;
-	return sockt->sockt->sendandrecv(node_arr, node_arr_len, send_buf, send_size, recv_arr, recv_arr_size);
+int net_mod_socket_sendandrecv(void *_socket, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sendandrecv(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size);
 }
+/**
+ * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅绛夊緟timeout鐨勬椂闂村悗杩斿洖
+ * @timeout 绛夊緟鏃堕棿锛屽崟浣嶆槸鍗冨垎涔嬩竴绉�
+*/
+int net_mod_socket_sendandrecv_timout(void *_socket, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int  timeout){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sendandrecv_timout(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size, timeout);
+}
+
+int net_mod_socket_sendandrecv_nowait(void *_socket, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sendandrecv_nowait(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size);
+}
+
+ 
+
+ /**
+ * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭�
+ * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
+ * @topic 涓婚锛孈topic_size 璇ヤ富棰樼殑闀垮害
+ * @content 鍐呭锛孈content_size 鍐呭闀垮害
+ * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟
+ */
+int net_mod_socket_pub(void *_socket, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->pub(node_arr, node_arr_len, topic, topic_size, content, content_size);
+}
+
+
+
+/**
+ * 鍚姩bus
+ * 
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int  net_mod_socket_start_bus(void * _socket) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->start_bus();
+}
+
+/**
+ * 璁㈤槄鎸囧畾涓婚
+ * @topic 涓婚
+ * @size 涓婚闀垮害
+ * @port 鎬荤嚎绔彛
+ */
+int  net_mod_socket_sub(void * _socket, void *topic, int size, int port) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sub((char *)topic,  size,  port);
+}
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  net_mod_socket_sub_timeout(void * _socket, void *topic, int size, int port, int sec, int nsec){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sub_timeout((char *)topic,  size,  port, sec, nsec);
+}
+int  net_mod_socket_sub_nowait(void * _socket, void *topic, int size, int port){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->sub_nowait((char *)topic,  size,  port);
+}
+
+
+/**
+ * 鍙栨秷璁㈤槄鎸囧畾涓婚
+ * @topic 涓婚,涓婚涓虹┖鏃跺彇娑堝叏閮ㄨ闃�
+ * @size 涓婚闀垮害
+ * @port 鎬荤嚎绔彛
+ */
+int  net_mod_socket_desub(void * _socket, void *topic, int size, int port) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->desub((char *)topic,  size,  port);
+}
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  net_mod_socket_desub_timeout(void * _socket, void *topic, int size, int port, int sec, int nsec) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->desub_timeout((char *)topic,  size,  port, sec, nsec);
+}
+int  net_mod_socket_desub_nowait(void * _socket, void *topic, int size, int port){
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->desub_nowait((char *)topic,  size,  port);
+}
+
+
+
+/**
+ * 鑾峰彇soket绔彛鍙�
+ */
+int net_mod_socket_get_port(void * _socket) {
+	net_mod_socket_t *sockt = (net_mod_socket_t *)_socket;
+	return sockt->sockt->get_port();
+}
+
+
+/**
+ * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡uf
+ */
+void net_mod_socket_free(void *buf) {
+	free(buf);
+}
+
+
 
 /**
  * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 
@@ -38,16 +207,4 @@
 void  net_mod_socket_free_recv_msg_arr(net_mod_recv_msg_t * arr, int len) {
 	 
 	return NetModSocket::free_recv_msg_arr(arr, len);
-}
-
- /**
- * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭�
- * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
- * @topic 涓婚锛孈topic_size 璇ヤ富棰樼殑闀垮害
- * @content 鍐呭锛孈content_size 鍐呭闀垮害
- * @return 鎴愬姛鍙戝竷鐨勮妭鐐圭殑涓暟
- */
-int net_mod_socket_pub(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size) {
-	net_mod_socket_t *sockt = (net_mod_socket_t *)_sockt;
-	return sockt->sockt->pub(node_arr, node_arr_len, topic, topic_size, content, content_size);
 }
diff --git a/src/socket/net_mod_socket_wrapper.h b/src/socket/net_mod_socket_wrapper.h
index 9e135fb..1a15003 100644
--- a/src/socket/net_mod_socket_wrapper.h
+++ b/src/socket/net_mod_socket_wrapper.h
@@ -22,23 +22,68 @@
  */
 void net_mod_socket_close(void *_sockt);
 
-  /**
-   * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂閫佽姹傛秷鎭紝鑺傜偣鐨勮繑鍥炰俊鎭眹鎬诲苟瀛樺偍鍦╮ecv_arr涓�
-   * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
-   * @send_buf 鍙戦�佺殑娑堟伅锛孈send_size 璇ユ秷鎭綋鐨勯暱搴�
-   * @recv_arr 杩斿洖鐨勫簲绛旀秷鎭粍锛孈recv_arr_size 璇ユ暟缁勯暱搴�
-   * @return 鎴愬姛鍙戦�佺殑鑺傜偣鐨勪釜鏁�
-   * 璇ユ柟娉曚笉鏄嚎绋嬪畨鍏ㄧ殑锛屼笉鑳芥湁澶氫釜绾跨▼鍚屾椂浣跨敤涓�涓猻ocket
-   */
-int net_mod_socket_sendandrecv(void *_sockt, net_node_t *node_arr, int node_arr_len, void *send_buf, int send_size, 
-	net_mod_recv_msg_t ** recv_arr, int *recv_arr_size);
+
 
 /**
- * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 
- * @arr 娑堟伅缁�
- * @size 娑堟伅缁勭殑闀垮害
+ * 缁戝畾绔彛鍒皊ocket, 濡傛灉涓嶇粦瀹氬垯绯荤粺鑷姩鍒嗛厤涓�涓�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int net_mod_socket_bind(void * _socket, int port);
+
+/**
+ * 寮哄埗缁戝畾绔彛鍒皊ocket, 閫傜敤浜庣▼搴忛潪姝e父鍏抽棴鐨勬儏鍐典笅锛岄噸鍚▼搴忕粦瀹氬師鏉ヨ繕娌¢噴鏀剧殑key
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int net_mod_socket_force_bind(void * _socket, int port);
+/**
+ * 鍙戦�佷俊鎭�
+ * @port 鍙戦�佺粰璋�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
  */
-void  net_mod_socket_free_recv_msg_arr(net_mod_recv_msg_t * arr, int size);
+int net_mod_socket_sendto(void *_socket, const void *buf, const int size, const int port);
+// 鍙戦�佷俊鎭秴鏃惰繑鍥炪�� @sec 绉� 锛� @nsec 绾崇
+int net_mod_socket_sendto_timeout(void *_socket, const void *buf, const int size, const int port, int sec, int nsec);
+// 鍙戦�佷俊鎭珛鍒昏繑鍥炪��
+int net_mod_socket_sendto_nowait(void *_socket, const void *buf, const int size, const int port);
+
+/**
+ * 鎺ユ敹淇℃伅
+ * @port 浠庤皝鍝噷鏀跺埌鐨勪俊鎭�
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int net_mod_socket_recvfrom(void *_socket, void **buf, int *size, int *port);
+// 鎺ュ彈淇℃伅瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int net_mod_socket_recvfrom_timeout(void *_socket, void **buf, int *size, int *port, int sec, int nsec);
+int net_mod_socket_recvfrom_nowait(void *_socket, void **buf, int *size, int *port);
+
+
+  
+/**
+ * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅浼氫竴鐩寸瓑寰�
+ * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂閫佽姹傛秷鎭紝鑺傜偣鐨勮繑鍥炰俊鎭眹鎬诲苟瀛樺偍鍦╮ecv_arr涓�
+ * @node_arr 缃戠粶鑺傜偣缁�, @node_arr_len璇ユ暟缁勯暱搴�
+ * @send_buf 鍙戦�佺殑娑堟伅锛孈send_size 璇ユ秷鎭綋鐨勯暱搴�
+ * @recv_arr 杩斿洖鐨勫簲绛旀秷鎭粍锛孈recv_arr_size 璇ユ暟缁勯暱搴�
+ * @return 鎴愬姛鍙戦�佺殑鑺傜偣鐨勪釜鏁�
+ * 浼樼偣锛�1鏌愪釜鑺傜偣鐨勬晠闅滀笉浼氶樆濉炲叾浠栬妭鐐广��2鎬ц兘濂�
+ * 缂虹偣锛氫笉鏄嚎绋嬪畨鍏ㄧ殑, 鍗充笉鑳芥湁涓や釜浠ヤ笂鐨勭嚎绋嬪悓鏃朵娇鐢ㄨ繖涓璞$殑鏂规硶
+ */
+int net_mod_socket_sendandrecv(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ;
+/**
+ * 濡傛灉寤虹珛杩炴帴鐨勮妭鐐规病鏈夋帴鍙楀埌娑堟伅绛夊緟timeout鐨勬椂闂村悗杩斿洖
+ * @timeout 绛夊緟鏃堕棿锛屽崟浣嶆槸鍗冨垎涔嬩竴绉�
+*/
+int net_mod_socket_sendandrecv_timout(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int  timeout);
+
+/**
+ * 涓嶇瓑寰呯珛鍗宠繑鍥�
+*/
+int net_mod_socket_sendandrecv_nowait(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, 
+  net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ;
+
+
 
  /**
  * 鍚憂ode_arr 涓殑鎵�鏈夌綉缁滆妭鐐瑰彂甯冩秷鎭�
@@ -50,6 +95,59 @@
 int net_mod_socket_pub(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size);
 
 
+
+/**
+ * 鍚姩bus
+ * 
+ * @return 0 鎴愬姛锛� 鍏朵粬鍊� 澶辫触鐨勯敊璇爜
+*/
+int  net_mod_socket_start_bus(void * _socket);
+
+/**
+ * 璁㈤槄鎸囧畾涓婚
+ * @topic 涓婚
+ * @size 涓婚闀垮害
+ * @port 鎬荤嚎绔彛
+ */
+int  net_mod_socket_sub(void * _socket, void *topic, int size, int port);
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  net_mod_socket_sub_timeout(void * _socket, void *topic, int size, int port, int sec, int nsec);
+int  net_mod_socket_sub_nowait(void * _socket, void *topic, int size, int port);
+
+
+/**
+ * 鍙栨秷璁㈤槄鎸囧畾涓婚
+ * @topic 涓婚,涓婚涓虹┖鏃跺彇娑堝叏閮ㄨ闃�
+ * @size 涓婚闀垮害
+ * @port 鎬荤嚎绔彛
+ */
+int  net_mod_socket_desub(void * _socket, void *topic, int size, int port);
+// 瓒呮椂杩斿洖銆� @sec 绉� 锛� @nsec 绾崇
+int  net_mod_socket_desub_timeout(void * _socket, void *topic, int size, int port, int sec, int nsec);
+int  net_mod_socket_desub_nowait(void * _socket, void *topic, int size, int port);
+
+
+
+/**
+ * 鑾峰彇soket绔彛鍙�
+ */
+int net_mod_socket_get_port(void * _socket) ;
+
+
+
+/**
+ * 閿�姣乻endandrecv鏂规硶杩斿洖鐨勬秷鎭粍 
+ * @arr 娑堟伅缁�
+ * @size 娑堟伅缁勭殑闀垮害
+ */
+void  net_mod_socket_free_recv_msg_arr(net_mod_recv_msg_t * arr, int size);
+
+
+/**
+ * 閲婃斁瀛樺偍鎺ユ敹淇℃伅鐨刡uf
+ */
+void net_mod_socket_free(void *buf) ;
+
 #ifdef __cplusplus
 }
 #endif

--
Gitblit v1.8.0