| | |
| | | static Logger *logger = LoggerFactory::getLogger(); |
| | | |
| | | |
| | | size_t ShmModSocket::remove_keys(int keys[], size_t length) { |
| | | BusServerSocket::remove_subscripters(keys, length); |
| | | return shm_socket_remove_keys(keys, length); |
| | | } |
| | | |
| | | ShmModSocket::ShmModSocket() { |
| | | shm_socket = shm_open_socket(SHM_SOCKET_DGRAM); |
| | | shm_socket = shm_socket_open(SHM_SOCKET_DGRAM); |
| | | bus_set = new std::set<int>; |
| | | } |
| | | |
| | |
| | | delete bus_set; |
| | | } |
| | | |
| | | shm_close_socket(shm_socket); |
| | | shm_socket_close(shm_socket); |
| | | } |
| | | |
| | | int ShmModSocket::stop() { |
| | | return shm_socket_stop(shm_socket); |
| | | } |
| | | |
| | | |
| | | int ShmModSocket::bind(int key) { |
| | | return shm_socket_bind(shm_socket, key); |
| | |
| | | */ |
| | | int ShmModSocket::sendandrecv(const void *send_buf, const int send_size, const int send_key, |
| | | void **recv_buf, int *recv_size, const struct timespec *timeout, int flag){ |
| | | return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, flag); |
| | | int rv = shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, flag); |
| | | |
| | | if(rv == 0) { |
| | | logger->debug("ShmModSocket::sendandrecv: sendandrecv to %d success.\n", send_key); |
| | | return 0; |
| | | } |
| | | |
| | | logger->debug("ShmModSocket::sendandrecv : sendandrecv to %d failed %s", send_key, bus_strerror(rv)); |
| | | return rv; |
| | | } |
| | | |
| | | |
| | | int ShmModSocket::recvandsend( recvandsend_callback_fn callback, |
| | | const struct timespec *timeout , int flag, void * user_data ) { |
| | | return shm_recvandsend(shm_socket, callback, timeout, flag, user_data); |
| | | } |
| | | |
| | | // 超时返回。 @sec 秒 , @nsec 纳秒 |
| | | int ShmModSocket::sendandrecv_unsafe(const void *send_buf, const int send_size, const int send_key, |
| | | void **recv_buf, int *recv_size, const struct timespec *timeout, int flag){ |
| | | return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, flag); |
| | | } |
| | | // // 超时返回。 @sec 秒 , @nsec 纳秒 |
| | | // int ShmModSocket::sendandrecv_unsafe(const void *send_buf, const int send_size, const int send_key, |
| | | // void **recv_buf, int *recv_size, const struct timespec *timeout, int flag){ |
| | | // return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, flag); |
| | | // } |
| | | |
| | | /** |
| | | * 订阅指定主题 |
| | |
| | | * @size 主题长度 |
| | | * @key 总线端口 |
| | | */ |
| | | int ShmModSocket::sub(char *topic, int topic_size, int key, |
| | | int ShmModSocket::sub(const char *topic, int topic_size, int key, |
| | | const struct timespec *timeout, int flags) { |
| | | int ret; |
| | | bus_head_t head = {}; |
| | |
| | | * @size 主题长度 |
| | | * @key 总线端口 |
| | | */ |
| | | int ShmModSocket::desub(char *topic, int topic_size, int key, const struct timespec *timeout, int flags) { |
| | | int ShmModSocket::desub(const char *topic, int topic_size, int key, const struct timespec *timeout, int flags) { |
| | | // char buf[8192]; |
| | | int ret; |
| | | if(topic == NULL) { |
| | |
| | | * @content 主题内容 |
| | | * @key 总线端口 |
| | | */ |
| | | int ShmModSocket::pub(char *topic, int topic_size, void *content, int content_size, int key, const struct timespec *timeout, int flags) { |
| | | int ShmModSocket::pub(const char *topic, int topic_size, const void *content, int content_size, int key, const struct timespec *timeout, int flags) { |
| | | int ret; |
| | | bus_head_t head = {}; |
| | | memcpy(head.action, "pub", sizeof(head.action)); |
| | |
| | | // ============================================================================= |
| | | |
| | | int ShmModSocket::get_bus_sendbuf(bus_head_t &request_head, |
| | | void *topic_buf, int topic_size, void *content_buf, int content_size, void **retbuf) { |
| | | const void *topic_buf, int topic_size, const void *content_buf, int content_size, void **retbuf) { |
| | | |
| | | int buf_size; |
| | | char *buf; |