---
name: "BIO_socket_wait"
section: "3ssl"
platform: "linux"
package: "openssl"
version: "3.6.5-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/BIO_socket_wait"
---

# BIO\_socket\_wait(3ssl)

BIO connection utility functions

## NAME

BIO\_socket\_wait, BIO\_wait, BIO\_do\_connect\_retry - BIO connection utility functions

## 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);
```

## DESCRIPTION

**BIO\_socket\_wait()** waits on the socket **fd** for reading if **for\_read** is not 0, else for writing, at most until **max\_time**. It succeeds immediately if **max\_time** == 0 (which means no timeout given).

**BIO\_wait()** waits at most until **max\_time** on the given (typically socket-based) **bio**, for reading if **bio** is supposed to read, else for writing. It is used by **BIO\_do\_connect\_retry()** and can be used together **BIO\_read**(3). It succeeds immediately if **max\_time** == 0 (which means no timeout given). If sockets are not available it supports polling by succeeding after sleeping at most the given **nap\_milliseconds** in order to avoid a tight busy loop. Via **nap\_milliseconds** the caller determines the polling granularity.

**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., connection succeeded, timeout has been reached, or 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. If the **timeout** parameter is \> 0 this 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. The function may, directly or indirectly, invoke **ERR\_clear\_error()**.

## RETURN VALUES

**BIO\_socket\_wait()**, **BIO\_wait()**, and **BIO\_do\_connect\_retry()** return -1 on error, 0 on timeout, and 1 on success.

## SEE ALSO

**BIO\_do\_connect**(3), **BIO\_read**(3)

## HISTORY

**BIO\_socket\_wait()**, **BIO\_wait()**, and **BIO\_do\_connect\_retry()** were added in OpenSSL 3.0.

## 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\>.
