SSL_CTX_SET_READ_AHEAD(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… SSL_CTX_SET_READ_AHEAD πŸ’…

ok so this is the 3ossl girlies' guide to read-ahead β€” aka the "should OpenSSL gobble up ALL the bytes or just, like, the ones it needs" setting. bestie, it's giving buffer management realness and honestly it's iconic.


✨ 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 β€” managing whether to read as many input bytes as possible. that's the whole vibe 🫢


🌸 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 πŸ¦‹

ok so picture this: SSL_CTX_set_read_ahead() and SSL_set_read_ahead() decide whether we should read as many input bytes as possible (this is a nonblocking-reads thing, iykyk) or not. like, say OpenSSL currently needs x bytes but y bytes are sitting there available from the underlying BIO (and y > x) β€” then:

  • read ahead ON β†’ OpenSSL slurps all y bytes into its buffer (as long as the buffer is big enough πŸ’–)
  • read ahead OFF β†’ it takes just x bytes, no hoarding

setting the yes parameter to 0 turns reading ahead off, and any other value turns it on. slay.

SSL_CTX_set_default_read_ahead() is identical to SSL_CTX_set_read_ahead(). literally the same thing, not me making that up.

SSL_CTX_get_read_ahead() and SSL_get_read_ahead() tell you whether reading ahead has been set or not. and SSL_CTX_get_default_read_ahead() is identical to SSL_CTX_get_read_ahead(). twins fr fr.

⚠️ these functions cannot be used with QUIC SSL objects. SSL_set_read_ahead() has no effect if you call it on a QUIC SSL object β€” it's just gonna sit there doing nothing, embarrassing honestly 😭

πŸŽ€ NOTES πŸŽ€

these functions have no impact when used with DTLS. and the return values for SSL_CTX_get_read_head() and SSL_get_read_ahead() are undefined for DTLS β€” undefined, bestie, do not build your whole personality on those numbers πŸ’€

setting read_ahead can impact the behaviour of the SSL_pending() function (go read SSL_pending(3), it's linked below 🫢).

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, you do not turn off SSL_MODE_AUTO_RETRY using SSL_CTX_clear_mode(). that keeps you from getting SSL_ERROR_WANT_READ when there's still a complete record available that hasn't been processed. no cap, just leave it alone.

🚨 also: if the application wants to keep using the underlying transport (like, say, 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. and that's the kind of chaos nobody asked for πŸ™ˆ

⭐ RETURN VALUES ⭐

SSL_get_read_ahead() and SSL_CTX_get_read_ahead() return 0 if reading ahead is off, and non zero otherwise. simple. clean. iconic.


🌈 SEE ALSO 🌈


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


ok that's the whole page, bestie, you're officially read-ahead literate πŸ’…βœ¨

version 3.5.6 πŸ¦‹ dated 2026-04-07 πŸŽ€ β€” mwah, go forth and buffer responsibly πŸ’–

πŸ“¦ where this page comes from