| 3635 | } |
| 3636 | |
| 3637 | static int start_async_send_rtpe_command(struct rtpe_node *node, bencode_item_t *dict, char* cookie, enum async_ret_code *out_fd) |
| 3638 | { |
| 3639 | struct sockaddr_un addr; |
| 3640 | int fd=-1, len, vcnt; |
| 3641 | char buf[0x10000]; |
| 3642 | struct pollfd fds[1]; |
| 3643 | struct iovec *v; |
| 3644 | |
| 3645 | v = bencode_iovec(dict, &vcnt, 1, 0); |
| 3646 | if (!v) { |
| 3647 | LM_ERR("error converting bencode to iovec\n"); |
| 3648 | goto error; |
| 3649 | } |
| 3650 | |
| 3651 | len = 0; |
| 3652 | if (node->rn_umode == 0) { |
| 3653 | memset(&addr, 0, sizeof(addr)); |
| 3654 | addr.sun_family = AF_LOCAL; |
| 3655 | strncpy(addr.sun_path, node->rn_address, |
| 3656 | sizeof(addr.sun_path) - 1); |
| 3657 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 3658 | addr.sun_len = strlen(addr.sun_path); |
| 3659 | #endif |
| 3660 | |
| 3661 | fd = socket(AF_LOCAL, SOCK_STREAM, 0); |
| 3662 | if (fd < 0) { |
| 3663 | LM_ERR("can't create socket %d \n",errno); |
| 3664 | goto badproxy; |
| 3665 | } |
| 3666 | if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) { |
| 3667 | LM_ERR("can't connect to RTP proxy %s (%d:%s)\n",node->rn_url.s,errno,strerror(errno)); |
| 3668 | close(fd); |
| 3669 | goto badproxy; |
| 3670 | } |
| 3671 | |
| 3672 | do { |
| 3673 | len = writev(fd, v + 1, vcnt); |
| 3674 | } while (len == -1 && errno == EINTR); |
| 3675 | if (len <= 0) { |
| 3676 | LM_ERR("can't send command to RTP proxy %s (%d:%s)\n",node->rn_url.s, |
| 3677 | errno, strerror(errno)); |
| 3678 | close(fd); |
| 3679 | goto badproxy; |
| 3680 | } |
| 3681 | *out_fd = fd; |
| 3682 | } else { |
| 3683 | if (rtpe_socks[node->idx] != -1) { |
| 3684 | fds[0].fd = rtpe_socks[node->idx]; |
| 3685 | fds[0].events = POLLIN; |
| 3686 | fds[0].revents = 0; |
| 3687 | /* Drain input buffer */ |
| 3688 | while ((poll(fds, 1, 0) == 1) && |
| 3689 | ((fds[0].revents & POLLIN) != 0)) { |
| 3690 | if (fds[0].revents & (POLLERR|POLLNVAL|POLLHUP)) { |
| 3691 | LM_WARN("error on rtpengine socket %d!\n", rtpe_socks[node->idx]); |
| 3692 | RTPE_IO_ERROR_CLOSE(rtpe_socks[node->idx]); |
| 3693 | break; |
| 3694 | } |
no test coverage detected