Esempio n. 1
0
void
lwmsg_session_generate_cookie(
    LWMsgSessionCookie* cookie
    )
{
    mt m;
    uint32_t seed[3];
    uint32_t s;
    int i;
    LWMsgTime now;

    lwmsg_time_now(&now);

    /* Add in 32 bits of data from the address of the cookie */
    seed[0] = (uint32_t) (size_t) cookie;
    /* Add in 32 bits of data from the current pid */
    seed[1] = (uint32_t) getpid();
    /* Add in 32 bits of data from the current time */
    seed[2] = (uint32_t) now.microseconds;
        
    mt_init_by_array(&m, seed, sizeof(seed) / sizeof(*seed));
        
    for (i = 0; i < sizeof(cookie->bytes); i += sizeof(s))
    {
        s = mt_genrand_int32(&m);
        
        memcpy(cookie->bytes + i, &s, sizeof(s));
    }
}
Esempio n. 2
0
static
LWMsgStatus
lwmsg_clock_update(
    LWMsgClock* clock
    )
{
    LWMsgTime now, diff;
    LWMsgStatus status = LWMSG_STATUS_SUCCESS;


    BAIL_ON_ERROR(status = lwmsg_time_now(&now));

    if (clock->last_time.seconds == 0 &&
        clock->last_time.microseconds == 0)
    {
        clock->adjust.seconds = -now.seconds;
        clock->adjust.microseconds = -now.microseconds;
    }
    else if (lwmsg_time_compare(&now, &clock->last_time) <= LWMSG_TIME_EQUAL)
    {
        lwmsg_time_difference(&now, &clock->last_time, &diff);
        diff.microseconds++;
        lwmsg_time_sum(&clock->adjust, &diff, &clock->adjust);
    }

    clock->last_time = now;

error:

    return status;
}