Exemple #1
0
/**
 * Returns the difference (in u_long 1/100th secs) between the two markers
 * (functionally this is what sysUpTime needs)
 */
u_long
uatime_hdiff(const_marker_t first, const_marker_t second)
{
    struct timeval diff;

    NETSNMP_TIMERSUB((const struct timeval *) second, (const struct timeval *) first, &diff);
    return ((u_long) diff.tv_sec) * 100 + diff.tv_usec / 10000;
}
Exemple #2
0
/**
 * Compute (*now - *then) in centiseconds.
 */
int
calculate_time_diff(const struct timeval *now, const struct timeval *then)
{
    struct timeval  diff;

    NETSNMP_TIMERSUB(now, then, &diff);
    return (int)(diff.tv_sec * 100 + diff.tv_usec / 10000);
}
Exemple #3
0
/** Compute rounded (*now - *then) in seconds. */
u_int
calculate_sectime_diff(const struct timeval *now, const struct timeval *then)
{
    struct timeval  diff;

    NETSNMP_TIMERSUB(now, then, &diff);
    return diff.tv_sec + (diff.tv_usec >= 500000L);
}
Exemple #4
0
/**
 * Returns the difference (in msec) between the two markers
 */
long
atime_diff(const_marker_t first, const_marker_t second)
{
    struct timeval diff;

    NETSNMP_TIMERSUB((const struct timeval *) second, (const struct timeval *) first, &diff);

    return (long)(diff.tv_sec * 1000 + diff.tv_usec / 1000);
}
Exemple #5
0
/**
 * Is the current time past (marked time plus delta) ?
 *
 * @param[in] pm Pointer to marked time as obtained via
 *   netsnmp_set_monotonic_marker().
 * @param[in] delta_ms Time delta in milliseconds.
 *
 * @return pm != NULL && now >= (*pm + delta_ms)
 */
int
netsnmp_ready_monotonic(const_marker_t pm, int delta_ms)
{
    struct timeval  now, diff, delta;

    netsnmp_assert(delta_ms >= 0);
    if (pm) {
        netsnmp_get_monotonic_clock(&now);
        NETSNMP_TIMERSUB(&now, (const struct timeval *) pm, &diff);
        delta.tv_sec = delta_ms / 1000;
        delta.tv_usec = (delta_ms % 1000) * 1000UL;
        return timercmp(&diff, &delta, >=) ? TRUE : FALSE;
    } else {
        return FALSE;