BIO_S_SOCKET(3ossl)

πŸ’– BIO_S_SOCKET(3ossl) β€” bestie, it's the socket BIO πŸ’–

okay so this is BIO_s_socket and BIO_new_socket from the OpenSSL manual, third section, and it's literally the moment sockets become a BIO. grab a strawberry πŸ“ and let's go.


✨ NAME ✨

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


✨ SYNOPSIS ✨

#include <openssl/bio.h>

const BIO_METHOD *BIO_s_socket(void);

BIO *BIO_new_socket(int sock, int close_flag);

yes bestie, two whole functions, both iconic, both here πŸ’…


✨ DESCRIPTION ✨

BIO_s_socket() hands you the socket BIO method. what even is that? it's a lil wrapper round the platform's socket routines β€” like a cute jacket for your socket, no cap. πŸŽ€

BIO_read_ex() and BIO_write_ex() read or write the underlying socket. that's the whole job fr fr.

BIO_puts() is supported but BIO_gets() is NOT. 🫠 read that again. supported: puts. not supported: gets. don't come for me, that's just what it says.

if the close flag is set then the socket is shut down and closed when the BIO is freed. so like, the BIO dies, the socket dies too. ride or die energy πŸ’€

BIO_new_socket() returns a socket BIO using sock and close_flag. that's it, that's the function. πŸ‘‘


✨ NOTES ✨

socket BIOs also support any relevant functionality of file descriptor BIOs. so you get the fd perks too, lucky you ✨

now, the tea on why there's separate file descriptor and socket BIOs: on some platforms sockets are not file descriptors and they use distinct I/O routines. Windows is one such platform. πŸ‘€

⚠️ any code mixing the two will not work on all platforms. not "might", not "sometimes", will not. so pls don't mix them and then act surprised, bestie 😭

✨ RETURN VALUES ✨

  • BIO_s_socket() β€” returns the socket BIO method. πŸŽ€
  • BIO_new_socket() β€” returns the newly allocated BIO, or NULL is an error occurred. 🫢

Copyright 2000-2016 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, you ate it πŸ’…βœ¨ this was OpenSSL version 3.5.9, dated 2026-09-29, and it's been a whole BIO_S_SOCKET(3ossl) moment. mwah, bye bestie πŸŽ€πŸ«ΆπŸŒˆ

πŸ“¦ where this page comes from