Exemple #1
0
static int
rtpp_notify_schedule(struct rtpp_notify *pub,
  struct rtpp_tnotify_target *rttp, const char *notify_tag)
{
    struct rtpp_notify_wi *wi_data;
    struct rtpp_wi *wi;
    int len;
    struct rtpp_notify_priv *pvt;

    pvt = PUB2PVT(pub);

    /* string, \0 and \n */
    len = strlen(notify_tag) + 2;

    wi = rtpp_wi_malloc_udata((void **)&wi_data,
      sizeof(struct rtpp_notify_wi) + len);
    if (wi == NULL) {
        return (-1);
    }
    memset(wi_data, '\0', sizeof(struct rtpp_notify_wi) + len);

    wi_data->rttp = rttp;
    wi_data->len = len;

    len = snprintf(wi_data->notify_buf, len, "%s\n", notify_tag);

    CALL_METHOD(pvt->glog->rcnt, incref);
    wi->log = pvt->glog;

    rtpp_queue_put_item(wi, pvt->nqueue);
    return (0);
}
int
rtpp_anetio_send_pkt(struct sthread_args *sender, int sock, \
                     const struct sockaddr *sendto, socklen_t tolen, struct rtp_packet *pkt)
{
    struct rtpp_wi *wi;
    int nsend;

    if (sender->dmode != 0 && pkt->size < LBR_THRS) {
        nsend = 2;
    } else {
        nsend = 1;
    }

    wi = rtpp_wi_malloc_pkt(sock, pkt, sendto, tolen, nsend);
    if (wi == NULL) {
        rtp_packet_free(pkt);
        return (-1);
    }
    /*
     * rtpp_wi_malloc_pkt() consumes pkt and returns wi, so no need to
     * call rtp_packet_free() here.
     */
    rtpp_queue_put_item(wi, sender->out_q);
    return (0);
}
Exemple #3
0
static void
rtpp_mif_dtor(struct rtpp_module_if_priv *pvt)
{

    rtpp_module_if_fin(&(pvt->pub));
    /* First, stop the worker thread and wait for it to terminate */
    rtpp_queue_put_item(pvt->sigterm, pvt->req_q);
    pthread_join(pvt->thread_id, NULL);
    rtpp_queue_destroy(pvt->req_q);

    /* Then run module destructor (if any) */
    if (pvt->mip->dtor != NULL) {
        pvt->mip->dtor(pvt->mpvt);
    }

#if RTPP_CHECK_LEAKS
    /* Check if module leaked any mem */
    if (rtpp_memdeb_dumpstats(pvt->memdeb_p, 1) != 0) {
        RTPP_LOG(pvt->log, RTPP_LOG_ERR, "module '%s' leaked memory after "
          "destruction", pvt->mip->name);
    }
    rtpp_memdeb_dtor(pvt->memdeb_p);
#endif
    /* Unload and free everything */
    dlclose(pvt->dmp);
    CALL_METHOD(pvt->log->rcnt, decref);
    free(pvt);
}
Exemple #4
0
static void
rtpp_notify_dtor(struct rtpp_notify_obj *pub)
{
    struct rtpp_notify_priv *pvt;

    pvt = PUB2PVT(pub);

    rtpp_queue_put_item(pvt->sigterm, pvt->nqueue);
    pthread_join(pvt->thread_id, NULL);
    rtpp_queue_destroy(pvt->nqueue);
    free(pvt);
}
Exemple #5
0
static void
rtpp_notify_dtor(struct rtpp_notify *pub)
{
    struct rtpp_notify_priv *pvt;

    pvt = PUB2PVT(pub);

    rtpp_queue_put_item(pvt->sigterm, pvt->nqueue);
    pthread_join(pvt->thread_id, NULL);
    rtpp_queue_destroy(pvt->nqueue);
    CALL_METHOD(pvt->glog->rcnt, decref);
    free(pvt);
}
void
rtpp_netio_async_destroy(struct rtpp_anetio_cf *netio_cf)
{
    int i;

    for (i = 0; i < SEND_THREADS; i++) {
        rtpp_queue_put_item(netio_cf->args[i].sigterm, netio_cf->args[i].out_q);
    }
    for (i = 0; i < SEND_THREADS; i++) {
        pthread_join(netio_cf->thread_id[i], NULL);
        rtpp_queue_destroy(netio_cf->args[i].out_q);
    }
    free(netio_cf);
}
void
rtpp_proc_async_wakeup(struct rtpp_proc_async_cf *proc_cf, int clock, long long ncycles_ref)
{
    struct sign_arg s_a;
    struct rtpp_wi *wi;

    s_a.clock_tick = clock;
    s_a.ncycles_ref = ncycles_ref;
    wi = rtpp_wi_malloc_sgnl(SIGALRM, &s_a, sizeof(s_a));
    if (wi == NULL) {
        /* XXX complain */
        return;
    }
    rtpp_queue_put_item(wi, proc_cf->time_q);
}
Exemple #8
0
static void
rtpp_mif_do_acct(struct rtpp_module_if *self, struct rtpp_acct *acct)
{
    struct rtpp_module_if_priv *pvt;
    struct rtpp_wi *wi;

    pvt = PUB2PVT(self);
    wi = rtpp_wi_malloc_apis(do_acct_aname, &acct, sizeof(acct));
    if (wi == NULL) {
        RTPP_LOG(pvt->log, RTPP_LOG_ERR, "module '%s': cannot allocate "
          "memory", pvt->mip->name);
        return;
    }
    CALL_METHOD(acct->rcnt, incref);
    rtpp_queue_put_item(wi, pvt->req_q);
}
int
rtpp_anetio_sendto(struct rtpp_anetio_cf *netio_cf, int sock, const void *msg, \
                   size_t msg_len, int flags, const struct sockaddr *sendto, socklen_t tolen)
{
    struct rtpp_wi *wi;

    wi = rtpp_wi_malloc(sock, msg, msg_len, flags, sendto, tolen);
    if (wi == NULL) {
        return (-1);
    }
#ifdef RTPP_DEBUG
    wi->debug = 1;
    rtpp_log_write(RTPP_LOG_DBUG, netio_cf->args[0].glog, "rtpp_anetio_sendto: malloc(%d, %p, %d, %d, %p, %d) = %p",
                   sock, msg, msg_len, flags, sendto, tolen, wi);
    rtpp_log_write(RTPP_LOG_DBUG, netio_cf->args[0].glog, "rtpp_anetio_sendto: sendto(%d, %p, %d, %d, %p, %d)",
                   wi->sock, wi->msg, wi->msg_len, wi->flags, wi->sendto, wi->tolen);
#endif
    rtpp_queue_put_item(wi, netio_cf->args[0].out_q);
    return (0);
}
Exemple #10
0
int
rtpp_anetio_send_pkt_na(struct sthread_args *sender, int sock, \
  struct rtpp_netaddr *sendto, struct rtp_packet *pkt,
  struct rtpp_refcnt *sock_rcnt, struct rtpp_log *plog)
{
    struct rtpp_wi *wi;
    int nsend;

    if (sender->dmode != 0 && pkt->size < LBR_THRS) {
        nsend = 2;
    } else {
        nsend = 1;
    }

    wi = rtpp_wi_malloc_pkt_na(sock, pkt, sendto, nsend, sock_rcnt);
    if (wi == NULL) {
        rtp_packet_free(pkt);
        return (-1);
    }
    /*
     * rtpp_wi_malloc_pkt() consumes pkt and returns wi, so no need to
     * call rtp_packet_free() here.
     */
#if RTPP_DEBUG_netio >= 2
    wi->debug = 1;
    if (plog == NULL) {
        plog = sender->glog;
    }
    CALL_SMETHOD(plog->rcnt, incref);
    wi->log = plog;
    RTPP_LOG(plog, RTPP_LOG_DBUG, "send_pkt(%d, %p, %d, %d, %p, %d)",
      wi->sock, wi->msg, wi->msg_len, wi->flags, wi->sendto, wi->tolen);
#endif
    rtpp_queue_put_item(wi, sender->out_q);
    return (0);
}
Exemple #11
0
int
rtpp_anetio_sendto(struct rtpp_anetio_cf *netio_cf, int sock, const void *msg, \
  size_t msg_len, int flags, const struct sockaddr *sendto, socklen_t tolen)
{
    struct rtpp_wi *wi;

    wi = rtpp_wi_malloc(sock, msg, msg_len, flags, sendto, tolen);
    if (wi == NULL) {
        return (-1);
    }
#if RTPP_DEBUG_netio >= 1
    wi->debug = 1;
    wi->log = netio_cf->args[0].glog;
    CALL_SMETHOD(wi->log->rcnt, incref);
#if RTPP_DEBUG_netio >= 2
    RTPP_LOG(netio_cf->args[0].glog, RTPP_LOG_DBUG, "malloc(%d, %p, %d, %d, %p, %d) = %p",
      sock, msg, msg_len, flags, sendto, tolen, wi);
    RTPP_LOG(netio_cf->args[0].glog, RTPP_LOG_DBUG, "sendto(%d, %p, %d, %d, %p, %d)",
      wi->sock, wi->msg, wi->msg_len, wi->flags, wi->sendto, wi->tolen);
#endif
#endif
    rtpp_queue_put_item(wi, netio_cf->args[0].out_q);
    return (0);
}
struct rtpp_anetio_cf *
rtpp_netio_async_init(struct cfg *cf, int qlen)
{
    struct rtpp_anetio_cf *netio_cf;
    int i, ri;

    netio_cf = rtpp_zmalloc(sizeof(*netio_cf));
    if (netio_cf == NULL)
        return (NULL);

    for (i = 0; i < SEND_THREADS; i++) {
        netio_cf->args[i].out_q = rtpp_queue_init(qlen, "RTPP->NET%.2d", i);
        if (netio_cf->args[i].out_q == NULL) {
            for (ri = i - 1; ri >= 0; ri--) {
                rtpp_queue_destroy(netio_cf->args[ri].out_q);
            }
            goto e0;
        }
        netio_cf->args[i].glog = cf->stable->glog;
        netio_cf->args[i].dmode = cf->stable->dmode;
#ifdef RTPP_DEBUG
        recfilter_init(&netio_cf->args[i].average_load, 0.9, 0.0, 0);
#endif
    }

    for (i = 0; i < SEND_THREADS; i++) {
        netio_cf->args[i].sigterm = rtpp_wi_malloc_sgnl(SIGTERM, NULL, 0);
        if (netio_cf->args[i].sigterm == NULL) {
            for (ri = i - 1; ri >= 0; ri--) {
                rtpp_wi_free(netio_cf->args[ri].sigterm);
            }
            goto e1;
        }
    }

    cf->stable->rtpp_netio_cf = netio_cf;
    for (i = 0; i < SEND_THREADS; i++) {
        if (pthread_create(&(netio_cf->thread_id[i]), NULL, (void *(*)(void *))&rtpp_anetio_sthread, &netio_cf->args[i]) != 0) {
            for (ri = i - 1; ri >= 0; ri--) {
                rtpp_queue_put_item(netio_cf->args[ri].sigterm, netio_cf->args[ri].out_q);
                pthread_join(netio_cf->thread_id[ri], NULL);
            }
            for (ri = i; ri < SEND_THREADS; ri++) {
                rtpp_wi_free(netio_cf->args[ri].sigterm);
            }
            goto e1;
        }
    }

    return (netio_cf);

#if 0
e2:
    for (i = 0; i < SEND_THREADS; i++) {
        rtpp_wi_free(netio_cf->args[i].sigterm);
    }
#endif
e1:
    for (i = 0; i < SEND_THREADS; i++) {
        rtpp_queue_destroy(netio_cf->args[i].out_q);
    }
e0:
    free(netio_cf);
    return (NULL);
}