SSL_CTX_SET_READ_AHEAD(3SSL)

πŸ’– SSL_CTX_SET_READ_AHEAD β€” bestie edition πŸ’–

ok so this is an OpenSSL manpage (3SSL), and today's main character is: managing whether to read as many input bytes as possible. yes. we're doing buffering discourse. buckle up πŸŽ€


✨ NAME ✨

SSL_CTX_set_read_ahead, SSL_CTX_get_read_ahead, SSL_set_read_ahead, SSL_get_read_ahead, SSL_CTX_get_default_read_ahead β€” the little crew that manages whether to read as many input bytes as possible πŸ¦‹


🌸 SYNOPSIS 🌸

#include <openssl/ssl.h>

void SSL_set_read_ahead(SSL *s, int yes);
int SSL_get_read_ahead(const SSL *s);

SSL_CTX_set_read_ahead(SSL_CTX *ctx, int yes);
long SSL_CTX_get_read_ahead(SSL_CTX *ctx);
long SSL_CTX_get_default_read_ahead(SSL_CTX *ctx);

πŸ’… DESCRIPTION πŸ’…

SSL_CTX_set_read_ahead() and SSL_set_read_ahead() set whether we should read as many input bytes as possible (this matters for nonblocking reads) or not. okay so picture this: OpenSSL currently needs x bytes, but your underlying BIO is sitting there with y bytes available, and y > x. if reading ahead is on, OpenSSL will slurp all y bytes into its buffer (as long as the buffer is big enough to hold them, bestie, it's not gonna overflow for you πŸ™ˆ). if it's off, you get just x bytes. that's it. that's the whole vibe.

Setting the parameter yes to 0 turns reading ahead off, and any other value turns it on. πŸ’–

SSL_CTX_set_default_read_ahead() is identical to SSL_CTX_set_read_ahead(). literally twins, no notes. πŸ‘‘

SSL_CTX_get_read_ahead() and SSL_get_read_ahead() indicate whether reading ahead has been set or not. and SSL_CTX_get_default_read_ahead() is identical to SSL_CTX_get_read_ahead(). again, twins. 🫢

🚨 these functions cannot be used with QUIC SSL objects. and SSL_set_read_ahead() has no effect if you call it on a QUIC SSL object. so, like, don't. πŸ’€

πŸ“ NOTES πŸ“

these functions have no impact when used with DTLS. also the return values for SSL_CTX_get_read_head() and SSL_get_read_ahead() are undefined for DTLS. yes that's a typo in the source, no I will not be fixing it, it's canon now πŸŽ€

Setting read_ahead can impact the behaviour of the SSL_pending() function (go peek at SSL_pending(3)).

Since SSL_read() can return SSL_ERROR_WANT_READ for non-application data records, and SSL_has_pending() can't tell the difference between processed and unprocessed data β€” it's recommended that if read ahead is turned on, that SSL_MODE_AUTO_RETRY is not turned off using SSL_CTX_clear_mode(). that way you won't get SSL_ERROR_WANT_READ while there's still a complete record available that hasn't been processed. do it, it'll save you a whole crisis 😭

If the application wants to continue to use the underlying transport (e.g. a TCP connection) after the SSL connection is finished using SSL_shutdown(), reading ahead should be turned off. otherwise the SSL structure might read data that it shouldn't. ⚠️ class, this one's important.


🌈 RETURN VALUES 🌈

SSL_get_read_ahead() and SSL_CTX_get_read_ahead() return 0 if reading ahead is off, and non zero otherwise. cute and simple. periodt. ✨


πŸ‘€ SEE ALSO πŸ‘€

ssl(7), SSL_pending(3)


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


okay bye bestie, this was version 4.0.3, dated 2026-09-29, and the page is SSL_CTX_SET_READ_AHEAD(3SSL) β€” go forth and buffer responsibly πŸ’œπŸ§šπŸ“

πŸ“¦ where this page comes from