| | |
| | | } |
| | | |
| | | ShmModSocket::ShmModSocket() { |
| | | mod = (socket_mod_t)0; |
| | | shm_socket = shm_open_socket(SHM_SOCKET_DGRAM); |
| | | bus_set = new std::set<int>; |
| | | } |
| | |
| | | } |
| | | // 发送信息立刻返回。 |
| | | 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); |
| | | return shm_sendto(shm_socket, buf, size, key, NULL, (int)BUS_NOWAIT_FLAG); |
| | | } |
| | | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 接收信息 |
| | |
| | | * @return 0 成功, 其他值 失败的错误码 |
| | | */ |
| | | int ShmModSocket::recvfrom(void **buf, int *size, int *key) { |
| | | int rv = _recvfrom_( buf, size, key, NULL, 0); |
| | | // logger->error(rv, "ShmModSocket::recvfrom failed!"); |
| | | 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) { |
| | | int rv = _recvfrom_(buf, size, key, timeout, 0); |
| | | int rv = shm_recvfrom(shm_socket, buf, size, key, timeout, BUS_TIMEOUT_FLAG); |
| | | return rv; |
| | | } |
| | | |
| | | int ShmModSocket::recvfrom_nowait( void **buf, int *size, int *key){ |
| | | int rv = _recvfrom_(buf, size, key, NULL, (int)SHM_MSG_NOWAIT); |
| | | int rv = shm_recvfrom(shm_socket, buf, size, key, NULL, BUS_NOWAIT_FLAG); |
| | | // logger->error(rv, "ShmModSocket::recvfrom_nowait failed!"); |
| | | return rv; |
| | | } |
| | |
| | | return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, timeout, 0); |
| | | } |
| | | 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)SHM_MSG_NOWAIT); |
| | | return shm_sendandrecv(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, 0, (int)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, timeout, 0); |
| | | } |
| | | 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)SHM_MSG_NOWAIT); |
| | | return shm_sendandrecv_unsafe(shm_socket, send_buf, send_size, send_key, recv_buf, recv_size, 0, (int)BUS_NOWAIT_FLAG); |
| | | } |
| | | |
| | | |
| | |
| | | return _sub_(topic, size, key, timeout, 0); |
| | | } |
| | | int ShmModSocket::sub_nowait(char *topic, int size, int key) { |
| | | return _sub_(topic, size, key, NULL, (int)SHM_MSG_NOWAIT); |
| | | return _sub_(topic, size, key, NULL, (int)BUS_NOWAIT_FLAG); |
| | | } |
| | | |
| | | |
| | |
| | | return _desub_(topic, size, key, timeout, 0); |
| | | } |
| | | int ShmModSocket::desub_nowait(char *topic, int size, int key) { |
| | | return _desub_(topic, size, key, NULL, (int)SHM_MSG_NOWAIT); |
| | | return _desub_(topic, size, key, NULL, (int)BUS_NOWAIT_FLAG); |
| | | } |
| | | |
| | | |
| | |
| | | return _pub_( topic, topic_size, content, content_size, key, timeout, 0); |
| | | } |
| | | 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)SHM_MSG_NOWAIT); |
| | | return _pub_(topic, topic_size, content, content_size, key, NULL, (int)BUS_NOWAIT_FLAG); |
| | | } |
| | | |
| | | |