BIO_S_SOCKET(3SSL)

πŸ’– BIO_S_SOCKET πŸ’–

okay bestie, welcome to the socket BIO page β€” that's BIO_S_SOCKET(3SSL) from the OpenSSL manual, and yes we're doing this together, hand in hand, no cap 🫢

✨ NAME ✨

BIO_s_socket, BIO_new_socket, BIO_set_send_flags β€” it's giving socket BIO energy, fr fr πŸ¦‹


🌸 SYNOPSIS 🌸

#include <openssl/bio.h>

const BIO_METHOD *BIO_s_socket(void);

BIO *BIO_new_socket(int sock, int close_flag);

long BIO_set_send_flags(BIO *b, int flags);

look at those three little lines, so compact, so iconic πŸ‘‘


πŸ’… DESCRIPTION πŸ’…

  • BIO_s_socket() β€” returns the socket BIO method. Think of it as a cute lil wrapper round your platform's socket routines. she's not doing the work herself, she's delegating πŸ’β™€οΈ
  • BIO_read_ex() and BIO_write_ex() β€” these two read or write the underlying socket. the main characters, honestly.
  • BIO_puts() is supported ✨ but BIO_gets() is not. and we simply don't talk about it πŸ™ˆ (jk we do, it's listed right there, just don't expect BIO_gets() to work on a socket BIO).
  • If the close flag is set, then the socket gets shut down and closed when the BIO is freed. so like, she leaves the party and turns off the lights on her way out πŸ”₯
  • BIO_new_socket() β€” returns a socket BIO using sock and close_flag. that's it, that's the whole job. slay.
  • BIO_set_send_flags() β€” sets flags passed to send(), sendto() and sendmsg(). The set of available flags is platform-dependent, so pls don't assume, bestie. The main intention here is to allow setting the MSG_NOSIGNAL flag to avoid a crash on receiving the SIGPIPE signal. yes really, that's the whole reason she exists β€” she's a bodyguard for your process πŸ˜€πŸ’–

πŸŽ€ NOTES πŸŽ€

Socket BIOs also support any relevant functionality of file descriptor BIOs. they're flexible like that, versatile queen 🌈

So why do file descriptor BIOs and socket BIOs even exist separately?? the tea β˜•: on some platforms, sockets are not file descriptors and use distinct I/O routines. Windows is one such platform, iykyk. Any code mixing the two will not work on all platforms. periodt. don't do it. 🚫


πŸ¦‹ RETURN VALUES πŸ¦‹

  • BIO_s_socket() β€” returns the socket BIO method. every time, no drama.
  • BIO_new_socket() β€” returns the newly allocated BIO, or NULL if an error occurred. so if you see NULL... yeah. that happened. 😭
  • BIO_set_send_flags() β€” returns 1 on success, 0 on errors. simple binary, we love to see it.

⭐ HISTORY ⭐

BIO_set_send_flags() was added in OpenSSL 4.0. she's new here, be nice to her, she's already thriving πŸ’œ


Copyright 2000-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>.


and that's the whole page bestie, you ate that πŸ’…βœ¨ this was OpenSSL 4.0.3, dated 2026-09-29 β€” mwah, go write some sockets, ily πŸ«ΆπŸ’–

πŸ“¦ where this page comes from