Beispiel #1
0
/**
 * rgaWaitTail
 *
 *
 *
 */
uint8_t *rgaWaitTail(
    rgaRing_t       *ring)
{
    uint8_t         *tail = NULL;

    g_mutex_lock(ring->mtx);
    while (!ring->interrupt && ((tail = rgaNextTail(ring)) == NULL)) {
        g_cond_wait(ring->cnd_zero, ring->mtx);
    }
    if (ring->interrupt) {
        tail = NULL;
        goto end;
    }
    if (++(ring->trsv) >= ring->cap) {
        ring->trsv = ring->cap;
    }
    g_cond_signal(ring->cnd_full);
end:
    g_mutex_unlock(ring->mtx);
    return tail;
}
Beispiel #2
0
gboolean yfProcessPBufRing(
    yfContext_t        *ctx,
    GError             **err)
{
    AirLock             *lock = NULL;
    yfPBuf_t            *pbuf = NULL;
    gboolean            ok = TRUE;
    uint64_t            cur_time;

    /* point to lock buffer if we need it */
    if (ctx->cfg->lockmode) {
        lock = &ctx->lockbuf;
    }

    /* Open output if we need to */
    if (!ctx->fbuf) {
        if (!(ctx->fbuf = yfOutputOpen(ctx->cfg, lock, err))) {
            ok = FALSE;
            goto end;
        }
    }

    /* Dump statistics if requested */
    yfStatDumpLoop();

    /* process packets from the ring buffer */
    while ((pbuf = (yfPBuf_t *)rgaNextTail(ctx->pbufring))) {

        /* Skip time zero packets (these are marked invalid) */
        if (!pbuf->ptime) {
            continue;
        }

        /* Add the packet to the flow table */
        yfFlowPBuf(ctx->flowtab, ctx->pbuflen, pbuf);
    }

    /* Flush the flow table */
    if (!yfFlowTabFlush(ctx, FALSE, err)) {
        ok = FALSE;
        goto end;
    }

    /* Close output file for rotation if necessary */
    if (ctx->cfg->rotate_ms) {
        cur_time = yfFlowTabCurrentTime(ctx->flowtab);
        if (ctx->last_rotate_ms) {
            if (cur_time - ctx->last_rotate_ms > ctx->cfg->rotate_ms) {
                yfOutputClose(ctx->fbuf, lock, TRUE);
                ctx->fbuf = NULL;
                ctx->last_rotate_ms = cur_time;
                if (!(ctx->fbuf = yfOutputOpen(ctx->cfg, lock, err))) {
                    ok = FALSE;
                    goto end;
                }
            }
        } else {
            ctx->last_rotate_ms = cur_time;
        }
    }

end:
    return ok;
}