| | |
| | | return shm_socket_force_bind(socket->shm_socket, port); |
| | | } |
| | | |
| | | |
| | | |
| | | int dgram_mod_sendto(void *_socket, const void *buf, const int size, const int port) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | return shm_sendto(socket->shm_socket, buf, size, port); |
| | | return shm_sendto(socket->shm_socket, buf, size, port, NULL, 0); |
| | | |
| | | } |
| | | |
| | | int dgram_mod_recvfrom(void *_socket, void **buf, int *size, int *port) { |
| | | int dgram_mod_sendto_timeout(void *_socket, const void *buf, const int size, const int port, int sec, int nsec) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | struct timespec timeout = {sec, nsec}; |
| | | return shm_sendto(socket->shm_socket, buf, size, port, &timeout, 0); |
| | | |
| | | } |
| | | |
| | | int dgram_mod_sendto_nowait(void *_socket, const void *buf, const int size, const int port) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | return shm_sendto(socket->shm_socket, buf, size, port, NULL, (int)SHM_MSG_NOWAIT); |
| | | |
| | | } |
| | | |
| | | static inline int _dgram_mod_recvfrom_(void *_socket, void **buf, int *size, int *port, struct timespec *timeout, int flags) { |
| | | |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | if(socket->mod == BUS) { |
| | | err_exit(0, "Can not use method recvfrom in a Bus"); |
| | | } |
| | | // printf("dgram_mod_recvfrom before\n"); |
| | | int rv = shm_recvfrom(socket->shm_socket, buf, size, port); |
| | | int rv = shm_recvfrom(socket->shm_socket, buf, size, port, timeout, flags); |
| | | // printf("dgram_mod_recvfrom after\n"); |
| | | return rv; |
| | | } |
| | | |
| | | int dgram_mod_recvfrom(void *_socket, void **buf, int *size, int *port) { |
| | | return _dgram_mod_recvfrom_(_socket, buf, size, port, NULL, 0); |
| | | } |
| | | |
| | | int dgram_mod_recvfrom_timeout(void *_socket, void **buf, int *size, int *port, int sec, int nsec) { |
| | | struct timespec timeout = {sec, nsec}; |
| | | return _dgram_mod_recvfrom_(_socket, buf, size, port, &timeout, 0); |
| | | } |
| | | |
| | | int dgram_mod_recvfrom_nowait(void *_socket, void **buf, int *size, int *port) { |
| | | return _dgram_mod_recvfrom_(_socket, buf, size, port, NULL, (int)SHM_MSG_NOWAIT); |
| | | } |
| | | |
| | | |
| | | |
| | | int dgram_mod_sendandrecv(void * _socket, const void *send_buf, const int send_size, const int send_port, void **recv_buf, int *recv_size) { |
| | | int dgram_mod_sendandrecv(void * _socket, const void *send_buf, const int send_size, const int send_port, |
| | | void **recv_buf, int *recv_size) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | return shm_sendandrecv(socket->shm_socket, send_buf, send_size, send_port, recv_buf, recv_size); |
| | | return shm_sendandrecv(socket->shm_socket, send_buf, send_size, send_port, recv_buf, recv_size, NULL, 0); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | int dgram_mod_get_port(void * _socket) { |
| | | int dgram_mod_sendandrecv_timeout(void * _socket, const void *send_buf, const int send_size, const int send_port, |
| | | void **recv_buf, int *recv_size, int sec, int nsec) { |
| | | struct timespec timeout = {sec, nsec}; |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | return socket->shm_socket->port; |
| | | return shm_sendandrecv(socket->shm_socket, send_buf, send_size, send_port, recv_buf, recv_size, &timeout, 0); |
| | | |
| | | } |
| | | |
| | | int dgram_mod_sendandrecv_nowait(void * _socket, const void *send_buf, const int send_size, const int send_port, |
| | | void **recv_buf, int *recv_size) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | return shm_sendandrecv(socket->shm_socket, send_buf, send_size, send_port, recv_buf, recv_size, 0, (int)SHM_MSG_NOWAIT); |
| | | |
| | | } |
| | | |
| | | |
| | | void dgram_mod_free(void *buf) { |
| | | free(buf); |
| | | } |
| | | // =================bus======================== |
| | | |
| | | int dgram_mod_start_bus(void * _socket) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | |
| | | /** |
| | | * @port 总线端口 |
| | | */ |
| | | int dgram_mod_sub(void * _socket, void *topic, int size, int port) { |
| | | static int _dgram_mod_sub_(void * _socket, void *topic, int size, int port, |
| | | struct timespec *timeout, int flags) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | char buf[8192]; |
| | | snprintf(buf, 8192, "%ssub%s%s%s%s", ACTION_LIDENTIFIER, ACTION_RIDENTIFIER, TOPIC_LIDENTIFIER, (char *)topic, TOPIC_RIDENTIFIER); |
| | | return shm_sendto(socket->shm_socket, buf, strlen(buf) + 1, port); |
| | | return shm_sendto(socket->shm_socket, buf, strlen(buf) + 1, port, timeout, flags); |
| | | } |
| | | |
| | | int dgram_mod_sub(void * _socket, void *topic, int size, int port ) { |
| | | return _dgram_mod_sub_(_socket, topic, size, port, NULL, 0); |
| | | } |
| | | |
| | | int dgram_mod_sub_timeout(void * _socket, void *topic, int size, int port, int sec, int nsec) { |
| | | struct timespec timeout = {sec, nsec}; |
| | | return _dgram_mod_sub_(_socket, topic, size, port, &timeout, 0); |
| | | } |
| | | |
| | | int dgram_mod_sub_nowait(void * _socket, void *topic, int size, int port) { |
| | | return _dgram_mod_sub_(_socket, topic, size, port, NULL, (int)SHM_MSG_NOWAIT); |
| | | } |
| | | |
| | | /** |
| | | * @port 总线端口 |
| | | */ |
| | | int dgram_mod_pub(void * _socket, void *topic, int topic_size, void *content, int content_size, int port) { |
| | | static int _dgram_mod_pub_(void * _socket, void *topic, int topic_size, void *content, int content_size, int port, |
| | | struct timespec *timeout, int flags) { |
| | | |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | int head_len; |
| | |
| | | snprintf(buf, 8192, "%spub%s%s%s%s", ACTION_LIDENTIFIER, ACTION_RIDENTIFIER, TOPIC_LIDENTIFIER, (char *)topic, TOPIC_RIDENTIFIER); |
| | | head_len = strlen(buf); |
| | | memcpy(buf+head_len, content, content_size); |
| | | return shm_sendto(socket->shm_socket, buf, head_len+content_size, port); |
| | | return shm_sendto(socket->shm_socket, buf, head_len+content_size, port, timeout, flags); |
| | | |
| | | } |
| | | |
| | | int dgram_mod_pub(void * _socket, void *topic, int topic_size, void *content, int content_size, int port) { |
| | | return _dgram_mod_pub_(_socket, topic, topic_size, content, content_size, port, NULL, 0); |
| | | } |
| | | |
| | | int dgram_mod_pub_timeout(void * _socket, void *topic, int topic_size, void *content, int content_size, int port, int sec, int nsec) { |
| | | struct timespec timeout = {sec, nsec}; |
| | | return _dgram_mod_pub_(_socket, topic, topic_size, content, content_size, port, &timeout, 0); |
| | | } |
| | | |
| | | int dgram_mod_pub_nowait(void * _socket, void *topic, int topic_size, void *content, int content_size, int port) { |
| | | return _dgram_mod_pub_(_socket, topic, topic_size, content, content_size, port, NULL, (int)SHM_MSG_NOWAIT); |
| | | } |
| | | |
| | | |
| | | |
| | | int dgram_mod_get_port(void * _socket) { |
| | | dgram_mod_socket_t * socket = (dgram_mod_socket_t *) _socket; |
| | | return socket->shm_socket->port; |
| | | } |
| | | |
| | | |
| | | void dgram_mod_free(void *buf) { |
| | | free(buf); |
| | | } |
| | | |
| | | //========================================================================================================================== |
| | | |