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

Header for tvdiff.c. More...

#include "lib/cc/torint.h"

Go to the source code of this file.

Functions

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 from, const time_t to)
 

Detailed Description

Header for tvdiff.c.

Definition in file tvdiff.h.

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_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.