su 1.12.11devel
|
Time types and functions. More...
#include "sofia-sip/su_types.h"
Go to the source code of this file.
Data Structures | |
struct | su_time_s |
Time in seconds and microsecondcs. More... | |
Macros | |
#define | SU_TIME_H |
Defined when <sofia-sip/su_time.h> has been included. | |
#define | SU_NTP_C(x) |
Represent NTP constant. | |
#define | SU_TIME_CMP(t1, t2) |
Compare two timestamps. | |
#define | SU_TIME_EPOCH |
Seconds from 1.1.1900 to 1.1.1970. | |
#define | SU_TIME64_MAX |
Maximum value of su_time64_t type. | |
Typedefs | |
typedef uint64_t | su_time64_t |
Time in nanoseconds. | |
typedef su_time64_t | su_nanotime_t |
Time in nanoseconds. | |
typedef int64_t | su_dur64_t |
Time offset (duration) in nanoseconds. | |
typedef struct su_time_s | su_time_t |
Time in seconds and microsecondcs. | |
typedef long | su_duration_t |
Time difference in microseconds. | |
typedef uint64_t | su_ntp_t |
NTP timestamp. | |
Enumerations | |
enum | { SU_DURATION_MAX } |
Functions | |
su_time64_t | su_nanotime (su_time64_t *return_time) |
Get current time as nanoseconds since epoch. | |
su_time64_t | su_monotime (su_time64_t *return_time) |
Get current monotonic time as nanoseconds. | |
su_time64_t | su_now64 (void) |
Get current time as nanoseconds since epoch. | |
su_time64_t | su_stamp64 (void) |
Get current monotonic timestamp as nanoseconds. | |
su_duration_t | su_duration64 (su_time64_t t1, su_time64_t t2) |
Time difference in milliseconds. | |
su_time_t | su_now (void) |
Get current time. | |
void | su_time (su_time_t *tv) |
Get current time. | |
long | su_time_cmp (su_time_t const t1, su_time_t const t2) |
Compare two timestamps. | |
double | su_time_diff (su_time_t const t1, su_time_t const t2) |
Difference between two timestamps. | |
su_duration_t | su_duration (su_time_t const t1, su_time_t const t2) |
Time difference in milliseconds. | |
su_time_t | su_time_add (su_time_t t, su_duration_t dur) |
Add milliseconds to the time. | |
su_time_t | su_time_dadd (su_time_t t, double dur) |
Add seconds to the time. | |
int | su_time_print (char *s, int n, su_time_t const *tv) |
Print su_time_t timestamp. | |
su_ntp_t | su_ntp_now (void) |
Get NTP timestamp. | |
uint32_t | su_ntp_sec (void) |
Get NTP seconds. | |
uint32_t | su_ntp_hi (su_ntp_t) |
High 32 bit of NTP timestamp. | |
uint32_t | su_ntp_lo (su_ntp_t) |
Low 32 bit of NTP timestamp. | |
uint32_t | su_ntp_mw (su_ntp_t ntp) |
Middle 32 bit of NTP timestamp. | |
uint32_t | su_ntp_fraq (su_time_t t) |
Middle 32 bit of NTP timestamp. | |
uint32_t | su_time_ms (su_time_t t) |
Time as milliseconds. | |
su_time64_t | su_time64_add (su_time64_t t, su_duration_t offset) |
Add offset in milliseconds to 64-bit nanosecond time. | |
uint32_t | su_random (void) |
Generate a random 32-bit unsigned integer. | |
Time types and functions.
#define SU_TIME64_MAX |
Maximum value of su_time64_t type.
#define SU_TIME_CMP | ( | t1, | |
t2 | |||
) |
Compare two timestamps.
The macro SU_TIME_CMP() compares two su_time_t timestamps.
t1 | first NTP timestamp in su_time_t structure |
t2 | second NTP timestamp in su_time_t structure |
negative,if | t1 is before t2, |
zero,if | t1 is same as t2, or |
positive,if | t1 is after t2. |
#define SU_TIME_EPOCH |
Seconds from 1.1.1900 to 1.1.1970.
typedef int64_t su_dur64_t |
Time offset (duration) in nanoseconds.
typedef long su_duration_t |
Time difference in microseconds.
The type su_duration_t is used to present small time differences (24 days), usually calculated between two su_time_t timestamps. Note that the su_duration_t is signed.
NTP timestamp.
NTP timestamp is defined as microseconds since epoch (1-Jan-1900) with 64-bit resolution.
typedef uint64_t su_time64_t |
Time in nanoseconds.
su_duration_t su_duration | ( | su_time_t const | t1, |
su_time_t const | t2 | ||
) |
Time difference in milliseconds.
Calculates the duration from t2 to t1 in milliseconds.
t1 | after time |
t2 | before time |
su_duration_t su_duration64 | ( | su_time64_t | t1, |
su_time64_t | t2 | ||
) |
Time difference in milliseconds.
Calculates the duration from t2 to t1 in milliseconds.
t1 | after time |
t2 | before time |
If the difference is bigger than SU_DURATION_MAX, return SU_DURATION_MAX instead.
If the difference is smaller than -SU_DURATION_MAX, return -SU_DURATION_MAX instead.
su_time64_t su_monotime | ( | su_time64_t * | return_time | ) |
Get current monotonic time as nanoseconds.
Return the current time expressed as nanoseconds. The time returned is monotonic and never goes back - if the underlying system supports such a clock.
return_time | optional pointer to return the current time |
su_time64_t su_nanotime | ( | su_time64_t * | return_time | ) |
Get current time as nanoseconds since epoch.
Return the current NTP timestamp expressed as nanoseconds since epoch (January 1st 1900).
return_time | optional pointer to current time to return |
su_time_t su_now | ( | void | ) |
Get current time.
Return the current timestamp in su_time_t structure.
su_time64_t su_now64 | ( | void | ) |
Get current time as nanoseconds since epoch.
Return the current NTP timestamp expressed as nanoseconds since epoch (January 1st 1900).
High 32 bit of NTP timestamp.
ntp | 64bit NTP timestamp. |
Low 32 bit of NTP timestamp.
ntp | 64bit NTP timestamp. |
Middle 32 bit of NTP timestamp.
ntp | 64bit NTP timestamp. |
su_ntp_t su_ntp_now | ( | void | ) |
Get NTP timestamp.
The function su_ntp_now() returns the current NTP timestamp. NTP timestamp is seconds elapsed since January 1st, 1900.
uint32_t su_ntp_sec | ( | void | ) |
Get NTP seconds.
The function su_ntp_sec() returns the seconds elapsed since January 1st, 1900.
su_time64_t su_stamp64 | ( | void | ) |
Get current monotonic timestamp as nanoseconds.
Return the current timestamp expressed as nanoseconds. The time returned is monotonic and never goes back - if the underlying system supports such a clock.
void su_time | ( | su_time_t * | tv | ) |
Get current time.
The function su_time()
fills its argument with the current NTP timestamp expressed as a su_time_t structure.
tv | pointer to the timeval object |
|
inline |
Add offset in milliseconds to 64-bit nanosecond time.
su_time_t su_time_add | ( | su_time_t | t0, |
su_duration_t | dur | ||
) |
Add milliseconds to the time.
t0 | time in seconds and microseconds as su_time_t |
dur | milliseconds to be added |
Compare two timestamps.
The function su_time_cmp() compares two su_time_t timestamps.
t1 | first NTP timestamp in su_time_t structure |
t2 | second NTP timestamp in su_time_t structure |
Negative,if | t1 is before t2, |
Zero,if | t1 is same as t2, or |
Positive,if | t1 is after t2. |
Add seconds to the time.
t0 | time in seconds and microseconds as su_time_t |
sec | seconds to be added |
su_time_t
. Difference between two timestamps.
The function returns difference between two timestamps in seconds (t1 - t2).
t1 | first timeval |
t2 | second timeval |
int su_time_print | ( | char * | s, |
int | n, | ||
su_time_t const * | tv | ||
) |
Print su_time_t timestamp.
This function prints a su_time_t timestamp as a decimal number to the given buffer.
s | pointer to buffer |
n | buffer size |
tv | pointer to the timeval object |
NUL
.