Tor  0.4.7.0-alpha-dev
Functions
tvdiff.c File Reference

Compute the difference between timevals, in various units. More...

#include "lib/time/tvdiff.h"
#include "lib/cc/compat_compiler.h"
#include "lib/defs/time.h"
#include "lib/log/log.h"

Go to the source code of this file.

Functions

static int64_t tv_secdiff_impl (const struct timeval *start, const struct timeval *end)
 
long tv_udiff (const struct timeval *start, const struct timeval *end)
 
long tv_mdiff (const struct timeval *start, const struct timeval *end)
 
int64_t tv_to_msec (const struct timeval *tv)
 
time_t time_diff (const time_t t1, const time_t t2)
 

Detailed Description

Compute the difference between timevals, in various units.

Definition in file tvdiff.c.

Function Documentation

◆ time_diff()

time_t time_diff ( const time_t  t1,
const time_t  t2 
)

Return duration in seconds between time_t values t1 and t2 iff t1 is numerically less or equal than t2. Otherwise, return TIME_MAX.

This provides a safe way to compute difference between two UNIX timestamps (t2 can be assumed by calling code to be later than t1) or two durations measured in seconds (t2 can be assumed to be longer than t1). Calling code is expected to check for TIME_MAX return value and interpret that as error condition.

Definition at line 181 of file tvdiff.c.

Referenced by predicted_ports_prediction_time_remaining().

◆ tv_mdiff()

long tv_mdiff ( const struct timeval start,
const struct timeval end 
)

Return the number of milliseconds elapsed between *start and *end. If the tv_usec difference is 500, rounds away from zero. Returns LONG_MAX on overflow and underflow.

Definition at line 102 of file tvdiff.c.

Referenced by circuit_build_times_handle_completed_hop().

◆ tv_secdiff_impl()

static int64_t tv_secdiff_impl ( const struct timeval start,
const struct timeval end 
)
static

Return the difference between start->tv_sec and end->tv_sec. Returns INT64_MAX on overflow and underflow.

Definition at line 28 of file tvdiff.c.

◆ tv_to_msec()

int64_t tv_to_msec ( const struct timeval tv)

Converts timeval to milliseconds.

Definition at line 160 of file tvdiff.c.

◆ tv_udiff()

long tv_udiff ( const struct timeval start,
const struct timeval end 
)

Return the number of microseconds elapsed between *start and *end. Returns LONG_MAX on overflow and underflow.

Definition at line 53 of file tvdiff.c.