Path: blob/main/crypto/openssl/ssl/rio/poll_builder.h
48266 views
/*1* Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/8#ifndef OSSL_POLL_BUILDER_H9# define OSSL_POLL_BUILDER_H1011# include "poll_method.h"12# include "internal/time.h"1314/*15* RIO_POLL_BUILDER16* ================17*18* RIO_POLL_BUILDER provides support for immediate-mode polling architectures.19* It abstracts OS-specific immediate-mode polling APIs such as select(2) and20* poll(2) and allows an arbitrarily large number of FDs to be polled for while21* providing minimal overhead (over the OS APIs themselves) for small numbers of22* FDs.23*/24typedef struct rio_poll_builder_st {25# if RIO_POLL_METHOD == RIO_POLL_METHOD_NONE26int unused_dummy; /* make microsoft compiler happy */27# elif RIO_POLL_METHOD == RIO_POLL_METHOD_SELECT28fd_set rfd, wfd, efd;29int hwm_fd;30# elif RIO_POLL_METHOD == RIO_POLL_METHOD_POLL31# define RIO_NUM_STACK_PFDS 3232struct pollfd *pfd_heap;33struct pollfd pfds[RIO_NUM_STACK_PFDS];34size_t pfd_num, pfd_alloc;35# else36# error Unknown RIO poll method37# endif38} RIO_POLL_BUILDER;3940/*41* Initialises a new poll builder.42*43* Returns 1 on success and 0 on failure.44*/45int ossl_rio_poll_builder_init(RIO_POLL_BUILDER *rpb);4647/*48* Tears down a poll builder, freeing any heap allocations (if any) which may49* have been made internally.50*/51void ossl_rio_poll_builder_cleanup(RIO_POLL_BUILDER *rpb);5253/*54* Adds a file descriptor to a poll builder. If want_read is 1, listens for55* readability events (POLLIN). If want_write is 1, listens for writability56* events (POLLOUT).57*58* If this is called with the same fd twice, the result equivalent to calling59* it one time with logically OR'd values of want_read and want_write.60*61* Returns 1 on success and 0 on failure.62*/63int ossl_rio_poll_builder_add_fd(RIO_POLL_BUILDER *rpb, int fd,64int want_read, int want_write);6566/*67* Polls the set of file descriptors added to a poll builder. deadline is a68* deadline time based on the ossl_time_now() clock or ossl_time_infinite() for69* no timeout. Returns 1 on success or 0 on failure.70*/71int ossl_rio_poll_builder_poll(RIO_POLL_BUILDER *rpb, OSSL_TIME deadline);7273/*74* TODO(RIO): No support currently for readout of what was readable/writeable as75* it is currently not needed.76*/7778#endif798081