BIO_SOCKET_WAIT(3ossl)

πŸ’– BIO_SOCKET_WAIT(3ossl) πŸ’–

okay bestie, pull up a chair, we're talking about the BIO_socket_wait, BIO_wait, and BIO_do_connect_retry girlies β€” the BIO connection utility functions from OpenSSL. they're literally the ones who handle the "hey are we connected yet??" energy so you don't have to. πŸ¦‹


✨ NAME ✨

BIO_socket_wait, BIO_wait, BIO_do_connect_retry β€” BIO connection utility functions, no cap. they wait, they retry, they slay. πŸ’…


🌸 SYNOPSIS 🌸

#include <openssl/bio.h>

#ifndef OPENSSL_NO_SOCK
int BIO_socket_wait(int fd, int for_read, time_t max_time);
#endif
int BIO_wait(BIO *bio, time_t max_time, unsigned int nap_milliseconds);
int BIO_do_connect_retry(BIO *bio, int timeout, int nap_milliseconds);
note that BIO_socket_wait() only exists if OPENSSL_NO_SOCK is not defined, iykyk. the other two are always there for you. 🫢

πŸŽ€ DESCRIPTION πŸŽ€

so basically, three functions, three vibes, all working together. let's get into it.

BIO_socket_wait() sits and waits on the socket fd β€” for reading if for_read is not 0, otherwise for writing β€” and it waits at most until max_time. it succeeds immediately if max_time == 0, which is the "no timeout given" case. so like, zero patience required. ✨

BIO_wait() waits at most until max_time on the given bio (typically socket-based, bestie), for reading if the bio is supposed to read, otherwise for writing. it's the one BIO_do_connect_retry() uses under the hood, and you can also pair it up with BIO_read(3). same deal as before: it succeeds immediately if max_time == 0 (no timeout given). and if sockets aren't available, it supports polling by succeeding after sleeping at most the given nap_milliseconds, specifically so you don't end up in a tight busy loop (that's giving ✨chaos✨, we don't do that here). via nap_milliseconds the caller decides the polling granularity. your nap, your rules. 😴

BIO_do_connect_retry() connects via the given bio. it retries BIO_do_connect() as far as needed to reach a definite outcome, i.e. one of these three: connection succeeded, timeout has been reached, or an error occurred. periodt. for nonblocking and potentially even non-socket BIOs it polls every nap_milliseconds and sleeps in between using BIO_wait(). if nap_milliseconds is < 0 then a default value of 100 ms is used. if the timeout parameter is > 0, that indicates the maximum number of seconds to wait until the connection is established or a definite error occurred. a value of 0 enables waiting indefinitely (i.e, no timeout), while a value < 0 means that BIO_do_connect() is tried only once. one time only, no retries, main character exits the chat. also heads up: the function may, directly or indirectly, invoke ERR_clear_error(). so don't be shocked when the error queue gets cleared out from under you. πŸ’€


πŸ”₯ RETURN VALUES πŸ”₯

the trio β€” BIO_socket_wait(), BIO_wait(), and BIO_do_connect_retry() β€” all return the same way:

  • -1 on error πŸ™ˆ
  • 0 on timeout ⏰
  • 1 on success πŸ‘‘

so yeah, three possible moods. check them accordingly.


πŸ¦‹ SEE ALSO πŸ¦‹

go read those too, bestie, they're in the group chat. πŸ’œ


⭐ HISTORY ⭐

BIO_socket_wait(), BIO_wait(), and BIO_do_connect_retry() were added in OpenSSL 3.0. so they're not ancient, they're just iconic. 🌈


Copyright 2019-2020 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 the whole page, babe β€” this was OpenSSL 3.5.9, dated 2026-09-29, from the BIO_SOCKET_WAIT(3ossl) manual. go forth and wait responsibly. πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from