SSL_poll.3ossl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "SSL_POLL 3ossl"
  58. .TH SSL_POLL 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. SSL_poll,
  65. SSL_POLL_EVENT_NONE,
  66. SSL_POLL_EVENT_F,
  67. SSL_POLL_EVENT_EC,
  68. SSL_POLL_EVENT_ECD,
  69. SSL_POLL_EVENT_ER,
  70. SSL_POLL_EVENT_EW,
  71. SSL_POLL_EVENT_R,
  72. SSL_POLL_EVENT_W,
  73. SSL_POLL_EVENT_ISB,
  74. SSL_POLL_EVENT_ISU,
  75. SSL_POLL_EVENT_OSB,
  76. SSL_POLL_EVENT_OSU,
  77. SSL_POLL_EVENT_RW,
  78. SSL_POLL_EVENT_RE,
  79. SSL_POLL_EVENT_WE,
  80. SSL_POLL_EVENT_RWE,
  81. SSL_POLL_EVENT_E,
  82. SSL_POLL_EVENT_IS,
  83. SSL_POLL_EVENT_ISE,
  84. SSL_POLL_EVENT_I,
  85. SSL_POLL_EVENT_OS,
  86. SSL_POLL_EVENT_OSE,
  87. SSL_POLL_FLAG_NO_HANDLE_EVENTS
  88. \&\- determine or await readiness conditions for one or more pollable objects
  89. .SH SYNOPSIS
  90. .IX Header "SYNOPSIS"
  91. .Vb 1
  92. \& #include <openssl/ssl.h>
  93. \&
  94. \& #define SSL_POLL_EVENT_NONE 0
  95. \&
  96. \& #define SSL_POLL_EVENT_F /* F (Failure) */
  97. \& #define SSL_POLL_EVENT_EC /* EC (Exception on Conn) */
  98. \& #define SSL_POLL_EVENT_ECD /* ECD (Exception on Conn Drained) */
  99. \& #define SSL_POLL_EVENT_ER /* ER (Exception on Read) */
  100. \& #define SSL_POLL_EVENT_EW /* EW (Exception on Write) */
  101. \& #define SSL_POLL_EVENT_R /* R (Readable) */
  102. \& #define SSL_POLL_EVENT_W /* W (Writable) */
  103. \& #define SSL_POLL_EVENT_ISB /* ISB (Incoming Stream: Bidi) */
  104. \& #define SSL_POLL_EVENT_ISU /* ISU (Incoming Stream: Uni) */
  105. \& #define SSL_POLL_EVENT_OSB /* OSB (Outgoing Stream: Bidi) */
  106. \& #define SSL_POLL_EVENT_OSU /* OSU (Outgoing Stream: Uni) */
  107. \&
  108. \& #define SSL_POLL_EVENT_RW /* R | W */
  109. \& #define SSL_POLL_EVENT_RE /* R | ER */
  110. \& #define SSL_POLL_EVENT_WE /* W | EW */
  111. \& #define SSL_POLL_EVENT_RWE /* RE | WE */
  112. \& #define SSL_POLL_EVENT_E /* EC | ER | EW */
  113. \& #define SSL_POLL_EVENT_IS /* ISB | ISU */
  114. \& #define SSL_POLL_EVENT_ISE /* IS | EC */
  115. \& #define SSL_POLL_EVENT_I /* IS */
  116. \& #define SSL_POLL_EVENT_OS /* OSB | OSU */
  117. \& #define SSL_POLL_EVENT_OSE /* OS | EC */
  118. \&
  119. \& typedef struct ssl_poll_item_st {
  120. \& BIO_POLL_DESCRIPTOR desc;
  121. \& uint64_t events, revents;
  122. \& } SSL_POLL_ITEM;
  123. \&
  124. \& #define SSL_POLL_FLAG_NO_HANDLE_EVENTS
  125. \&
  126. \& int SSL_poll(SSL_POLL_ITEM *items,
  127. \& size_t num_items,
  128. \& size_t stride,
  129. \& const struct timeval *timeout,
  130. \& uint64_t flags,
  131. \& size_t *result_count);
  132. .Ve
  133. .SH DESCRIPTION
  134. .IX Header "DESCRIPTION"
  135. \&\fBSSL_poll()\fR allows the readiness conditions of the resources represented by one
  136. or more BIO_POLL_DESCRIPTOR structures to be determined. In particular, it can
  137. be used to query for readiness conditions on QUIC connection SSL objects and
  138. QUIC stream SSL objects in a single call.
  139. .PP
  140. A call to \fBSSL_poll()\fR specifies an array of \fBSSL_POLL_ITEM\fR structures, each of
  141. which designates a resource which is being polled for readiness, and a set of
  142. event flags which indicate the specific readiness events which the caller is
  143. interested in in relation to the specified resource.
  144. .PP
  145. The fields of \fBSSL_POLL_ITEM\fR are as follows:
  146. .IP \fIdesc\fR 4
  147. .IX Item "desc"
  148. The resource being polled for readiness, as represented by a
  149. \&\fBBIO_POLL_DESCRIPTOR\fR. Currently, this must be a poll descriptor of type
  150. \&\fBBIO_POLL_DESCRIPTOR_TYPE_SSL\fR, representing a SSL object pointer, and the SSL
  151. object must be a QUIC connection SSL object or QUIC stream SSL object.
  152. .Sp
  153. If a \fBSSL_POLL_ITEM\fR has a poll descriptor type of
  154. \&\fBBIO_POLL_DESCRIPTOR_TYPE_NONE\fR, or the SSL object pointer is NULL, the
  155. \&\fBSSL_POLL_ITEM\fR array entry is ignored and \fIrevents\fR will be set to 0 on
  156. return.
  157. .IP \fIevents\fR 4
  158. .IX Item "events"
  159. This is the set of zero or more events which the caller is interested in
  160. learning about in relation to the resource described by \fIdesc\fR. It is a
  161. collection of zero or more \fBSSL_POLL_EVENT\fR flags. See "EVENT TYPES" for a
  162. description of each of the event types.
  163. .IP \fIrevents\fR 4
  164. .IX Item "revents"
  165. After \fBSSL_poll()\fR returns, this is the set of zero or more events which are
  166. actually applicable to the resource described by \fIdesc\fR. As for \fIevents\fR,
  167. it is a collection of zero or more \fBSSL_POLL_EVENT\fR flags.
  168. .Sp
  169. \&\fIrevents\fR need not be a subset of the events specified in \fIevents\fR, as some
  170. event types are defined as always being enabled (non-maskable). See "EVENT
  171. TYPES" for more information.
  172. .PP
  173. To use \fBSSL_poll()\fR, call it with an array of \fBSSL_POLL_ITEM\fR structures. The
  174. array need remain allocated only for the duration of the call. \fInum_items\fR must
  175. be set to the number of entries in the array, and \fIstride\fR must be set to
  176. \&\f(CWsizeof(SSL_POLL_ITEM)\fR.
  177. .PP
  178. The present implementation of \fBSSL_poll()\fR is a subset of the functionality which
  179. will eventually be available. Only a nonblocking mode of operation is available
  180. at this time, where \fBSSL_poll()\fR always returns immediately. As such, \fItimeout\fR
  181. must point to a valid \fBstruct timeval\fR and that structure must be set to zero.
  182. In future, other inputs to the \fItimeout\fR argument will result in a blocking
  183. mode of operation, which is not currently supported. For more information, see
  184. "LIMITATIONS".
  185. .PP
  186. The following flags are currently defined for the \fIflags\fR argument:
  187. .IP \fBSSL_POLL_FLAG_NO_HANDLE_EVENTS\fR 4
  188. .IX Item "SSL_POLL_FLAG_NO_HANDLE_EVENTS"
  189. This flag indicates that internal state machine processing should not be
  190. performed in an attempt to generate new readiness events. Only existing
  191. readiness events will be reported.
  192. .PP
  193. The \fIresult_count\fR argument is optional. If it is non-NULL, it is used to
  194. output the number of entries in the array which have nonzero \fIrevents\fR fields
  195. when the call to \fBSSL_poll()\fR returns; see "RETURN VALUES" for details.
  196. .SH "EVENT TYPES"
  197. .IX Header "EVENT TYPES"
  198. The \fBSSL_poll()\fR interface reports zero or more event types on a given resource,
  199. represented by a bit mask.
  200. .PP
  201. All of the event types are level triggered and represent a readiness or
  202. permanent exception condition; as such, after an event has been reported by
  203. \&\fBSSL_poll()\fR for a resource, it will continue to be reported in future \fBSSL_poll()\fR
  204. calls until the condition ceases to be in effect. A caller must mask the given
  205. event type bit in future \fBSSL_poll()\fR calls if it does not wish to receive
  206. repeated notifications and has not caused the underlying readiness condition
  207. (for example, consuming all available data using \fBSSL_read_ex\fR\|(3) after
  208. \&\fBSSL_POLL_EVENT_R\fR is reported) to be deasserted.
  209. .PP
  210. Some event types do not make sense on a given kind of resource. In this case,
  211. specifying that event type in \fIevents\fR is a no-op and will be ignored, and the
  212. given event will never be reported in \fIrevents\fR.
  213. .PP
  214. Failure of the polling mechanism itself is considered distinct from an exception
  215. condition on a resource which was successfully polled. See \fBSSL_POLL_EVENT_F\fR
  216. and "RETURN VALUES" for details.
  217. .PP
  218. In general, an application should always listen for the event types
  219. corresponding to exception conditions if it is listening to the corresponding
  220. non-exception event types (e.g. \fBSSL_POLL_EVENT_EC\fR and \fBSSL_POLL_EVENT_ER\fR
  221. for \fBSSL_POLL_EVENT_R\fR), as not doing so is unlikely to be a sound design.
  222. .PP
  223. Some event types are non-maskable and may be reported in \fIrevents\fR regardless
  224. of whether they were requested in \fIevents\fR.
  225. .PP
  226. The following event types are supported:
  227. .IP \fBSSL_POLL_EVENT_F\fR 4
  228. .IX Item "SSL_POLL_EVENT_F"
  229. Polling failure. This event is raised when a resource could not be polled. It is
  230. distinct from an exception condition reported on a resource which was
  231. successfully polled and represents a failure of the polling process itself in
  232. relation to a resource. This may mean that \fBSSL_poll()\fR does not support the kind
  233. of resource specified.
  234. .Sp
  235. Where this event is raised on at least one item in \fIitems\fR, \fBSSL_poll()\fR will
  236. return 0 and the ERR stack will contain information pertaining to the first item
  237. in \fIitems\fR with \fBSSL_POLL_EVENT_F\fR set. See "RETURN VALUES" for more
  238. information.
  239. .Sp
  240. This event type may be raised even if it was not requested in \fIevents\fR;
  241. specifying this event type in \fIevents\fR does nothing.
  242. .IP \fBSSL_POLL_EVENT_EC\fR 4
  243. .IX Item "SSL_POLL_EVENT_EC"
  244. Error at connection level. This event is raised when a connection has failed.
  245. In particular, it is raised when a connection begins terminating.
  246. .Sp
  247. This event is never raised on objects which are not connections.
  248. .IP \fBSSL_POLL_EVENT_DCD\fR 4
  249. .IX Item "SSL_POLL_EVENT_DCD"
  250. Error at connection level (drained). This event is raised when a connection has
  251. finished terminating, and has reached the terminated state. This event will
  252. generally occur after an interval of time passes after the \fBSSL_POLL_EVENT_EC\fR
  253. event is raised on a connection.
  254. .Sp
  255. This event is never raised on objects which are not connections.
  256. .IP \fBSSL_POLL_EVENT_ER\fR 4
  257. .IX Item "SSL_POLL_EVENT_ER"
  258. Error in read direction. For QUIC, this is raised only in the event that a
  259. stream has a read part and that read part has been reset by the peer (for
  260. example, using a \fBRESET_STREAM\fR frame).
  261. .IP \fBSSL_POLL_EVENT_EW\fR 4
  262. .IX Item "SSL_POLL_EVENT_EW"
  263. Error in write direction. For QUIC, this is raised only in the event that a
  264. stream has a write part and that write part has been reset by the peer using a
  265. \&\fBSTOP_SENDING\fR frame.
  266. .IP \fBSSL_POLL_EVENT_R\fR 4
  267. .IX Item "SSL_POLL_EVENT_R"
  268. Readable. This event is raised when a QUIC stream SSL object (or a QUIC
  269. connection SSL object with a default stream attached) has application data
  270. waiting to be read using \fBSSL_read_ex\fR\|(3), or a FIN event as represented by
  271. \&\fBSSL_ERROR_ZERO_RETURN\fR waiting to be read.
  272. .Sp
  273. It is not raised in the event of the receiving part of the QUIC stream being
  274. reset by the peer; see \fBSSL_POLL_EVENT_ER\fR.
  275. .IP \fBSSL_POLL_EVENT_W\fR 4
  276. .IX Item "SSL_POLL_EVENT_W"
  277. Writable. This event is raised when a QUIC stream SSL object (or a QUIC
  278. connection SSL object with a default stream attached) could accept more
  279. application data using \fBSSL_write_ex\fR\|(3).
  280. .Sp
  281. This event is never raised by a receive-only stream.
  282. .Sp
  283. This event is never raised by a stream which has had its send part concluded
  284. normally (as with \fBSSL_stream_conclude\fR\|(3)) or locally reset (as with
  285. \&\fBSSL_stream_reset\fR\|(3)).
  286. .Sp
  287. This event does not guarantee that a subsequent call to \fBSSL_write_ex\fR\|(3) will
  288. succeed.
  289. .IP \fBSSL_POLL_EVENT_ISB\fR 4
  290. .IX Item "SSL_POLL_EVENT_ISB"
  291. This event, which is only raised by a QUIC connection SSL object, is raised when
  292. one or more incoming bidirectional streams are available to be accepted using
  293. \&\fBSSL_accept_stream\fR\|(3).
  294. .IP \fBSSL_POLL_EVENT_ISU\fR 4
  295. .IX Item "SSL_POLL_EVENT_ISU"
  296. This event, which is only raised by a QUIC connection SSL object, is raised when
  297. one or more incoming unidirectional streams are available to be accepted using
  298. \&\fBSSL_accept_stream\fR\|(3).
  299. .IP \fBSSL_POLL_EVENT_OSB\fR 4
  300. .IX Item "SSL_POLL_EVENT_OSB"
  301. This event, which is only raised by a QUIC connection SSL object, is raised when
  302. QUIC stream creation flow control currently permits at least one additional
  303. bidirectional stream to be locally created.
  304. .IP \fBSSL_POLL_EVENT_OSU\fR 4
  305. .IX Item "SSL_POLL_EVENT_OSU"
  306. This event, which is only raised by a QUIC connection SSL object, is raised when
  307. QUIC stream creation flow control currently permits at least one additional
  308. unidirectional stream to be locally created.
  309. .SH LIMITATIONS
  310. .IX Header "LIMITATIONS"
  311. \&\fBSSL_poll()\fR as presently implemented has the following limitations:
  312. .IP \(bu 4
  313. The implementation of \fBSSL_poll()\fR only supports nonblocking operation and
  314. therefore requires the \fItimeout\fR argument be used to specify a zero timeout.
  315. Calls to \fBSSL_poll()\fR which specify another value, or which pass \fItimeout\fR as
  316. NULL, will fail. This does not allow waiting, but does allow multiple QUIC SSL
  317. objects to be queried for their readiness state in a single call.
  318. .Sp
  319. Future releases will remove this limitation and support blocking \fBSSL_poll()\fR.
  320. .IP \(bu 4
  321. Only \fBBIO_POLL_DESCRIPTOR\fR structures with type
  322. \&\fBBIO_POLL_DESCRIPTOR_TYPE_SSL\fR, referencing QUIC connection SSL objects or QUIC
  323. stream SSL objects, are supported.
  324. .PP
  325. These limitations will be revised in a future release of OpenSSL.
  326. .SH "RETURN VALUES"
  327. .IX Header "RETURN VALUES"
  328. \&\fBSSL_poll()\fR returns 1 on success and 0 on failure.
  329. .PP
  330. Unless the \fIitems\fR pointer itself is invalid, \fBSSL_poll()\fR will always initialise
  331. the \fIrevents\fR fields of all items in the input array upon returning, even if it
  332. returns failure.
  333. .PP
  334. If \fIresult_count\fR is non-NULL, it is always written with the number of items in
  335. the array with nonzero \fIrevents\fR fields, even if the \fBSSL_poll()\fR call returns
  336. failure.
  337. .PP
  338. It is possible for \fIresult_count\fR to be written as 0 even if the \fBSSL_poll()\fR
  339. call returns success, namely if no events were output but the polling process
  340. was successful (e.g. in nonblocking usage) or timed out.
  341. .PP
  342. It is possible for \fIresult_count\fR to be written as a nonzero value if the
  343. \&\fBSSL_poll()\fR call returns failure, for example due to \fBSSL_POLL_EVENT_F\fR events,
  344. or because some events were detected and output before encountering a failure
  345. condition while processing a subsequent entry in the \fIitems\fR array.
  346. .PP
  347. If at least one \fBSSL_POLL_EVENT_F\fR event is output, \fBSSL_poll()\fR is guaranteed
  348. to return 0 and guaranteed to place at least one ERR on the error stack
  349. describing the first \fBSSL_POLL_EVENT_F\fR output. Detailed information on any
  350. additional \fBSSL_POLL_EVENT_F\fR events is not available. \fBSSL_poll()\fR may or may
  351. not return more than one \fBSSL_POLL_EVENT_F\fR event at once.
  352. .PP
  353. "Normal" events representing exceptional I/O conditions which do not
  354. constitute a failure of the \fBSSL_poll()\fR mechanism itself are not considered
  355. errors by \fBSSL_poll()\fR and are instead represented using their own event type; see
  356. "EVENT TYPES" for details.
  357. .PP
  358. The caller can establish the meaning of the \fBSSL_poll()\fR return and output values
  359. as follows:
  360. .IP \(bu 4
  361. If \fBSSL_poll()\fR returns 1 and \fIresult_count\fR is zero, the operation timed out
  362. before any resource was ready.
  363. .IP \(bu 4
  364. If \fBSSL_poll()\fR returns 1 and \fIresult_count\fR is nonzero, that many events were
  365. output.
  366. .IP \(bu 4
  367. If \fBSSL_poll()\fR returns 0 and \fIresult_count\fR is zero, the caller has made a basic
  368. usage error; check the ERR stack for details.
  369. .IP \(bu 4
  370. If \fBSSL_poll()\fR returns 0 and \fIresult_count\fR is nonzero, inspect the \fIitems\fR
  371. array for \fBSSL_POLL_ITEM\fR structures with the \fBSSL_POLL_EVENT_F\fR event type
  372. raised in \fIrevents\fR. The entries added to the ERR stack (of which there is
  373. guaranteed to be at least one) reflect the cause of the failure of the first
  374. item in \fIitems\fR with \fBSSL_POLL_EVENT_F\fR raised. Note that there may be events
  375. other than \fISSL_POLL_EVENT_F\fR output for items which come before the first
  376. item with \fBSSL_POLL_EVENT_F\fR raised, and additional \fBSSL_POLL_EVENT_F\fR
  377. events may or may not have been output, both of which which will be reflected in
  378. \&\fIresult_count\fR.
  379. .SH "SEE ALSO"
  380. .IX Header "SEE ALSO"
  381. \&\fBBIO_get_rpoll_descriptor\fR\|(3), \fBBIO_get_wpoll_descriptor\fR\|(3),
  382. \&\fBSSL_get_rpoll_descriptor\fR\|(3), \fBSSL_get_wpoll_descriptor\fR\|(3)
  383. .SH HISTORY
  384. .IX Header "HISTORY"
  385. \&\fBSSL_poll()\fR was added in OpenSSL 3.3.
  386. .SH COPYRIGHT
  387. .IX Header "COPYRIGHT"
  388. Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
  389. .PP
  390. Licensed under the Apache License 2.0 (the "License"). You may not use
  391. this file except in compliance with the License. You can obtain a copy
  392. in the file LICENSE in the source distribution or at
  393. <https://www.openssl.org/source/license.html>.