Home | History | Annotate | Line # | Download | only in internal
      1      1.1  christos /*
      2      1.1  christos  * Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.
      3      1.1  christos  *
      4      1.1  christos  * Licensed under the Apache License 2.0 (the "License").  You may not use
      5      1.1  christos  * this file except in compliance with the License.  You can obtain a copy
      6      1.1  christos  * in the file LICENSE in the source distribution or at
      7      1.1  christos  * https://www.openssl.org/source/license.html
      8      1.1  christos  */
      9      1.1  christos #ifndef OSSL_RIO_NOTIFIER_H
     10  1.1.1.2  christos #define OSSL_RIO_NOTIFIER_H
     11      1.1  christos 
     12  1.1.1.2  christos #include "internal/common.h"
     13  1.1.1.2  christos #include "internal/sockets.h"
     14      1.1  christos 
     15      1.1  christos /*
     16      1.1  christos  * Pollable Notifier
     17      1.1  christos  * =================
     18      1.1  christos  *
     19      1.1  christos  * RIO_NOTIFIER provides an OS-pollable resource which can be plugged into an
     20      1.1  christos  * OS's socket polling APIs to allow socket polling calls to be woken
     21      1.1  christos  * artificially by other threads.
     22      1.1  christos  */
     23  1.1.1.2  christos #define RIO_NOTIFIER_METHOD_SOCKET 1
     24  1.1.1.2  christos #define RIO_NOTIFIER_METHOD_SOCKETPAIR 2
     25      1.1  christos 
     26  1.1.1.2  christos #if !defined(RIO_NOTIFIER_METHOD)
     27  1.1.1.2  christos #if defined(OPENSSL_SYS_WINDOWS)
     28  1.1.1.2  christos #define RIO_NOTIFIER_METHOD RIO_NOTIFIER_METHOD_SOCKET
     29  1.1.1.2  christos #elif defined(OPENSSL_SYS_UNIX)
     30  1.1.1.2  christos #define RIO_NOTIFIER_METHOD RIO_NOTIFIER_METHOD_SOCKETPAIR
     31  1.1.1.2  christos #else
     32  1.1.1.2  christos #define RIO_NOTIFIER_METHOD RIO_NOTIFIER_METHOD_SOCKET
     33  1.1.1.2  christos #endif
     34  1.1.1.2  christos #endif
     35      1.1  christos 
     36      1.1  christos typedef struct rio_notifier_st {
     37      1.1  christos     int rfd, wfd;
     38      1.1  christos } RIO_NOTIFIER;
     39      1.1  christos 
     40      1.1  christos /*
     41      1.1  christos  * Initialises a RIO_NOTIFIER. Returns 1 on success or 0 on failure.
     42      1.1  christos  */
     43      1.1  christos int ossl_rio_notifier_init(RIO_NOTIFIER *nfy);
     44      1.1  christos 
     45      1.1  christos /*
     46      1.1  christos  * Cleans up a RIO_NOTIFIER, tearing down any allocated resources.
     47      1.1  christos  */
     48      1.1  christos void ossl_rio_notifier_cleanup(RIO_NOTIFIER *nfy);
     49      1.1  christos 
     50      1.1  christos /*
     51      1.1  christos  * Signals a RIO_NOTIFIER, waking up any waiting threads.
     52      1.1  christos  */
     53      1.1  christos int ossl_rio_notifier_signal(RIO_NOTIFIER *nfy);
     54      1.1  christos 
     55      1.1  christos /*
     56      1.1  christos  * Unsignals a RIO_NOTIFIER.
     57      1.1  christos  */
     58      1.1  christos int ossl_rio_notifier_unsignal(RIO_NOTIFIER *nfy);
     59      1.1  christos 
     60      1.1  christos /*
     61      1.1  christos  * Returns an OS socket handle (FD or Win32 SOCKET) which can be polled for
     62      1.1  christos  * readability to determine when the notifier has been signalled.
     63      1.1  christos  */
     64      1.1  christos static ossl_inline ossl_unused int ossl_rio_notifier_as_fd(RIO_NOTIFIER *nfy)
     65      1.1  christos {
     66      1.1  christos     return nfy->rfd;
     67      1.1  christos }
     68      1.1  christos 
     69      1.1  christos #endif
     70