int round_robin_loop_condition()

in flood_round_robin.c [1307:1359]


int round_robin_loop_condition(profile_t *profile)
{
    round_robin_profile_t *rp;
    int real_current_url;

    rp = (round_robin_profile_t*)profile;

    real_current_url = rp->current_url; /* save the real one before we try to increment */

    rp->current_url++;

    /* Adjust counters for profile */
    if (rp->current_url >= rp->urls) {
        rp->current_url = 0;
        
        /* Loop cond tells us when to stop. */
        rp->current_round++;
    }

#ifdef PROFILE_DEBUG
    apr_file_printf(local_stdout, "Round %d of %d, %s.\n",
                    rp->current_round, rp->execute_rounds,
                    (rp->current_round < rp->execute_rounds ? "Continuing" : "Finished"));
#endif /* PROFILE_DEBUG */

    if (rp->current_round >= rp->execute_rounds)
        return 0;
    else { /* we'll continue, so do delay stuff now if necessary */
        
        /* If they want a sleep, do it now. */
        if (rp->url[real_current_url].postdelay) {
            apr_int64_t real_postdelay = rp->url[real_current_url].postdelay;

            /* If the delay has a precision, adjust the
             * delay by some random fraction of the precision here */
            if (rp->url[real_current_url].postdelayprecision) {
                /* FIXME: this should be more portable, like apr_generate_random_bytes() */
                float factor = -1.0 + (2.0*rand()/(RAND_MAX+1.0));
                real_postdelay += rp->url[real_current_url].postdelayprecision * factor;
            }

            /* we can only delay positive times, can't go back in time :( */
            if (real_postdelay < 0)
                real_postdelay = 0;

            /* only bother going to sleep if we generated a delay */
            if (real_postdelay > 0)
                apr_sleep(real_postdelay);
        }

        return 1;
    }
}