OSSL_TIME.pod 7.4 KB

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