SSL_SET_FD(3SSL)
π SSL_SET_FD β bestie, let's plug a file descriptor into your SSL object π
okay so this is a page from the OpenSSL manual, section 3SSL β the one where we wire a raw file descriptor up to an SSL thing. sit down, grab a strawberry π, we're doing this.
β¨ NAME β¨
SSL_set_fd, SSL_set_rfd, SSL_set_wfd β connect the SSL object with a file descriptor. that's the whole vibe. we're matchmaking π«Ά
πΈ SYNOPSIS πΈ
#include <openssl/ssl.h>
int SSL_set_fd(SSL *ssl, int fd);
int SSL_set_rfd(SSL *ssl, int fd);
int SSL_set_wfd(SSL *ssl, int fd);
three little functions, one big job. no cap. π
π¦ DESCRIPTION π¦
SSL_set_fd() sets the file descriptor fd as the input/output facility for the TLS/SSL (encrypted) side of ssl. and like, fd is typically gonna be the socket file descriptor of a network connection. classic. π₯
the way that this works: when it does the operation, a socket BIO is automatically created to interface between the ssl and fd. the BIO β and therefore the SSL engine too β inherit the behaviour of fd. so if fd is nonblocking, your ssl is gonna be nonblocking too. it's giving "you are who you hang out with" fr fr. β¨
when you use it on a QUIC connection SSL object, a datagram BIO gets automatically created instead of a socket BIO. but bestie β these functions fail if you call them on a QUIC stream SSL object. π so don't.
and if there was already a BIO connected to ssl? BIO_free() gets called on it. for both the reading and writing side, if they're different. cleaning house, as she should. π§Ή
SSL_set_rfd() and SSL_set_wfd() perform the respective action β but only for the read channel or the write channel. which, iconic, means you can set them independently. π
β RETURN VALUES β
these are the possible outcomes, no surprises:
0β the operation failed. check the error stack to find out why. go read the receipts, bestie. π1β the operation succeeded. slay!! π
π NOTES π
okay Windows girlies, this one's for you: on Windows, a socket handle is a 64-bit data type (UINT_PTR), which leads to a compiler warning when you pass the socket handle to SSL_set_*fd():
conversion from 'SOCKET' to 'int', possible loss of data
for the time being, this warning can safely be ignored β because even though the Microsoft documentation claims the upper limit is INVALID_SOCKET-1 (2^64 - 2), in practice the current socket() implementation returns an index into the kernel handle table, and the size of that table is limited to 2^24. so likeβ¦ it's fine. breathe. π«Ά
ngl this is exactly the kind of thing that sounds scary and is actually a nothingburger. but it IS what the docs say, so don't come for me. π
π SEE ALSO π
go read those too, you'll be obsessed. πβ¨
π COPYRIGHT π
Copyright 2000-2023 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!! π this was SSL_SET_FD(3SSL) β you read it, you understood it, main character energy only. it's version 4.0.3, dated 2026-09-29, and honestly? she ate. π
β¨ mwah, go set some file descriptors. ππ¦πΈ
π¦ 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