BIO_SOCKET_WAIT(3SSL)
π BIO_SOCKET_WAIT(3SSL) π
okay bestie so this is a page from the OpenSSL manual, section 3SSL, and we're talking about the BIO connection utility functions: BIO_socket_wait, BIO_wait, and BIO_do_connect_retry. pull up a chair, grab a matcha, we're doing sockets today π
β¨ NAME β¨
BIO_socket_wait, BIO_wait, BIO_do_connect_retry β the BIO connection utility functions, aka the little trio that waits around for your sockets so you don't have to. π
πΈ 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);
see how BIO_socket_wait is wrapped in that #ifndef OPENSSL_NO_SOCK? yeah. if you compiled without sockets, that one literally does not exist. no cap. π
π¦ DESCRIPTION π¦
BIO_socket_wait π
BIO_socket_wait() waits on the socket fd β for reading if for_read is not 0, otherwise for writing β and it waits at most until max_time. and here's the slay detail: it succeeds immediately if max_time == 0, because that means no timeout was given. so 0 is not "wait zero seconds", it's "bestie I'm not putting a clock on this". β
BIO_wait π
BIO_wait() waits at most until max_time on the given bio β typically a socket-based one β for reading if the bio is supposed to read, else for writing. it's the engine inside BIO_do_connect_retry(), and you can also pair it up with BIO_read(3). same energy as above: it succeeds immediately if max_time == 0 (that means no timeout given). π«Ά
and if sockets are not available? it still supports polling β it succeeds after sleeping at most the given nap_milliseconds, specifically so you don't end up in a tight busy loop burning your CPU for no reason. π via nap_milliseconds the caller decides the polling granularity. your nap, your rules. π΄
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 these three iconic endings:
- 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(). if nap_milliseconds is < 0, then a default value of 100 ms is used. πΈ
now the timeout parameter, listen closely:
- if
timeoutis> 0, that's 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 don't be gagged when your error queue comes back looking different. π
π RETURN VALUES π
BIO_socket_wait(), BIO_wait(), and BIO_do_connect_retry() all use the same little report card:
-1β error π0β timeout β°1β success β¨
three values, three moods. periodt.
π SEE ALSO π
go read those next, iykyk π
π HISTORY π
BIO_socket_wait(), BIO_wait(), and BIO_do_connect_retry() were added in OpenSSL 3.0. so if you're on something older... bestie. upgrade. π
π COPYRIGHT π
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 4.0.3, dated 2026-09-29, filed under BIO_SOCKET_WAIT(3SSL). go forth and connect responsibly πβ¨πΈ
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms