wangzhengquan
2021-01-18 01e202b60cc8aceb65fd6c82949e2a2b08142f8c
src/socket/shm_mod_socket.cpp
@@ -9,7 +9,6 @@
}
ShmModSocket::ShmModSocket() {
   mod = (socket_mod_t)0;
   shm_socket = shm_open_socket(SHM_SOCKET_DGRAM);
   bus_set = new std::set<int>;
}
@@ -54,37 +53,30 @@
int ShmModSocket::sendto_nowait( const void *buf, const int size, const int key){
   return shm_sendto(shm_socket, buf, size, key, NULL, (int)SHM_MSG_NOWAIT);
}
inline int ShmModSocket::_recvfrom_(void **buf, int *size, int *key,  struct timespec *timeout, int flags) {
   if(mod == BUS) {
      logger->error("Can not use method recvfrom in a Bus");
      exit(1);
   }
// printf("dgram_mod_recvfrom  before\n");
   int rv = shm_recvfrom(shm_socket, buf, size, key, timeout, flags);
// printf("dgram_mod_recvfrom  after\n");
   return rv;
}
/**
 * 接收信息
 * @key 从谁哪里收到的信息
 * @return 0 成功, 其他值 失败的错误码
*/
int ShmModSocket::recvfrom(void **buf, int *size, int *key) {
      return  _recvfrom_( buf, size, key, NULL, 0);
   int rv =  shm_recvfrom(shm_socket, buf, size, key, NULL, 0);
  return rv;
}
// 接受信息超时返回。 @sec 秒 , @nsec 纳秒
int ShmModSocket::recvfrom_timeout( void **buf, int *size, int *key, struct timespec *timeout) {
   return _recvfrom_(buf, size, key, timeout, 0);
   int rv =  shm_recvfrom(shm_socket, buf, size, key, timeout, 0);
    return rv;
}
int ShmModSocket::recvfrom_nowait( void **buf, int *size, int *key){
   return _recvfrom_(buf, size, key, NULL, (int)SHM_MSG_NOWAIT);
   int rv =  shm_recvfrom(shm_socket, buf, size, key, NULL, (int)SHM_MSG_NOWAIT);
   // logger->error(rv, "ShmModSocket::recvfrom_nowait failed!");
  return rv;
}
/**
@@ -188,14 +180,7 @@
 */
int  ShmModSocket::_sub_(char *topic, int topic_size, int key,  
   struct timespec *timeout, int flags) {
   // char buf[8192];
   // int rv;
   // snprintf(buf,  8192, "%ssub%s%s%s%s", ACTION_LIDENTIFIER, ACTION_RIDENTIFIER, TOPIC_LIDENTIFIER, topic, TOPIC_RIDENTIFIER);
   // rv = shm_sendto(shm_socket, buf, strlen(buf) + 1, key, timeout, flags);
   // if(rv == 0) {
   //    bus_set->insert(key);
   // }
   // return rv;
   int ret;
   bus_head_t head = {};
@@ -240,7 +225,14 @@
   if(size > 0) {
      ret = shm_sendto(shm_socket, buf, size, key, timeout, flags);
      free(buf);
      return ret;
      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;
     }
   } else {
      return -1;
   }