SSL_POLL(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

SSL_POLL(3ossl) β€” bestie, welcome to the OpenSSL page for polling readiness. It’s giving very β€œI know what your sockets are doing” energy. πŸ’…βœ¨

πŸŽ€ NAME πŸŽ€

Okay so the entire squad on this page is SSL_poll, SSL_POLL_EVENT_NONE, SSL_POLL_EVENT_F, SSL_POLL_EVENT_EC, SSL_POLL_EVENT_ECD, SSL_POLL_EVENT_ER, SSL_POLL_EVENT_EW, SSL_POLL_EVENT_R, SSL_POLL_EVENT_W, SSL_POLL_EVENT_ISB, SSL_POLL_EVENT_ISU, SSL_POLL_EVENT_OSB, SSL_POLL_EVENT_OSU, SSL_POLL_EVENT_RW, SSL_POLL_EVENT_RE, SSL_POLL_EVENT_WE, SSL_POLL_EVENT_RWE, SSL_POLL_EVENT_E, SSL_POLL_EVENT_IS, SSL_POLL_EVENT_ISE, SSL_POLL_EVENT_I, SSL_POLL_EVENT_OS, SSL_POLL_EVENT_OSE, and SSL_POLL_FLAG_NO_HANDLE_EVENTS β€” all here to determine or await readiness conditions for one or more pollable objects. Periodt. πŸ’–

✨ SYNOPSIS ✨

This is the exact sauce, bestie β€” keep it character-for-character:

        #include <openssl/ssl.h>

        #define SSL_POLL_EVENT_NONE        0

        #define SSL_POLL_EVENT_F           /* F   (Failure) */
        #define SSL_POLL_EVENT_EC          /* EC  (Exception on Conn) */
        #define SSL_POLL_EVENT_ECD         /* ECD (Exception on Conn Drained) */
        #define SSL_POLL_EVENT_ER          /* ER  (Exception on Read) */
        #define SSL_POLL_EVENT_EW          /* EW  (Exception on Write) */
        #define SSL_POLL_EVENT_R           /* R   (Readable) */
        #define SSL_POLL_EVENT_W           /* W   (Writable) */
        #define SSL_POLL_EVENT_ISB         /* ISB (Incoming Stream: Bidi) */
        #define SSL_POLL_EVENT_ISU         /* ISU (Incoming Stream: Uni) */
        #define SSL_POLL_EVENT_OSB         /* OSB (Outgoing Stream: Bidi) */
        #define SSL_POLL_EVENT_OSU         /* OSU (Outgoing Stream: Uni) */

        #define SSL_POLL_EVENT_RW          /* R   | W         */
        #define SSL_POLL_EVENT_RE          /* R   | ER        */
        #define SSL_POLL_EVENT_WE          /* W   | EW        */
        #define SSL_POLL_EVENT_RWE         /* RE  | WE        */
        #define SSL_POLL_EVENT_E           /* EC  | ER  | EW  */
        #define SSL_POLL_EVENT_IS          /* ISB | ISU       */
        #define SSL_POLL_EVENT_ISE         /* IS  | EC        */
        #define SSL_POLL_EVENT_I           /* IS              */
        #define SSL_POLL_EVENT_OS          /* OSB | OSU       */
        #define SSL_POLL_EVENT_OSE         /* OS  | EC        */

        typedef struct ssl_poll_item_st {
            BIO_POLL_DESCRIPTOR desc;
            uint64_t            events, revents;
        } SSL_POLL_ITEM;

        #define SSL_POLL_FLAG_NO_HANDLE_EVENTS

        int SSL_poll(SSL_POLL_ITEM         *items,
                     size_t                num_items,
                     size_t                stride,
                     const struct timeval  *timeout,
                     uint64_t              flags,
                     size_t                *result_count);

πŸ’– DESCRIPTION πŸ’–

SSL_poll() lets you figure out the readiness conditions of the resources represented by one or more BIO_POLL_DESCRIPTOR structures. In particular, it can be used to query for readiness conditions on QUIC connection SSL objects and QUIC stream SSL objects in a single call. It can also be used to block until at least one of the given resources is ready. Iconic behavior, honestly. πŸ¦‹

A call to SSL_poll() specifies an array of SSL_POLL_ITEM structures, each of which designates a resource that’s being polled for readiness, plus a set of event flags that say which specific readiness events the caller is interested in for that specified resource.

The fields of SSL_POLL_ITEM are as follows:

  • desc β€” the resource being polled for readiness, as represented by a BIO_POLL_DESCRIPTOR. Currently, this must be a poll descriptor of type BIO_POLL_DESCRIPTOR_TYPE_SSL, representing an SSL object pointer, and the SSL object must be a QUIC connection SSL object or QUIC stream SSL object.

If an SSL_POLL_ITEM has a poll descriptor type of BIO_POLL_DESCRIPTOR_TYPE_NONE, or the SSL object pointer is NULL, that SSL_POLL_ITEM array entry is ignored and revents will be set to 0 on return.

  • events β€” this is the set of zero or more events the caller is interested in learning about in relation to the resource described by desc. It is a collection of zero or more SSL_POLL_EVENT flags. See "EVENT TYPES" for a description of each of the event types.
  • revents β€” after SSL_poll() returns, this is the set of zero or more events that are actually applicable to the resource described by desc. As for events, it is a collection of zero or more SSL_POLL_EVENT flags.

revents need not be a subset of the events specified in events, because some event types are defined as always being enabled β€” non-maskable, bestie. See "EVENT TYPES" for more information.

To use SSL_poll(), call it with an array of SSL_POLL_ITEM structures. The array needs to remain allocated only for the duration of the call. num_items must be set to the number of entries in the array, and stride must be set to sizeof(SSL_POLL_ITEM).

The timeout argument specifies the timeout to use, and, implicitly, whether to use SSL_poll() in blocking or nonblocking mode:

  • If timeout is NULL, the function blocks indefinitely until at least one resource is ready. 😴
  • If timeout is non-NULL, and it points to a struct timeval which is set to zero, the function operates in nonblocking mode and returns immediately with readiness information. ⚑
  • If timeout is non-NULL, and it points to a struct timeval which is set to a value other than zero, the function blocks for the specified interval or until at least one of the specified resources is ready, whichever comes first. ⏳

The present implementation of SSL_poll() is a subset of the functionality which will eventually be available. For more information, see "LIMITATIONS".

The following flags are currently defined for the flags argument:

  • SSL_POLL_FLAG_NO_HANDLE_EVENTS β€” this flag indicates that internal state machine processing should not be performed in an attempt to generate new readiness events. Only existing readiness events will be reported.

If this flag is used in nonblocking mode (with a timeout of zero), no internal state machine processing is performed.

If this flag is used in blocking mode (for example, with timeout set to NULL), event processing does not occur unless the function blocks.

The result_count argument is optional. If it is non-NULL, it is used to output the number of entries in the array which have nonzero revents fields when the call to SSL_poll() returns; see "RETURN VALUES" for details. 🌸

✨ EVENT TYPES ✨

Okay so SSL_poll() reports zero or more event types on a given resource, and it packs them into a bit mask. Cute, right? πŸ’…

Here's the vibe: all of these event types are level triggered. They mean "this thing is ready" or "this thing is permanently broken." So once SSL_poll() reports an event for a resource, it's gonna keep reporting it in future SSL_poll() calls until the condition actually stops being a thing. Which means πŸ‘ you πŸ‘ gotta πŸ‘ mask πŸ‘ the bit. If you don't wanna get the same notification over and over, mask that event type out in future SSL_poll() calls β€” unless you've actually caused the underlying readiness condition to be deasserted (like, consuming all the available data with SSL_read_ex(3) after SSL_POLL_EVENT_R got reported). Otherwise it's just gonna keep yelling at you, bestie.

Some event types genuinely do not make sense on a given kind of resource. In that case, specifying that event type in events is a total no-op β€” it gets ignored, and the given event will never show up in revents. Not a bug, just not applicable. πŸ™ˆ

Failure of the polling mechanism itself is a whole different thing from an exception condition on a resource that got successfully polled. See SSL_POLL_EVENT_F and "RETURN VALUES" for the deets.

Real talk: generally you should always listen for the event types that correspond to exception conditions if you're listening to the corresponding non-exception event types (like SSL_POLL_EVENT_EC and SSL_POLL_EVENT_ER for SSL_POLL_EVENT_R). Not doing that is, um, unlikely to be a sound design. 😭 Please don't do that to yourself.

Some event types are non-maskable and may be reported in revents regardless of whether you even requested them in events. Sneaky but iconic.

The following event types are supported:

  • SSL_POLL_EVENT_F β€” Polling failure. Raised when a resource could not be polled. It is distinct from an exception condition reported on a resource that was successfully polled, and it represents a failure of the polling process itself in relation to a resource. This may mean that SSL_poll() does not support the kind of resource you specified. 🫠 Where this event is raised on at least one item in items, SSL_poll() will return 0 and the ERR stack will contain info pertaining to the first item in items with SSL_POLL_EVENT_F set. See "RETURN VALUES" for more. This event type may be raised even if it was not requested in events; specifying this event type in events does nothing.
  • SSL_POLL_EVENT_EL β€” Error at listener level. Raised when a listener has failed β€” for example, if a network BIO has encountered a permanent error. This event is never raised on objects which are not listeners, but its occurrence will cause SSL_POLL_EVENT_EC to be raised on all dependent connections.
  • SSL_POLL_EVENT_EC β€” Error at connection level. Raised when a connection has failed. In particular, it's raised when a connection begins terminating. This event is never raised on objects which are not connections.
  • SSL_POLL_EVENT_ECD β€” Error at connection level (drained). Raised when a connection has finished terminating and has reached the terminated state. This one generally occurs after an interval of time passes after the SSL_POLL_EVENT_EC event is raised on a connection. This event is never raised on objects which are not connections.
  • SSL_POLL_EVENT_ER β€” Error in read direction. For QUIC, this is raised only in the event that a stream has a read part and that read part has been reset by the peer (for example, using a RESET_STREAM frame).
  • SSL_POLL_EVENT_EW β€” Error in write direction. For QUIC, this is raised only in the event that a stream has a write part and that write part has been reset by the peer using a STOP_SENDING frame.
  • SSL_POLL_EVENT_R β€” Readable. Raised when a QUIC stream SSL object (or a QUIC connection SSL object with a default stream attached) has application data waiting to be read using SSL_read_ex(3), or a FIN event as represented by SSL_ERROR_ZERO_RETURN waiting to be read. It is not raised in the event of the receiving part of the QUIC stream being reset by the peer β€” see SSL_POLL_EVENT_ER.
  • SSL_POLL_EVENT_W β€” Writable. Raised when a QUIC stream SSL object (or a QUIC connection SSL object with a default stream attached) could accept more application data using SSL_write_ex(3). This event is never raised by a receive-only stream. This event is never raised by a stream which has had its send part concluded normally (as with SSL_stream_conclude(3)) or locally reset (as with SSL_stream_reset(3)).
Heads up: this event does not guarantee that a subsequent call to SSL_write_ex(3) will succeed. Rude, I know. πŸ’€
  • SSL_POLL_EVENT_IC β€” This event, which is only raised by a QUIC listener SSL object, is raised when one or more incoming QUIC connections are available to be accepted using SSL_accept_connection(3).
  • SSL_POLL_EVENT_ISB β€” This event, which is only raised by a QUIC connection SSL object, is raised when one or more incoming bidirectional streams are available to be accepted using SSL_accept_stream(3).
  • SSL_POLL_EVENT_ISU β€” This event, which is only raised by a QUIC connection SSL object, is raised when one or more incoming unidirectional streams are available to be accepted using SSL_accept_stream(3).
  • SSL_POLL_EVENT_OSB β€” This event, which is only raised by a QUIC connection SSL object, is raised when QUIC stream creation flow control currently permits at least one additional bidirectional stream to be locally created.
  • SSL_POLL_EVENT_OSU β€” This event, which is only raised by a QUIC connection SSL object, is raised when QUIC stream creation flow control currently permits at least one additional unidirectional stream to be locally created.

🌈 LIMITATIONS 🌈

SSL_poll() as presently implemented has the following limitation:

  • Only BIO_POLL_DESCRIPTOR structures with type BIO_POLL_DESCRIPTOR_TYPE_SSL, referencing QUIC listener, connection or stream SSL objects, are supported.

This limitation may be revised in a future release of OpenSSL. Manifesting it for you besties πŸ•―οΈβœ¨


πŸ’– RETURN VALUES πŸ’–

SSL_poll() returns 1 on success and 0 on failure.

Unless the items pointer itself is invalid, SSL_poll() will always initialise the revents fields of all items in the input array upon returning β€” even if it returns failure. So you always get something to look at. πŸŽ€

If result_count is non-NULL, it is always written with the number of items in the array with nonzero revents fields, even if the SSL_poll() call returns failure.

It is possible for result_count to be written as 0 even if the SSL_poll() call returns success β€” namely if no events were output but the polling process was successful (e.g. in nonblocking usage) or timed out.

It is also possible for result_count to be written as a nonzero value if the SSL_poll() call returns failure β€” for example due to SSL_POLL_EVENT_F events, or because some events were detected and output before hitting a failure condition while processing a subsequent entry in the items array.

If at least one SSL_POLL_EVENT_F event is output, SSL_poll() is guaranteed to return 0 and guaranteed to place at least one ERR on the error stack describing the first SSL_POLL_EVENT_F output. Detailed information on any additional SSL_POLL_EVENT_F events is not available. SSL_poll() may or may not return more than one SSL_POLL_EVENT_F event at once. πŸ€·β€β™€οΈ

"Normal" events representing exceptional I/O conditions which do not constitute a failure of the SSL_poll() mechanism itself are not considered errors by SSL_poll() β€” they're represented using their own event type instead. See "EVENT TYPES" for details.

The caller can establish the meaning of the SSL_poll() return and output values as follows:

  • If SSL_poll() returns 1 and result_count is zero, the operation timed out before any resource was ready.
  • If SSL_poll() returns 1 and result_count is nonzero, that many events were output.
  • If SSL_poll() returns 0 and result_count is zero, the caller has made a basic usage error; check the ERR stack for details.
  • If SSL_poll() returns 0 and result_count is nonzero, inspect the items array for SSL_POLL_ITEM structures with the SSL_POLL_EVENT_F event type raised in revents. The entries added to the ERR stack (of which there is guaranteed to be at least one) reflect the cause of the failure of the first item in items with SSL_POLL_EVENT_F raised. Note that there may be events other than SSL_POLL_EVENT_F output for items which come before the first item with SSL_POLL_EVENT_F raised, and additional SSL_POLL_EVENT_F events may or may not have been output β€” both of which will be reflected in result_count.

πŸ¦‹ SEE ALSO πŸ¦‹

BIO_get_rpoll_descriptor(3), BIO_get_wpoll_descriptor(3), SSL_get_rpoll_descriptor(3), SSL_get_wpoll_descriptor(3)


🌸 HISTORY 🌸

SSL_poll() was added in OpenSSL 3.3.

Before 3.5, SSL_poll() did not support blocking operation and would fail if called with a NULL timeout parameter or a timeout parameter pointing to a struct timeval which was not zero.

Before 3.5, the SSL_POLL_EVENT_EL and SSL_POLL_EVENT_IC event types were not present. Glow-up era fr fr πŸ’…


Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


And that's a wrap on the whole page, bestie β€” this one walked so your QUIC code could run. 🌟 It's 3.5.0, dated 2026-09-25, and it lives at SSL_POLL(3ossl) in the man pages, so go forth and poll responsibly. 🫢✨

πŸ“¦ where this page comes from