Beispiel #1
0
static int
init_pollset(struct cfg *cf, struct rtpp_cmd_pollset *psp)
{
    struct rtpp_ctrl_sock *ctrl_sock;
    int pfds_used, msize, i;

    pfds_used = 0;
    ctrl_sock = RTPP_LIST_HEAD(cf->stable->ctrl_socks);
    for (pfds_used = 0; ctrl_sock != NULL; ctrl_sock = RTPP_ITER_NEXT(ctrl_sock)) {
        if (RTPP_CTRL_ACCEPTABLE(ctrl_sock))
            continue;
        pfds_used++;
    }
    msize = pfds_used > 0 ? pfds_used : 1;
    psp->pfds = malloc(sizeof(struct pollfd) * msize);
    if (psp->pfds == NULL) {
        return (-1);
    }
    if (pthread_mutex_init(&psp->pfds_mutex, NULL) != 0) {
        free(psp->pfds);
        return (-1);
    }
    psp->pfds_used = pfds_used;
    if (psp->pfds_used == 0) {
        return (0);
    }
    ctrl_sock = RTPP_LIST_HEAD(cf->stable->ctrl_socks);
    for (i = 0; ctrl_sock != NULL; ctrl_sock = RTPP_ITER_NEXT(ctrl_sock)) {
        if (RTPP_CTRL_ACCEPTABLE(ctrl_sock))
            continue;
        psp->pfds[i].fd = ctrl_sock->controlfd_in;
        psp->pfds[i].events = POLLIN;
        psp->pfds[i].revents = 0;
        psp->rccs[i] = rtpp_cmd_connection_ctor(ctrl_sock->controlfd_in, 
          ctrl_sock->controlfd_out, ctrl_sock, NULL);
        i++;
    }
    if (i == 1 && RTPP_CTRL_ISSTREAM(psp->rccs[0]->csock)) {
        psp->rccs[0]->csock->exit_on_close = 1;
    }
    return (0);
}
Beispiel #2
0
void
rtpp_controlfd_cleanup(struct cfg *cf)
{
    struct rtpp_ctrl_sock *ctrl_sock;

    for (ctrl_sock = RTPP_LIST_HEAD(cf->stable->ctrl_socks);
      ctrl_sock != NULL; ctrl_sock = RTPP_ITER_NEXT(ctrl_sock)) {
        if (RTPP_CTRL_ISUNIX(ctrl_sock) == 0)
            continue;
        unlink(ctrl_sock->cmd_sock);
    }
}
Beispiel #3
0
static int
init_accptset(struct cfg *cf, struct rtpp_cmd_accptset *asp)
{
    int i, pfds_used;
    struct rtpp_ctrl_sock *ctrl_sock;

    pfds_used = 0;
    ctrl_sock = RTPP_LIST_HEAD(cf->stable->ctrl_socks);
    for (pfds_used = 0; ctrl_sock != NULL; ctrl_sock = RTPP_ITER_NEXT(ctrl_sock)) {
        if (RTPP_CTRL_ACCEPTABLE(ctrl_sock) == 0)
            continue;
        pfds_used++;
    }
    if (pfds_used == 0) {
        return (0);
    }

    asp->pfds = malloc(sizeof(struct pollfd) * pfds_used);
    if (asp->pfds == NULL) {
        return (-1);
    }
    asp->pfds_used = pfds_used;
    asp->csocks = malloc(sizeof(struct rtpp_ctrl_sock) * pfds_used);
    if (asp->csocks == NULL) {
        free(asp->pfds);
        return (-1);
    }
    ctrl_sock = RTPP_LIST_HEAD(cf->stable->ctrl_socks);
    for (i = 0; i < asp->pfds_used; ctrl_sock = RTPP_ITER_NEXT(ctrl_sock)) {
        if (RTPP_CTRL_ACCEPTABLE(ctrl_sock) == 0)
            continue;
        asp->pfds[i].fd = ctrl_sock->controlfd_in;
        asp->pfds[i].events = POLLIN;
        asp->pfds[i].revents = 0;
        asp->csocks[i] = ctrl_sock;
        i++;
    }
    return (pfds_used);
}
Beispiel #4
0
int
rtpp_controlfd_init(struct cfg *cf)
{
    int controlfd_in, controlfd_out, flags;
    struct rtpp_ctrl_sock *ctrl_sock;

    for (ctrl_sock = RTPP_LIST_HEAD(cf->stable->ctrl_socks);
      ctrl_sock != NULL; ctrl_sock = RTPP_ITER_NEXT(ctrl_sock)) {
        switch (ctrl_sock->type) {
        case RTPC_SYSD:
            controlfd_in = controlfd_out = controlfd_init_systemd();
            break;

        case RTPC_IFSUN:
        case RTPC_IFSUN_C:
            controlfd_in = controlfd_out = controlfd_init_ifsun(cf, ctrl_sock);
            break;

        case RTPC_UDP4:
        case RTPC_UDP6:
            controlfd_in = controlfd_out = controlfd_init_udp(cf, ctrl_sock);
            break;

        case RTPC_TCP4:
        case RTPC_TCP6:
            controlfd_in = controlfd_out = controlfd_init_tcp(cf, ctrl_sock);
            break;

        case RTPC_STDIO:
            controlfd_in = fileno(stdin);
            controlfd_out = fileno(stdout);
            break;
        }
        if (controlfd_in < 0 || controlfd_out < 0) {
            return (-1);
        }
        flags = fcntl(controlfd_in, F_GETFL);
        fcntl(controlfd_in, F_SETFL, flags | O_NONBLOCK);
        ctrl_sock->controlfd_in = controlfd_in;
        ctrl_sock->controlfd_out = controlfd_out;
    }

    return (0);
}