From b52f98282470289cdd94aca46882347e35cb17a3 Mon Sep 17 00:00:00 2001
From: daurnimator <quae@daurnimator.com>
Date: Wed, 31 Oct 2018 14:17:47 +1100
Subject: Add ssl:setReadAhead(), ssl:getReadAhead(), context:setReadAhead(),
 context:getReadAhead()

---
 doc/luaossl.tex | 16 ++++++++++++++++
 src/openssl.c   | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/doc/luaossl.tex b/doc/luaossl.tex
index c3e4463..45c2602 100644
--- a/doc/luaossl.tex
+++ b/doc/luaossl.tex
@@ -914,6 +914,14 @@ Returns the option flags of the context instance as an integer.
 
 Clears the option flags of the context instance.
 
+\subsubsection[\fn{context:setReadAhead}]{\fn{context:setReadAhead($yes$)}}
+
+Sets if read ahead is enabled for the context, $yes$ should be a boolean.
+
+\subsubsection[\fn{context:getReadAhead}]{\fn{context:getReadAhead()}}
+
+Returns if read ahead is enable for the context instance as a boolean.
+
 \subsubsection[\fn{context:setStore}]{\fn{context:setStore($store$)}}
 
 Associate the \module{openssl.x509.store} object $store$ with $context$. Replaces any existing store.
@@ -1112,6 +1120,14 @@ Returns the option flags of the SSL connection instance. See \fn{openssl.ssl.con
 
 Clears the option flags of the SSL connection instance. See \fn{openssl.ssl.context:clearOptions}.
 
+\subsubsection[\fn{ssl:setReadAhead}]{\fn{ssl:setReadAhead($yes$)}}
+
+Sets if read ahead is enabled for the SSL connection instance, $yes$ should be a boolean.
+
+\subsubsection[\fn{ssl:getReadAhead}]{\fn{ssl:getReadAhead()}}
+
+Returns if read ahead is enable for the SSL connection instance as a boolean.
+
 \subsubsection[\fn{ssl:setStore}]{\fn{ssl:setStore($store$)}}
 
 Associate the \module{openssl.x509.store} object $store$ with $ssl$ for both verification and chain building. Replaces any existing stores.
diff --git a/src/openssl.c b/src/openssl.c
index ba97113..7a5031b 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -8593,6 +8593,27 @@ static int sx_clearOptions(lua_State *L) {
 } /* sx_clearOptions() */
 
 
+static int sx_setReadAhead(lua_State *L) {
+	SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
+	int yes = checkbool(L, 2);
+
+	SSL_CTX_set_read_ahead(ctx, yes);
+
+	lua_pushboolean(L, 1);
+
+	return 1;
+} /* sx_setReadAhead() */
+
+
+static int sx_getReadAhead(lua_State *L) {
+	SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
+
+	lua_pushboolean(L, SSL_CTX_get_read_ahead(ctx));
+
+	return 1;
+} /* sx_getReadAhead() */
+
+
 static int sx_setStore(lua_State *L) {
 	SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
 	X509_STORE *store = checksimple(L, 2, X509_STORE_CLASS);
@@ -9425,6 +9446,8 @@ static const auxL_Reg sx_methods[] = {
 	{ "setOptions",       &sx_setOptions },
 	{ "getOptions",       &sx_getOptions },
 	{ "clearOptions",     &sx_clearOptions },
+	{ "setReadAhead",     &sx_setReadAhead },
+	{ "getReadAhead",     &sx_getReadAhead },
 	{ "setStore",         &sx_setStore },
 	{ "getStore",         &sx_getStore },
 	{ "setParam",         &sx_setParam },
@@ -9759,6 +9782,27 @@ static int ssl_clearOptions(lua_State *L) {
 } /* ssl_clearOptions() */
 
 
+static int ssl_setReadAhead(lua_State *L) {
+	SSL *ssl = checksimple(L, 1, SSL_CLASS);
+	int yes = checkbool(L, 2);
+
+	SSL_set_read_ahead(ssl, yes);
+
+	lua_pushboolean(L, 1);
+
+	return 1;
+} /* ssl_setReadAhead() */
+
+
+static int ssl_getReadAhead(lua_State *L) {
+	SSL *ssl = checksimple(L, 1, SSL_CLASS);
+
+	lua_pushboolean(L, SSL_get_read_ahead(ssl));
+
+	return 1;
+} /* ssl_getReadAhead() */
+
+
 #if HAVE_SSL_SET1_CHAIN_CERT_STORE
 static int ssl_setChainStore(lua_State *L) {
 	SSL *ssl = checksimple(L, 1, SSL_CLASS);
@@ -10240,6 +10284,8 @@ static const auxL_Reg ssl_methods[] = {
 	{ "setOptions",       &ssl_setOptions },
 	{ "getOptions",       &ssl_getOptions },
 	{ "clearOptions",     &ssl_clearOptions },
+	{ "setReadAhead",     &ssl_setReadAhead },
+	{ "getReadAhead",     &ssl_getReadAhead },
 #if HAVE_SSL_SET1_CHAIN_CERT_STORE
 	{ "setChainStore",    &ssl_setChainStore },
 #endif
-- 
cgit v1.2.3-59-g8ed1b