wangzhengquan
2021-01-25 c46be6db32872bfd7c4010b43526b5e6bc0fa6a5
src/socket/shm_mod_socket.cpp
@@ -47,11 +47,11 @@
}
// 发送信息超时返回。 @sec 秒 , @nsec 纳秒
int ShmModSocket::sendto_timeout(const void *buf, const int size, const int key, const struct timespec *timeout) {
   return shm_sendto(shm_socket, buf, size, key, timeout, 0);
   return shm_sendto(shm_socket, buf, size, key, timeout, BUS_TIMEOUT_FLAG);
}
// 发送信息立刻返回。
int ShmModSocket::sendto_nowait( const void *buf, const int size, const int key){
   return shm_sendto(shm_socket, buf, size, key, NULL, (int)BUS_NOWAIT_FLAG);
   return shm_sendto(shm_socket, buf, size, key, NULL, BUS_NOWAIT_FLAG);
}
 
@@ -67,10 +67,12 @@
}
// 接受信息超时返回。 @sec 秒 , @nsec 纳秒
int ShmModSocket::recvfrom_timeout( void **buf, int *size, int *key, struct timespec *timeout) {
int ShmModSocket::recvfrom_timeout( void **buf, int *size, int *key, const struct timespec *timeout) {
   int rv =  shm_recvfrom(shm_socket, buf, size, key, timeout, BUS_TIMEOUT_FLAG);
    return rv;
    // printf("ShmModSocket::recvfrom_timeout\n");
    // return 501;
}
int ShmModSocket::recvfrom_nowait( void **buf, int *size, int *key){
@@ -88,22 +90,25 @@
   return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, NULL, 0);
}
// 超时返回。 @sec 秒 , @nsec 纳秒
int ShmModSocket::sendandrecv_timeout(const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size, struct timespec *timeout){
   return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, 0);
int ShmModSocket::sendandrecv_timeout(const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size, const struct timespec *timeout){
   return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, BUS_TIMEOUT_FLAG);
}
int ShmModSocket::sendandrecv_nowait(const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size){
   return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, 0, (int)BUS_NOWAIT_FLAG);
   return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, 0, BUS_NOWAIT_FLAG);
}
int ShmModSocket::sendandrecv_unsafe( const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size){
   return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, NULL, 0);
}
// 超时返回。 @sec 秒 , @nsec 纳秒
int ShmModSocket::sendandrecv_unsafe_timeout(const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size, struct timespec *timeout){
   return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, 0);
int ShmModSocket::sendandrecv_unsafe_timeout(const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size, const struct timespec *timeout){
   return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, BUS_TIMEOUT_FLAG);
}
int ShmModSocket::sendandrecv_unsafe_nowait(const void *send_buf, const int send_size, const int send_key, void **recv_buf, int *recv_size){
   return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, 0, (int)BUS_NOWAIT_FLAG);
   return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, 0, BUS_NOWAIT_FLAG);
}
@@ -119,11 +124,11 @@
   return _sub_( topic, size, key, NULL, 0);
}
// 超时返回。 @sec 秒 , @nsec 纳秒
int  ShmModSocket::sub_timeout(char *topic, int size, int key, struct timespec *timeout){
   return _sub_(topic, size, key, timeout, 0);
int  ShmModSocket::sub_timeout(char *topic, int size, int key, const struct timespec *timeout){
   return _sub_(topic, size, key, timeout, BUS_TIMEOUT_FLAG);
}
int  ShmModSocket::sub_nowait(char *topic, int size, int key) {
   return _sub_(topic, size, key, NULL,  (int)BUS_NOWAIT_FLAG);
   return _sub_(topic, size, key, NULL,  BUS_NOWAIT_FLAG);
}
@@ -138,11 +143,11 @@
   return _desub_( topic, size, key, NULL, 0);
}
// 超时返回。 @sec 秒 , @nsec 纳秒
int  ShmModSocket::desub_timeout(char *topic, int size, int key, struct timespec *timeout){
   return _desub_(topic, size, key, timeout, 0);
int  ShmModSocket::desub_timeout(char *topic, int size, int key, const struct timespec *timeout){
   return _desub_(topic, size, key, timeout, BUS_TIMEOUT_FLAG);
}
int  ShmModSocket::desub_nowait(char *topic, int size, int key) {
   return _desub_(topic, size, key, NULL,  (int)BUS_NOWAIT_FLAG);
   return _desub_(topic, size, key, NULL,  BUS_NOWAIT_FLAG);
}
@@ -157,11 +162,11 @@
      return _pub_(topic, topic_size, content, content_size, key, NULL, 0);
}
//  超时返回。 @sec 秒 , @nsec 纳秒
int  ShmModSocket::pub_timeout(char *topic, int topic_size, void *content, int content_size, int key, struct timespec * timeout){
   return _pub_( topic, topic_size, content, content_size, key, timeout, 0);
int  ShmModSocket::pub_timeout(char *topic, int topic_size, void *content, int content_size, int key, const struct timespec * timeout){
   return _pub_( topic, topic_size, content, content_size, key, timeout, BUS_TIMEOUT_FLAG);
}
int  ShmModSocket::pub_nowait(char *topic, int topic_size, void *content, int content_size, int key){
   return _pub_(topic, topic_size, content, content_size, key, NULL, (int)BUS_NOWAIT_FLAG);
   return _pub_(topic, topic_size, content, content_size, key, NULL, BUS_NOWAIT_FLAG);
}
@@ -179,7 +184,7 @@
 * @key 总线端口
 */
int  ShmModSocket::_sub_(char *topic, int topic_size, int key,  
   struct timespec *timeout, int flags) {
   const struct timespec *timeout, int flags) {
    
   int ret;
@@ -206,8 +211,7 @@
/**
 * @key 总线端口
 */
int  ShmModSocket::_desub_(char *topic, int topic_size, int key,
   struct timespec *timeout, int flags) {
int  ShmModSocket::_desub_(char *topic, int topic_size, int key, const struct timespec *timeout, int flags) {
   // char buf[8192];
   int ret;
   if(topic == NULL) {
@@ -225,14 +229,12 @@
   if(size > 0) {
      ret = shm_sendto(shm_socket, buf, size, key, timeout, flags);
      free(buf);
      if(ret == EBUS_TIMEOUT) {
       logger->error(ret, "ShmModSocket::_desub_ key %d failed, %s", key, bus_strerror(EBUS_TIMEOUT));
       return EBUS_TIMEOUT;
     } else {
       logger->error(ret, "ShmModSocket::_desub_ key %d failed!", key);
       return ret;
     }
      if(ret == 0) {
         return 0;
      } else {
         logger->error("ShmModSocket::_desub_ key %d failed, %s", key, bus_strerror(ret));
         return ret;
      }
   } else {
      return -1;
   }
@@ -244,8 +246,7 @@
 * @str "<**pub**>{经济}"
 */
 
int  ShmModSocket::_pub_(char *topic, int topic_size, void *content, int content_size, int key,
   struct timespec *timeout, int flags) {
int  ShmModSocket::_pub_(char *topic, int topic_size, void *content, int content_size, int key, const struct timespec *timeout, int flags) {
   // int head_len;
   // char buf[8192+content_size];
   // snprintf(buf, 8192, "%spub%s%s%s%s", ACTION_LIDENTIFIER, ACTION_RIDENTIFIER, TOPIC_LIDENTIFIER, topic, TOPIC_RIDENTIFIER);