]>
Commit | Line | Data |
---|---|---|
9f40251d P |
1 | =pod |
2 | ||
3 | =head1 NAME | |
4 | ||
d13c8b77 P |
5 | OSSL_TIME, OSSL_TIME_SECOND, ossl_time_infinite, ossl_time_zero, |
6 | ossl_ticks2time, ossl_time2ticks, | |
9f40251d P |
7 | ossl_time_now, ossl_time_time_to_timeval, ossl_time_compare, |
8 | ossl_time_add, ossl_time_subtract | |
9 | - times and durations | |
10 | ||
11 | =head1 SYNOPSIS | |
12 | ||
13 | #include "internal/time.h" | |
14 | ||
d13c8b77 | 15 | typedef struct OSSL_TIME; |
9f40251d | 16 | |
d13c8b77 | 17 | #define OSSL_TIME_SECOND /* Ticks per second */ |
9f40251d | 18 | |
d13c8b77 P |
19 | OSSL_TIME ossl_ticks2time(uint64_t); |
20 | uint64_t ossl_time2ticks(OSSL_TIME t); | |
21 | ||
22 | OSSL_TIME ossl_time_zero(void); | |
23 | OSSL_TIME ossl_time_infinite(void); | |
9f40251d | 24 | OSSL_TIME ossl_time_now(void); |
d13c8b77 | 25 | |
9f40251d P |
26 | void ossl_time_time_to_timeval(OSSL_TIME t, struct timeval *out); |
27 | ||
28 | int ossl_time_compare(OSSL_TIME a, OSSL_TIME b); | |
29 | OSSL_TIME ossl_time_add(OSSL_TIME a, OSSL_TIME b); | |
30 | OSSL_TIME ossl_time_subtract(OSSL_TIME a, OSSL_TIME b); | |
31 | ||
32 | =head1 DESCRIPTION | |
33 | ||
34 | These functions allow the current time to be obtained and for basic | |
35 | arithmetic operations to be safely performed with times and durations. | |
36 | ||
37 | B<OSSL_TIME> can represent a duration, or a point in time. Where it is | |
38 | used to represent a point in time, it does so by expressing a duration | |
39 | relative to some reference Epoch. The OSSL_TIME structure itself does | |
40 | not contain information about the Epoch used; thus, interpretation of | |
41 | an OSSL_TIME requires that the Epoch it is to be interpreted relative | |
42 | to is contextually understood. | |
43 | ||
44 | B<OSSL_TIME_SECOND> is an integer that indicates the precision of an | |
45 | B<OSSL_TIME>. Specifically, it is the number of counts per second that | |
46 | a time can represent. The accuracy is independent of this and is system | |
47 | dependent. | |
48 | ||
d13c8b77 P |
49 | B<ossl_ticks2time> converts an integral number of counts to a time. |
50 | ||
51 | B<ossl_time2ticks> converts a time to an integral number of counts. | |
52 | ||
53 | B<ossl_time_zero> returns the smallest representable B<OSSL_TIME>. | |
54 | This value represents the time Epoch and it is returned when an underflow | |
55 | would otherwise occur. | |
56 | ||
57 | B<ossl_time_infinite> returns the largest representable B<OSSL_TIME>. | |
58 | This value is returned when an overflow would otherwise occur. | |
9f40251d P |
59 | |
60 | B<ossl_time_now> returns the current time relative to an Epoch which | |
61 | is undefined but unchanging for at least the duration of program | |
62 | execution. The time returned is monotonic and need not represent | |
63 | wall-clock time. The time returned by this function is useful for | |
64 | scheduling timeouts, deadlines and recurring events, but due to its | |
65 | undefined Epoch and monotonic nature, is not suitable for other uses. | |
66 | ||
67 | B<ossl_time_time_to_timeval> converts a time to a I<struct timeval>. | |
68 | ||
69 | B<ossl_time_compare> compares I<a> with I<b> and returns -1 if I<a> | |
70 | is smaller than I<b>, 0 if they are equal and +1 if I<a> is | |
71 | larger than I<b>. | |
72 | ||
73 | B<ossl_time_add> performs a saturating addition of the two times, | |
74 | returning I<a> + I<b>. | |
75 | If the summation would overflow B<OSSL_TIME_INFINITY> is returned. | |
76 | ||
77 | B<ossl_time_subtract> performs a saturating subtraction of the two items, | |
78 | returning I<a> - I<b>. | |
79 | If the difference would be negative, B<0> is returned. | |
80 | ||
81 | =head1 NOTES | |
82 | ||
83 | The largest representable duration is guaranteed to be at least 500 years. | |
84 | ||
85 | =head1 RETURN VALUES | |
86 | ||
d13c8b77 P |
87 | B<ossl_time_now> returns the current time, or the time of the Epoch on error. |
88 | ||
89 | B<ossl_time_zero> returns the time of the Epoch. | |
90 | ||
91 | B<ossl_time_infinite> returns the last representable time. | |
92 | ||
93 | B<ossl_ticks2time> return the duration specified. | |
94 | ||
95 | B<ossl_time2ticks> returns the ticks since Epoch. | |
9f40251d P |
96 | |
97 | B<ossl_time_compare> returns -1, 0 or 1 depending on the comparison. | |
98 | ||
99 | B<ossl_time_add> returns the summation of the two times or | |
d13c8b77 | 100 | the last representable time on overflow. |
9f40251d P |
101 | |
102 | B<ossl_time_subtract> returns the difference of the two times or the | |
d13c8b77 | 103 | time of the Epoch on underflow. |
9f40251d P |
104 | |
105 | =head1 HISTORY | |
106 | ||
107 | This functionality was added in OpenSSL 3.1. | |
108 | ||
109 | =head1 COPYRIGHT | |
110 | ||
111 | Copyright 2022 The OpenSSL Project Authors. All Rights Reserved. | |
112 | ||
113 | Licensed under the Apache License 2.0 (the "License"). You may not use this | |
114 | file except in compliance with the License. You can obtain a copy in the file | |
115 | LICENSE in the source distribution or at | |
116 | L<https://www.openssl.org/source/license.html>. | |
117 | ||
118 | =cut |