SSL_poll.pod 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. =pod
  2. =head1 NAME
  3. SSL_poll,
  4. SSL_POLL_EVENT_NONE,
  5. SSL_POLL_EVENT_F,
  6. SSL_POLL_EVENT_EC,
  7. SSL_POLL_EVENT_ECD,
  8. SSL_POLL_EVENT_ER,
  9. SSL_POLL_EVENT_EW,
  10. SSL_POLL_EVENT_R,
  11. SSL_POLL_EVENT_W,
  12. SSL_POLL_EVENT_ISB,
  13. SSL_POLL_EVENT_ISU,
  14. SSL_POLL_EVENT_OSB,
  15. SSL_POLL_EVENT_OSU,
  16. SSL_POLL_EVENT_RW,
  17. SSL_POLL_EVENT_RE,
  18. SSL_POLL_EVENT_WE,
  19. SSL_POLL_EVENT_RWE,
  20. SSL_POLL_EVENT_E,
  21. SSL_POLL_EVENT_IS,
  22. SSL_POLL_EVENT_ISE,
  23. SSL_POLL_EVENT_I,
  24. SSL_POLL_EVENT_OS,
  25. SSL_POLL_EVENT_OSE,
  26. SSL_POLL_FLAG_NO_HANDLE_EVENTS
  27. - determine or await readiness conditions for one or more pollable objects
  28. =head1 SYNOPSIS
  29. #include <openssl/ssl.h>
  30. #define SSL_POLL_EVENT_NONE 0
  31. #define SSL_POLL_EVENT_F /* F (Failure) */
  32. #define SSL_POLL_EVENT_EC /* EC (Exception on Conn) */
  33. #define SSL_POLL_EVENT_ECD /* ECD (Exception on Conn Drained) */
  34. #define SSL_POLL_EVENT_ER /* ER (Exception on Read) */
  35. #define SSL_POLL_EVENT_EW /* EW (Exception on Write) */
  36. #define SSL_POLL_EVENT_R /* R (Readable) */
  37. #define SSL_POLL_EVENT_W /* W (Writable) */
  38. #define SSL_POLL_EVENT_ISB /* ISB (Incoming Stream: Bidi) */
  39. #define SSL_POLL_EVENT_ISU /* ISU (Incoming Stream: Uni) */
  40. #define SSL_POLL_EVENT_OSB /* OSB (Outgoing Stream: Bidi) */
  41. #define SSL_POLL_EVENT_OSU /* OSU (Outgoing Stream: Uni) */
  42. #define SSL_POLL_EVENT_RW /* R | W */
  43. #define SSL_POLL_EVENT_RE /* R | ER */
  44. #define SSL_POLL_EVENT_WE /* W | EW */
  45. #define SSL_POLL_EVENT_RWE /* RE | WE */
  46. #define SSL_POLL_EVENT_E /* EC | ER | EW */
  47. #define SSL_POLL_EVENT_IS /* ISB | ISU */
  48. #define SSL_POLL_EVENT_ISE /* IS | EC */
  49. #define SSL_POLL_EVENT_I /* IS */
  50. #define SSL_POLL_EVENT_OS /* OSB | OSU */
  51. #define SSL_POLL_EVENT_OSE /* OS | EC */
  52. typedef struct ssl_poll_item_st {
  53. BIO_POLL_DESCRIPTOR desc;
  54. uint64_t events, revents;
  55. } SSL_POLL_ITEM;
  56. #define SSL_POLL_FLAG_NO_HANDLE_EVENTS
  57. int SSL_poll(SSL_POLL_ITEM *items,
  58. size_t num_items,
  59. size_t stride,
  60. const struct timeval *timeout,
  61. uint64_t flags,
  62. size_t *result_count);
  63. =head1 DESCRIPTION
  64. SSL_poll() allows the readiness conditions of the resources represented by one
  65. or more BIO_POLL_DESCRIPTOR structures to be determined. In particular, it can
  66. be used to query for readiness conditions on QUIC connection SSL objects and
  67. QUIC stream SSL objects in a single call.
  68. A call to SSL_poll() specifies an array of B<SSL_POLL_ITEM> structures, each of
  69. which designates a resource which is being polled for readiness, and a set of
  70. event flags which indicate the specific readiness events which the caller is
  71. interested in in relation to the specified resource.
  72. The fields of B<SSL_POLL_ITEM> are as follows:
  73. =over 4
  74. =item I<desc>
  75. The resource being polled for readiness, as represented by a
  76. B<BIO_POLL_DESCRIPTOR>. Currently, this must be a poll descriptor of type
  77. B<BIO_POLL_DESCRIPTOR_TYPE_SSL>, representing a SSL object pointer, and the SSL
  78. object must be a QUIC connection SSL object or QUIC stream SSL object.
  79. If a B<SSL_POLL_ITEM> has a poll descriptor type of
  80. B<BIO_POLL_DESCRIPTOR_TYPE_NONE>, or the SSL object pointer is NULL, the
  81. B<SSL_POLL_ITEM> array entry is ignored and I<revents> will be set to 0 on
  82. return.
  83. =item I<events>
  84. This is the set of zero or more events which the caller is interested in
  85. learning about in relation to the resource described by I<desc>. It is a
  86. collection of zero or more B<SSL_POLL_EVENT> flags. See L</EVENT TYPES> for a
  87. description of each of the event types.
  88. =item I<revents>
  89. After SSL_poll() returns, this is the set of zero or more events which are
  90. actually applicable to the resource described by I<desc>. As for I<events>,
  91. it is a collection of zero or more B<SSL_POLL_EVENT> flags.
  92. I<revents> need not be a subset of the events specified in I<events>, as some
  93. event types are defined as always being enabled (non-maskable). See L</EVENT
  94. TYPES> for more information.
  95. =back
  96. To use SSL_poll(), call it with an array of B<SSL_POLL_ITEM> structures. The
  97. array need remain allocated only for the duration of the call. I<num_items> must
  98. be set to the number of entries in the array, and I<stride> must be set to
  99. C<sizeof(SSL_POLL_ITEM)>.
  100. The present implementation of SSL_poll() is a subset of the functionality which
  101. will eventually be available. Only a nonblocking mode of operation is available
  102. at this time, where SSL_poll() always returns immediately. As such, I<timeout>
  103. must point to a valid B<struct timeval> and that structure must be set to zero.
  104. In future, other inputs to the I<timeout> argument will result in a blocking
  105. mode of operation, which is not currently supported. For more information, see
  106. L</LIMITATIONS>.
  107. The following flags are currently defined for the I<flags> argument:
  108. =over 4
  109. =item B<SSL_POLL_FLAG_NO_HANDLE_EVENTS>
  110. This flag indicates that internal state machine processing should not be
  111. performed in an attempt to generate new readiness events. Only existing
  112. readiness events will be reported.
  113. =back
  114. The I<result_count> argument is optional. If it is non-NULL, it is used to
  115. output the number of entries in the array which have nonzero I<revents> fields
  116. when the call to SSL_poll() returns; see L</RETURN VALUES> for details.
  117. =head1 EVENT TYPES
  118. The SSL_poll() interface reports zero or more event types on a given resource,
  119. represented by a bit mask.
  120. All of the event types are level triggered and represent a readiness or
  121. permanent exception condition; as such, after an event has been reported by
  122. SSL_poll() for a resource, it will continue to be reported in future SSL_poll()
  123. calls until the condition ceases to be in effect. A caller must mask the given
  124. event type bit in future SSL_poll() calls if it does not wish to receive
  125. repeated notifications and has not caused the underlying readiness condition
  126. (for example, consuming all available data using L<SSL_read_ex(3)> after
  127. B<SSL_POLL_EVENT_R> is reported) to be deasserted.
  128. Some event types do not make sense on a given kind of resource. In this case,
  129. specifying that event type in I<events> is a no-op and will be ignored, and the
  130. given event will never be reported in I<revents>.
  131. Failure of the polling mechanism itself is considered distinct from an exception
  132. condition on a resource which was successfully polled. See B<SSL_POLL_EVENT_F>
  133. and L</RETURN VALUES> for details.
  134. In general, an application should always listen for the event types
  135. corresponding to exception conditions if it is listening to the corresponding
  136. non-exception event types (e.g. B<SSL_POLL_EVENT_EC> and B<SSL_POLL_EVENT_ER>
  137. for B<SSL_POLL_EVENT_R>), as not doing so is unlikely to be a sound design.
  138. Some event types are non-maskable and may be reported in I<revents> regardless
  139. of whether they were requested in I<events>.
  140. The following event types are supported:
  141. =over 4
  142. =item B<SSL_POLL_EVENT_F>
  143. Polling failure. This event is raised when a resource could not be polled. It is
  144. distinct from an exception condition reported on a resource which was
  145. successfully polled and represents a failure of the polling process itself in
  146. relation to a resource. This may mean that SSL_poll() does not support the kind
  147. of resource specified.
  148. Where this event is raised on at least one item in I<items>, SSL_poll() will
  149. return 0 and the ERR stack will contain information pertaining to the first item
  150. in I<items> with B<SSL_POLL_EVENT_F> set. See L</RETURN VALUES> for more
  151. information.
  152. This event type may be raised even if it was not requested in I<events>;
  153. specifying this event type in I<events> does nothing.
  154. =item B<SSL_POLL_EVENT_EC>
  155. Error at connection level. This event is raised when a connection has failed.
  156. In particular, it is raised when a connection begins terminating.
  157. This event is never raised on objects which are not connections.
  158. =item B<SSL_POLL_EVENT_DCD>
  159. Error at connection level (drained). This event is raised when a connection has
  160. finished terminating, and has reached the terminated state. This event will
  161. generally occur after an interval of time passes after the B<SSL_POLL_EVENT_EC>
  162. event is raised on a connection.
  163. This event is never raised on objects which are not connections.
  164. =item B<SSL_POLL_EVENT_ER>
  165. Error in read direction. For QUIC, this is raised only in the event that a
  166. stream has a read part and that read part has been reset by the peer (for
  167. example, using a B<RESET_STREAM> frame).
  168. =item B<SSL_POLL_EVENT_EW>
  169. Error in write direction. For QUIC, this is raised only in the event that a
  170. stream has a write part and that write part has been reset by the peer using a
  171. B<STOP_SENDING> frame.
  172. =item B<SSL_POLL_EVENT_R>
  173. Readable. This event is raised when a QUIC stream SSL object (or a QUIC
  174. connection SSL object with a default stream attached) has application data
  175. waiting to be read using L<SSL_read_ex(3)>, or a FIN event as represented by
  176. B<SSL_ERROR_ZERO_RETURN> waiting to be read.
  177. It is not raised in the event of the receiving part of the QUIC stream being
  178. reset by the peer; see B<SSL_POLL_EVENT_ER>.
  179. =item B<SSL_POLL_EVENT_W>
  180. Writable. This event is raised when a QUIC stream SSL object (or a QUIC
  181. connection SSL object with a default stream attached) could accept more
  182. application data using L<SSL_write_ex(3)>.
  183. This event is never raised by a receive-only stream.
  184. This event is never raised by a stream which has had its send part concluded
  185. normally (as with L<SSL_stream_conclude(3)>) or locally reset (as with
  186. L<SSL_stream_reset(3)>).
  187. This event does not guarantee that a subsequent call to L<SSL_write_ex(3)> will
  188. succeed.
  189. =item B<SSL_POLL_EVENT_ISB>
  190. This event, which is only raised by a QUIC connection SSL object, is raised when
  191. one or more incoming bidirectional streams are available to be accepted using
  192. L<SSL_accept_stream(3)>.
  193. =item B<SSL_POLL_EVENT_ISU>
  194. This event, which is only raised by a QUIC connection SSL object, is raised when
  195. one or more incoming unidirectional streams are available to be accepted using
  196. L<SSL_accept_stream(3)>.
  197. =item B<SSL_POLL_EVENT_OSB>
  198. This event, which is only raised by a QUIC connection SSL object, is raised when
  199. QUIC stream creation flow control currently permits at least one additional
  200. bidirectional stream to be locally created.
  201. =item B<SSL_POLL_EVENT_OSU>
  202. This event, which is only raised by a QUIC connection SSL object, is raised when
  203. QUIC stream creation flow control currently permits at least one additional
  204. unidirectional stream to be locally created.
  205. =back
  206. =head1 LIMITATIONS
  207. SSL_poll() as presently implemented has the following limitations:
  208. =over 4
  209. =item
  210. The implementation of SSL_poll() only supports nonblocking operation and
  211. therefore requires the I<timeout> argument be used to specify a zero timeout.
  212. Calls to SSL_poll() which specify another value, or which pass I<timeout> as
  213. NULL, will fail. This does not allow waiting, but does allow multiple QUIC SSL
  214. objects to be queried for their readiness state in a single call.
  215. Future releases will remove this limitation and support blocking SSL_poll().
  216. =item
  217. Only B<BIO_POLL_DESCRIPTOR> structures with type
  218. B<BIO_POLL_DESCRIPTOR_TYPE_SSL>, referencing QUIC connection SSL objects or QUIC
  219. stream SSL objects, are supported.
  220. =back
  221. These limitations will be revised in a future release of OpenSSL.
  222. =head1 RETURN VALUES
  223. SSL_poll() returns 1 on success and 0 on failure.
  224. Unless the I<items> pointer itself is invalid, SSL_poll() will always initialise
  225. the I<revents> fields of all items in the input array upon returning, even if it
  226. returns failure.
  227. If I<result_count> is non-NULL, it is always written with the number of items in
  228. the array with nonzero I<revents> fields, even if the SSL_poll() call returns
  229. failure.
  230. It is possible for I<result_count> to be written as 0 even if the SSL_poll()
  231. call returns success, namely if no events were output but the polling process
  232. was successful (e.g. in nonblocking usage) or timed out.
  233. It is possible for I<result_count> to be written as a nonzero value if the
  234. SSL_poll() call returns failure, for example due to B<SSL_POLL_EVENT_F> events,
  235. or because some events were detected and output before encountering a failure
  236. condition while processing a subsequent entry in the I<items> array.
  237. If at least one B<SSL_POLL_EVENT_F> event is output, SSL_poll() is guaranteed
  238. to return 0 and guaranteed to place at least one ERR on the error stack
  239. describing the first B<SSL_POLL_EVENT_F> output. Detailed information on any
  240. additional B<SSL_POLL_EVENT_F> events is not available. SSL_poll() may or may
  241. not return more than one B<SSL_POLL_EVENT_F> event at once.
  242. "Normal" events representing exceptional I/O conditions which do not
  243. constitute a failure of the SSL_poll() mechanism itself are not considered
  244. errors by SSL_poll() and are instead represented using their own event type; see
  245. L</EVENT TYPES> for details.
  246. The caller can establish the meaning of the SSL_poll() return and output values
  247. as follows:
  248. =over 4
  249. =item
  250. If SSL_poll() returns 1 and I<result_count> is zero, the operation timed out
  251. before any resource was ready.
  252. =item
  253. If SSL_poll() returns 1 and I<result_count> is nonzero, that many events were
  254. output.
  255. =item
  256. If SSL_poll() returns 0 and I<result_count> is zero, the caller has made a basic
  257. usage error; check the ERR stack for details.
  258. =item
  259. If SSL_poll() returns 0 and I<result_count> is nonzero, inspect the I<items>
  260. array for B<SSL_POLL_ITEM> structures with the B<SSL_POLL_EVENT_F> event type
  261. raised in I<revents>. The entries added to the ERR stack (of which there is
  262. guaranteed to be at least one) reflect the cause of the failure of the first
  263. item in I<items> with B<SSL_POLL_EVENT_F> raised. Note that there may be events
  264. other than I<SSL_POLL_EVENT_F> output for items which come before the first
  265. item with B<SSL_POLL_EVENT_F> raised, and additional B<SSL_POLL_EVENT_F>
  266. events may or may not have been output, both of which which will be reflected in
  267. I<result_count>.
  268. =back
  269. =head1 SEE ALSO
  270. L<BIO_get_rpoll_descriptor(3)>, L<BIO_get_wpoll_descriptor(3)>,
  271. L<SSL_get_rpoll_descriptor(3)>, L<SSL_get_wpoll_descriptor(3)>
  272. =head1 HISTORY
  273. SSL_poll() was added in OpenSSL 3.3.
  274. =head1 COPYRIGHT
  275. Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
  276. Licensed under the Apache License 2.0 (the "License"). You may not use
  277. this file except in compliance with the License. You can obtain a copy
  278. in the file LICENSE in the source distribution or at
  279. L<https://www.openssl.org/source/license.html>.
  280. =cut