OSSL_EVENT.pod 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. =pod
  2. =head1 NAME
  3. OSSL_EVENT_QUEUE, OSSL_EVENT, OSSL_EVENT_SUBSCRIPTION, ossl_event_callback_fn,
  4. ossl_event_queue_add, ossl_event_queue_add_new, ossl_event_free,
  5. ossl_event_get_type, ossl_event_get_priority, ossl_event_get_when,
  6. ossl_event_get0_payload,
  7. ossl_event_queue_new, ossl_event_queue_free,
  8. ossl_event_queue_schedule, ossl_event_queue_delete,
  9. ossl_event_time_until, ossl_event_queue_time_until_next,
  10. ossl_event_queue_postpone_until,
  11. ossl_event_queue_get1_next_event
  12. - event and timer queue
  13. =head1 SYNOPSIS
  14. #include "internal/event_queue.h"
  15. typedef OSSL_EVENT;
  16. typedef OSSL_EVENT_QUEUE;
  17. typedef OSSL_EVENT_SUBSCRIPTION;
  18. typedef int ossl_event_callback_fn(OSSL_EVENT *event, void *callback_data);
  19. OSSL_EVENT_QUEUE *ossl_event_queue_new(void);
  20. void ossl_event_queue_free(OSSL_EVENT_QUEUE *queue);
  21. int ossl_event_queue_add(OSSL_EVENT_QUEUE *queue, OSSL_EVENT *event,
  22. uint32_t type, uint32_t priority,
  23. OSSL_TIME when, void *ctx,
  24. void *payload, size_t payload_size);
  25. OSSL_EVENT *ossl_event_queue_add_new(OSSL_EVENT_QUEUE *queue,
  26. uint32_t type, uint32_t priority,
  27. OSSL_TIME when, void *ctx,
  28. void *payload, size_t payload_size);
  29. void ossl_event_free(OSSL_EVENT *event);
  30. uint32_t ossl_event_get_type(const OSSL_EVENT *event);
  31. uint32_t ossl_event_get_priority(const OSSL_EVENT *event);
  32. OSSL_TIME ossl_event_get_when(const OSSL_EVENT *event);
  33. void *ossl_event_get0_payload(const OSSL_EVENT *event, size_t *length);
  34. int ossl_event_queue_schedule(OSSL_EVENT_QUEUE *queue, OSSL_EVENT *event);
  35. int ossl_event_queue_delete(OSSL_EVENT_QUEUE *queue, OSSL_EVENT *event);
  36. OSSL_TIME ossl_event_time_until(OSSL_EVENT *event);
  37. OSSL_TIME ossl_event_queue_time_until_next(const OSSL_EVENT_QUEUE *queue);
  38. int ossl_event_queue_postpone_until(OSSL_EVENT_QUEUE *queue,
  39. OSSL_EVENT *event,
  40. OSSL_TIME when);
  41. int ossl_event_queue_get1_next_event(OSSL_EVENT_QUEUE *queue,
  42. OSSL_EVENT **event);
  43. =head1 DESCRIPTION
  44. These functions implement an event queue.
  45. =head2 Event
  46. An event is a small structure, B<OSSL_EVENT>, carrying information:
  47. =over 4
  48. =item type
  49. A mandatory event type, which is a simple numeric identity, the
  50. meaning of which is not known by the event functionality itself.
  51. =item priority
  52. A mandatory nonnegative integral quantity. The lower the priority the earlier
  53. the event will be processed.
  54. =item when
  55. An optional time indicating when the event could be triggered. Events are
  56. guaranteed to not trigger before their time.
  57. =item context
  58. A reference to user supplied contextual information. The event queue passes
  59. this to callbacks and never dereferences the pointer.
  60. =item payload, payload_size
  61. A reference to some event specific data of a specified length.
  62. =back
  63. The event itself is designed for a single synchronous thread, i.e. cannot be
  64. shared by multiple threads. The diverse objects it refers to may, however,
  65. be shared by multiple threads, at the discretion of the functions in the
  66. method structure.
  67. Once populated, the event type, the references to event context, and the
  68. reference to the destructor function are considered immutable, up until the
  69. event structure is destroyed.
  70. The reference to the auxiliary identifying material or to the payload,
  71. however, are considered mutable. Any event handler may "steal" them and
  72. replace the reference to them in the event structure with NULL. Stealing
  73. must be done with much care.
  74. Events may be embedded in another structure or as a static variable.
  75. Events may also be dynamically allocated.
  76. B<ossl_event_queue_add> initialises/reinitialises a static event object
  77. with the specified parameters and adds it to the event queue I<queue>.
  78. The event object I<event> has it's fields set to the passed parameters.
  79. B<ossl_event_queue_add_new> allocates a new timer event on the heap
  80. and initialises and adds it as per B<ossl_event_queue_add>. A pointer to the
  81. new event is returned on success and NULL is returned on error.
  82. B<ossl_event_free> frees an allocated event returned by B<ossl_event_new>.
  83. Does nothing if passed a pointer to a static event object which was initialised
  84. using B<ossl_event_set>.
  85. B<ossl_event_time_until> returns the time until I<event> would
  86. trigger. The event need not be part of an event queue.
  87. B<ossl_event_queue_postpone_until> reschedules the I<event>, which must
  88. be scheduled as part of timer event queue I<queue>, so that it will activate
  89. at time I<when>.
  90. B<ossl_event_get_type> returns the type of the I<event>.
  91. B<ossl_event_get_priority> returns the priority of the I<event>.
  92. B<ossl_event_get_when> returns the triggering time of the I<event>.
  93. B<ossl_event_get0_payload> returns the payload for the I<event>, the length
  94. of the payload is stored in I<length>.
  95. =head2 Event queue
  96. B<OSSL_EVENT_QUEUE> is an opaque structure that defines a timer based
  97. event queue. Event queue objects can only be dynamically allocated.
  98. B<ossl_event_queue_new> returns a newly allocated event queue object.
  99. B<ossl_event_queue_free> frees a event queue object returned by
  100. B<ossl_event_queue_new>.
  101. B<ossl_event_queue_schedule> adds the specified I<event> to the timer
  102. event queue I<queue>. The I<event> must not already be contained by any
  103. timer event queue including I<queue>.
  104. B<ossl_event_queue_delete> removes the specified I<event> from the
  105. timer event queue I<queue>. The event must have previously been added
  106. to I<queue> using the B<ossl_event_queue_schedule> call and must not yet
  107. have triggered.
  108. B<ossl_event_queue_time_until_next> returns the time until the next
  109. event in the timer event queue I<queue> is scheduled to trigger.
  110. B<ossl_event_queue_get1_next_event> gets the next event to process.
  111. The event is removed from the event queue and, if dynamically allocated,
  112. must be freed by the caller. A NULL event is returned if there is no event
  113. to process.
  114. =head1 RETURN VALUES
  115. B<ossl_event_queue_new> returns a new timer queue or NULL on failure.
  116. B<ossl_event_new> returns a new event or NULL on failure.
  117. B<ossl_event_get_type>, B<ossl_event_get_priority> and
  118. B<ossl_event_get_when> return the corresponding event field.
  119. B<ossl_event_get0_payload> returns a pointer to the event's payload.
  120. B<ossl_event_queue_add>, B<ossl_event_queue_remove>,
  121. B<ossl_event_queue_postpone_until> and
  122. B<ossl_event_queue_get1_next_event> return 1 on success and 0 on failure.
  123. B<ossl_event_time_until> and B<ossl_event_queue_time_until_next>
  124. return a time until the next event or B<OSSL_TIME_INFINITY> if there is no
  125. next event.
  126. =head1 SEE ALSO
  127. L<OSSL_TIME(3)>
  128. =head1 HISTORY
  129. This functionality was added to OpenSSL 3.2.
  130. =head1 COPYRIGHT
  131. Copyright 2022-2023 The OpenSSL Project Authors. All Rights Reserved.
  132. Licensed under the Apache License 2.0 (the "License"). You may not use this
  133. file except in compliance with the License. You can obtain a copy in the file
  134. LICENSE in the source distribution or at
  135. L<https://www.openssl.org/source/license.html>.
  136. =cut