BIO_CONNECT(3SSL)

πŸ’– BIO_CONNECT β€” the socket glow-up era πŸ’–

okay bestie, so this is the OpenSSL BIO_CONNECT(3SSL) page, and it's literally all about setting up your socket communication: making sockets, binding them, connecting them, making them listen, accepting the girlies that show up, and then closing the door behind them. it's giving backstage-pass energy for your network connections. πŸ’…


✨ NAME ✨

BIO_socket, BIO_bind, BIO_connect, BIO_listen, BIO_accept_ex, BIO_closesocket β€” the BIO socket communication setup routines. that's the whole squad 🫢


✨ SYNOPSIS ✨

#include <openssl/bio.h>

int BIO_socket(int domain, int socktype, int protocol, int options);
int BIO_bind(int sock, const BIO_ADDR *addr, int options);
int BIO_connect(int sock, const BIO_ADDR *addr, int options);
int BIO_listen(int sock, const BIO_ADDR *addr, int options);
int BIO_accept_ex(int accept_sock, BIO_ADDR *peer, int options);
int BIO_closesocket(int sock);

no cap, that's the lineup. πŸ’«


🌸 DESCRIPTION 🌸

so BIO_socket() creates a socket in the domain domain, of type socktype, with protocol. and listen β€” the socket options are currently unused, like genuinely unused, but she's sitting there in the function signature for future use. placeholder queen behavior, we respect it. πŸ’…

BIO_bind() binds the source address and service to a socket, and it may be useful before calling BIO_connect(). the options can include BIO_SOCK_REUSEADDR, which gets its own little spotlight down in "FLAGS" below. πŸŽ€

BIO_connect() connects sock to the address and service given by addr. connection options can be zero, or honestly any combo of BIO_SOCK_KEEPALIVE, BIO_SOCK_NONBLOCK and BIO_SOCK_NODELAY. flags described in "FLAGS" below, as always. ✨

BIO_listen() has sock start listening on the address and service given by addr. connection options can be zero or any combination of BIO_SOCK_KEEPALIVE, BIO_SOCK_NONBLOCK, BIO_SOCK_NODELAY, BIO_SOCK_REUSEADDR and BIO_SOCK_V6_ONLY. yes, also in "FLAGS" below. πŸ”₯

BIO_accept_ex() waits for an incoming connection on the given socket accept_sock. when it gets one, the address and port of the peer gets stored in peer if that one is non-NULL. accept options may be zero or BIO_SOCK_NONBLOCK, and it's applied on the accepted socket. flags β€” you guessed it β€” "FLAGS" below. 🌈

BIO_closesocket() closes sock. short, sweet, absolutely necessary. πŸ‘‘


πŸ”₯ FLAGS πŸ”₯

these are the little settings you sprinkle on, and here's what each one actually does, no gatekeeping:

πŸ¦‹ BIO_SOCK_KEEPALIVE

enables regular sending of keep-alive messages. she checks in on you. that's the vibe. πŸ’–

πŸ¦‹ BIO_SOCK_NONBLOCK

sets the socket to nonblocking mode. ain't nobody waiting around here. πŸ’…

πŸ¦‹ BIO_SOCK_NODELAY

corresponds to TCP_NODELAY, and disables the Nagle algorithm. with this set, any data will be sent as soon as possible instead of being buffered until there's enough for the socket to send out in one go. main character data does not queue. periodt. ✨

πŸ¦‹ BIO_SOCK_REUSEADDR

try to reuse the address and port combination for a recently closed port. recycling is iconic, actually. 🌸

πŸ¦‹ BIO_SOCK_V6_ONLY

when creating an IPv6 socket, make it only listen for IPv6 addresses and not IPv4 addresses mapped to IPv6. exclusive. she doesn't do remixes. πŸ’œ

πŸ¦‹ BIO_SOCK_TFO

enables TCP Fast Open on the socket. uses appropriate APIs on supported operating systems, including Linux, macOS and FreeBSD. can be used with BIO_connect(), BIO_set_conn_mode(), BIO_set_bind_mode(), and BIO_listen(). on Linux kernels before 4.14, use BIO_set_conn_address() to specify the peer address before starting the TLS handshake. ⭐


these flags are bit flags, bestie, so you combine them with the "|" operator, like this:

BIO_connect(sock, addr, BIO_SOCK_KEEPALIVE | BIO_SOCK_NONBLOCK);

see? like friendship bracelets but for socket options. 🫢


πŸŽ€ RETURN VALUES πŸŽ€

BIO_socket() returns the socket number on success or INVALID_SOCKET (-1) on error. when an error has occurred, the OpenSSL error stack will hold the error data and errno has the system error. 😭

BIO_bind(), BIO_connect() and BIO_listen() return 1 on success or 0 on error. same deal β€” when an error has occurred, the OpenSSL error stack will hold the error data and errno has the system error. πŸ’€

BIO_accept_ex() returns the accepted socket on success or INVALID_SOCKET (-1) on error. and yep β€” when an error has occurred, the OpenSSL error stack will hold the error data and errno has the system error. πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘

BIO_ADDR(3) β€” go read that one too, she's the address bestie. πŸ’–


πŸ’œ HISTORY πŸ’œ

BIO_gethostname(), BIO_get_port(), BIO_get_host_ip(), BIO_get_accept_socket() and BIO_accept() were deprecated in OpenSSL 1.1.0. use the functions described above instead. rip to the old crew, they served their time. πŸ•―οΈ


copyright 2016-2022 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 bestie, you now know socket setup better than half the internet πŸ’…βœ¨

version 4.0.3 🩷 dated 2026-09-29 πŸ¦‹ and that's the BIO_CONNECT(3SSL) page, mwah πŸŽ€πŸ’œ

πŸ“¦ where this page comes from