BIO_SOCKET_WAIT(3ssl)
π BIO_SOCKET_WAIT(3ssl) β like, the OpenSSL manual page, but make it make sense π«Ά
okay so bestie, this is a page from the OpenSSL manual set β the 3ssl section, which is where all the library-function lore lives. buckle up, we're talking about socket waiting and connection retries and honestly it's giving "quietly load-bearing utility functions" β¨
πΈ NAME πΈ
BIO_socket_wait, BIO_socket_ready, BIO_wait, BIO_do_connect_retry β these are the BIO connection utility functions. tiny little helpers, but they do a LOT of the emotional labor of getting a connection up π
β¨ SYNOPSIS β¨
#include <openssl/bio.h>
#ifndef OPENSSL_NO_SOCK
int BIO_socket_wait(int fd, int for_read, time_t max_time);
int BIO_socket_ready(int fd, int for_read);
#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 the #ifndef OPENSSL_NO_SOCK guard around the first two β if sockets aren't compiled in, those two just don't exist for you, sorry not sorry π the other two are always around π§
π¦ DESCRIPTION π¦
BIO_socket_wait β³
BIO_socket_wait() waits on the socket fd β like, it literally sits there and chills. if for_read is not 0 it's waiting for reading, otherwise it's waiting for writing, and it waits at most until max_time.
big mood: if max_time == 0 (which means no timeout given) it succeeds immediately. no waiting, no drama, instant slay π
π« BIO_socket_ready
BIO_socket_ready() is the non-blocking icon. it checks whether the socket fd is ready for reading (if for_read is not 0) or else for writing β without blocking. it does not wait, it just peeks.
this one is genuinely useful for polling a socket to figure out if an I/O operation can be performed immediately without waiting. vibe check on the socket, basically π
π BIO_wait
BIO_wait() waits at most until max_time on the given bio (typically socket-based) β for reading if bio is supposed to read, else for writing.
- it's used by
BIO_do_connect_retry(), and - you can use it together with
BIO_read(3)π«Ά
again: it succeeds immediately if max_time == 0 (which means no timeout given).
and here's the cute part β if sockets are not available, it supports polling by succeeding after sleeping at most the given nap_milliseconds, specifically so you don't get a tight busy loop π via nap_milliseconds the caller decides the polling granularity. you're the boss of how often it wakes up π
π§ BIO_do_connect_retry
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:
- connection succeeded π
- timeout has been reached β
- an error occurred π
for nonblocking and potentially even non-socket BIOs it polls every nap_milliseconds and sleeps in between using BIO_wait() π΄
the numbers, exactly:
- if
nap_millisecondsis< 0then a default value of100ms is used - if the
timeoutparameter is> 0this indicates the maximum number of seconds to wait until the connection is established or a definite error occurred - a value of
0enables waiting indefinitely (i.e, no timeout) - a value
< 0means thatBIO_do_connect()is tried only once
β οΈ heads up bestie: the function may, directly or indirectly, invoke ERR_clear_error(). so if you were emotionally attached to whatever was sitting in the error queue, it might get swept out from under you π
π RETURN VALUES π
BIO_socket_wait(), BIO_socket_ready(), BIO_wait(), and BIO_do_connect_retry() all return:
-1on error π0on timeout (or not ready, in the case ofBIO_socket_ready())1on success (or ready, in the case ofBIO_socket_ready()) β
so it's a cute little -1 / 0 / 1 trio. iykyk π
π SEE ALSO π
go read those too, they're the main characters of this friend group π
π°οΈ HISTORY π°οΈ
BIO_socket_wait(),BIO_wait(), andBIO_do_connect_retry()were added in OpenSSL 3.0 β¨BIO_socket_ready()was added in OpenSSL 4.1 β a newer addition, freshly iconic π
π COPYRIGHT π
Copyright 2019-2026 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>.
okay that's the whole page, no cap π this was OpenSSL 4.1.0, dated 2026-10-23 β so if you're reading this from the future, hi, hope your sockets were ready πβ¨π
π¦ where this page comes from
- nixos 26.05: openssl 4.1.0
- nixpkgs unstable: openssl 4.1.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms