Home | History | Annotate | Line # | Download | only in man3
      1 =pod
      2 
      3 =head1 NAME
      4 
      5 OSSL_TIME, OSSL_TIME_SECOND, OSSL_TIME_MS, OSSL_TIME_US,
      6 ossl_time_infinite, ossl_time_zero, ossl_time_now,
      7 ossl_ticks2time, ossl_time2ticks, ossl_seconds2time, ossl_time2seconds,
      8 ossl_ms2time, ossl_us2time, ossl_time2ms, ossl_time2us,
      9 ossl_time_to_timeval, ossl_time_from_timeval,
     10 ossl_time_to_time_t, ossl_time_from_time_t,
     11 ossl_time_compare, ossl_time_is_zero, ossl_time_is_infinite,
     12 ossl_time_add, ossl_time_subtract,
     13 ossl_time_multiply, ossl_time_divide, ossl_time_muldiv,
     14 ossl_time_abs_difference, ossl_time_max,
     15 ossl_time_min - times and durations
     16 
     17 =head1 SYNOPSIS
     18 
     19  #include "internal/time.h"
     20 
     21  typedef struct OSSL_TIME;
     22 
     23  #define OSSL_TIME_SECOND   /* Ticks per second */
     24  #define OSSL_TIME_MS       /* Ticks per millisecond */
     25  #define OSSL_TIME_US       /* Ticks per microsecond */
     26 
     27  OSSL_TIME ossl_ticks2time(uint64_t);
     28  uint64_t ossl_time2ticks(OSSL_TIME t);
     29  OSSL_TIME ossl_seconds2time(uint64_t);
     30  uint64_t ossl_time2seconds(OSSL_TIME t);
     31  OSSL_TIME ossl_ms2time(uint64_t);
     32  uint64_t ossl_time2ms(OSSL_TIME t);
     33  OSSL_TIME ossl_us2time(uint64_t);
     34  uint64_t ossl_time2us(OSSL_TIME t);
     35 
     36  OSSL_TIME ossl_time_zero(void);
     37  OSSL_TIME ossl_time_infinite(void);
     38  OSSL_TIME ossl_time_now(void);
     39 
     40  struct timeval ossl_time_to_timeval(OSSL_TIME t);
     41  OSSL_TIME ossl_time_from_timeval(struct timeval tv);
     42  time_t ossl_time_to_time_t(OSSL_TIME t);
     43  OSSL_TIME ossl_time_from_time_t(time_t t);
     44 
     45  int ossl_time_compare(OSSL_TIME a, OSSL_TIME b);
     46  int ossl_time_is_zero(OSSL_TIME t);
     47  int ossl_time_is_infinite(OSSL_TIME t);
     48 
     49  OSSL_TIME ossl_time_add(OSSL_TIME a, OSSL_TIME b);
     50  OSSL_TIME ossl_time_subtract(OSSL_TIME a, OSSL_TIME b);
     51  OSSL_TIME ossl_time_multiply(OSSL_TIME a, uint64_t b);
     52  OSSL_TIME ossl_time_divide(OSSL_TIME a, uint64_t b);
     53  OSSL_TIME ossl_time_muldiv(OSSL_TIME a, uint64_t b, uint64_t c);
     54  OSSL_TIME ossl_time_abs_difference(OSSL_TIME a, OSSL_TIME b);
     55  OSSL_TIME ossl_time_max(OSSL_TIME a, OSSL_TIME b);
     56  OSSL_TIME ossl_time_min(OSSL_TIME a, OSSL_TIME b);
     57 
     58 =head1 DESCRIPTION
     59 
     60 These functions allow the current time to be obtained and for basic
     61 arithmetic operations to be safely performed with times and durations.
     62 
     63 B<OSSL_TIME> can represent a duration, or a point in time. Where it is
     64 used to represent a point in time, it does so by expressing a duration
     65 relative to some reference Epoch.  The OSSL_TIME structure itself does
     66 not contain information about the Epoch used; thus, interpretation of
     67 an OSSL_TIME requires that the Epoch it is to be interpreted relative
     68 to is contextually understood.
     69 
     70 B<OSSL_TIME_SECOND> is an integer that indicates the precision of an
     71 B<OSSL_TIME>.  Specifically, it is the number of counts per second that
     72 a time can represent.  The accuracy is independent of this and is system
     73 dependent.
     74 
     75 B<ossl_ticks2time> converts an integral number of counts to a time.
     76 
     77 B<ossl_time2ticks> converts a time to an integral number of counts.
     78 
     79 B<ossl_seconds2time>, B<ossl_ms2time> and B<ossl_us2time> convert an
     80 integral number of seconds, milliseconds and microseconds respectively
     81 to a time.  These functions are implemented as macros.
     82 
     83 B<ossl_time2seconds>, B<ossl_time2ms> and B<ossl_time2us> convert a
     84 time to an integral number of second, milliseconds and microseconds
     85 respectively.  These functions truncates any fractional seconds and are
     86 implemented as macros.
     87 
     88 B<ossl_time_zero> returns the smallest representable B<OSSL_TIME>.
     89 This value represents the time Epoch and it is returned when an underflow
     90 would otherwise occur.
     91 
     92 B<ossl_time_infinite> returns the largest representable B<OSSL_TIME>.
     93 This value is returned when an overflow would otherwise occur.
     94 
     95 B<ossl_time_now> returns the current time relative to an Epoch which
     96 is undefined but unchanging for at least the duration of program
     97 execution.  The time returned is monotonic and need not represent
     98 wall-clock time.  The time returned by this function is useful for
     99 scheduling timeouts, deadlines and recurring events, but due to its
    100 undefined Epoch and monotonic nature, is not suitable for other uses.
    101 
    102 B<ossl_time_to_timeval> converts a time to a I<struct timeval>.
    103 
    104 B<ossl_time_from_timeval> converts a I<struct timeval> to a time.
    105 
    106 B<ossl_time_to_time_t> converts a time to a I<time_t>.
    107 
    108 B<ossl_time_from_time_t> converts a I<time_t> to a time.
    109 
    110 B<ossl_time_compare> compares I<a> with I<b> and returns -1 if I<a>
    111 is smaller than I<b>, 0 if they are equal and +1 if I<a> is
    112 larger than I<b>.
    113 
    114 B<ossl_time_is_zero> returns 1 if the time I<t> is zero and 0 otherwise.
    115 
    116 B<ossl_time_is_infinite> returns 1 if the time I<t> is infinite and 0 otherwise.
    117 
    118 B<ossl_time_add> performs a saturating addition of the two times,
    119 returning I<a> + I<b>.
    120 If the summation would overflow B<OSSL_TIME_INFINITY> is returned.
    121 
    122 B<ossl_time_subtract> performs a saturating subtraction of the two items,
    123 returning I<a> - I<b>.
    124 If the difference would be negative,  B<0> is returned.
    125 
    126 B<ossl_time_multiply> performs a saturating multiplication of a time value by a
    127 given integer multiplier returning I<a> &#xD7; I<b>.
    128 
    129 B<ossl_time_divide> performs division of a time value by a given integer
    130 divisor returning &#x230A;I<a> &#xF7; I<b>&#x230B;.
    131 
    132 B<ossl_time_muldiv> performs a fused multiplication and division operation.
    133 The result is equal to &#x230A;I<a> &#xD7; I<b> &#xF7; I<c>&#x230B;.
    134 
    135 B<ossl_time_abs_difference> returns the magnitude of the difference between two
    136 time values.
    137 
    138 B<ossl_time_min> returns the lesser of two time values.
    139 
    140 B<ossl_time_max> returns the greater of two time values.
    141 
    142 =head1 NOTES
    143 
    144 The largest representable duration is guaranteed to be at least 500 years.
    145 
    146 =head1 RETURN VALUES
    147 
    148 B<ossl_time_now> returns the current time, or the time of the Epoch on error.
    149 
    150 B<ossl_time_zero> returns the time of the Epoch.
    151 
    152 B<ossl_time_infinite> returns the last representable time.
    153 
    154 B<ossl_ticks2time>, B<ossl_seconds2time>, B<ossl_ms2time> and B<ossl_us2time>
    155 return the duration specified in ticks, seconds, milliseconds and microseconds
    156 respectively.
    157 
    158 B<ossl_time2ticks>, B<ossl_time2seconds>, B<ossl_time2ms> and B<ossl_time2us>
    159 return the number of ticks, seconds, microseconds and microseconds respectively
    160 that the time object represents.
    161 
    162 B<ossl_time_to_timeval>, B<ossl_time_from_timeval>, B<ossl_time_to_time_t> and
    163 B<ossl_time_from_time_t> all return the converted time.
    164 
    165 B<ossl_time_compare> returns -1, 0 or 1 depending on the comparison.
    166 
    167 B<ossl_time_is_zero> and B<ossl_time_is_infinite> return 1 if the condition
    168 is true and 0 otherwise.
    169 
    170 B<ossl_time_add> returns the summation of the two times or
    171 the last representable time on overflow.
    172 
    173 B<ossl_time_subtract> returns the difference of the two times or the
    174 time of the Epoch on underflow.
    175 
    176 B<ossl_time_multiply> returns the result of multiplying the given time by the
    177 given integral multiplier, or B<OSSL_TIME_INFINITY> on overflow.
    178 
    179 B<ossl_time_divide> returns the result of dividing the given time by the given
    180 integral divisor.
    181 
    182 B<ossl_time_muldiv> returns the fused multiplication and division of the given
    183 time and the two integral values.
    184 
    185 B<ossl_time_abs_difference> returns the magnitude of the difference between the
    186 input time values.
    187 
    188 B<ossl_time_min> and B<ossl_time_max> choose and return one of the input values.
    189 
    190 =head1 HISTORY
    191 
    192 This functionality was added in OpenSSL 3.2.
    193 
    194 =head1 COPYRIGHT
    195 
    196 Copyright 2022 The OpenSSL Project Authors. All Rights Reserved.
    197 
    198 Licensed under the Apache License 2.0 (the "License").  You may not use this
    199 file except in compliance with the License.  You can obtain a copy in the file
    200 LICENSE in the source distribution or at
    201 L<https://www.openssl.org/source/license.html>.
    202 
    203 =cut
    204