wangzhengquan
2021-02-05 607ac3ae8bfc017e10a7907e69dcbc3ab2a0fb63
src/net/net_mod_socket_wrapper.cpp
@@ -20,6 +20,11 @@
   delete sockt;
}
 
int net_mod_socket_stop(void *_socket) {
   NetModSocket *sockt = (NetModSocket *)_socket;
   return sockt->stop();
}
/**
 * 绑定端口到socket, 如果不绑定则系统自动分配一个
 * @return 0 成功, 其他值 失败的错误码
@@ -36,6 +41,7 @@
int net_mod_socket_force_bind(void * _socket, int key) {
   NetModSocket *sockt = (NetModSocket *)_socket;
   return sockt->force_bind(key);
   // return sockt->bind(key);
}
/**
@@ -53,6 +59,7 @@
   NetModSocket *sockt = (NetModSocket *)_socket;
   logger->debug("net_mod_socket_sendto: %d sendto  %d", net_mod_socket_get_key(_socket), key);
   return sockt->sendto_timeout(buf, size, key, sec, nsec);
   // return sockt->sendto(buf, size, key);
}
// 发送信息立刻返回。
int net_mod_socket_sendto_nowait(void *_socket, const void *buf, const int size, const int key){
@@ -75,12 +82,14 @@
   logger->debug(" %d net_mod_socket_recvfrom after. rv = %d", net_mod_socket_get_key(_socket), rv);
   return rv;
}
// 接受信息超时返回。 @sec 秒 , @nsec 纳秒
int net_mod_socket_recvfrom_timeout(void *_socket, void **buf, int *size, int *key, int sec, int nsec){
   NetModSocket *sockt = (NetModSocket *)_socket;
   //return sockt->recvfrom(buf, size, key);
   // return sockt->recvfrom(buf, size, key);
   return sockt->recvfrom_timeout(buf, size, key, sec, nsec);
}
int net_mod_socket_recvfrom_nowait(void *_socket, void **buf, int *size, int *key){
   NetModSocket *sockt = (NetModSocket *)_socket;
   return sockt->recvfrom_nowait(buf, size, key);
@@ -91,6 +100,7 @@
   NetModSocket *sockt = (NetModSocket *)_socket;
   return sockt->sendandrecv(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size);
}
/**
 * 如果建立连接的节点没有接受到消息等待timeout的时间后返回
 * @timeout 等待时间,单位是千分之一秒
@@ -98,6 +108,7 @@
int net_mod_socket_sendandrecv_timeout(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){
   NetModSocket *sockt = (NetModSocket *)_socket;
   // return sockt->sendandrecv(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size);
   return sockt->sendandrecv_timeout(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size, timeout);
}
@@ -107,7 +118,25 @@
   return sockt->sendandrecv_nowait(node_arr,  arrlen, send_buf,  send_size, recv_arr, recv_arr_size);
}
int net_mod_socket_recvandsend(void *_socket, recvandsend_callback_wrapper_fn callback, void * user_data) {
  NetModSocket *sockt = (NetModSocket *)_socket;
  return sockt->recvandsend(  callback, NULL, 0, user_data);
}
int net_mod_socket_recvandsend_timeout(void *_socket, recvandsend_callback_wrapper_fn callback,
                                       int sec, int nsec, void * user_data) {
  NetModSocket *sockt = (NetModSocket *)_socket;
  struct timespec timeout = {sec, nsec};
  return sockt->recvandsend(  callback, &timeout, BUS_TIMEOUT_FLAG, user_data);
}
int net_mod_socket_recvandsend_nowait(void *_socket,  recvandsend_callback_wrapper_fn callback, void * user_data) {
  NetModSocket *sockt = (NetModSocket *)_socket;
  return sockt->recvandsend(  callback, NULL, BUS_NOWAIT_FLAG, user_data);
}
 /**
 * 向node_arr 中的所有网络节点发布消息