aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-10 10:18:13 +0000
committerKazuki Yamaguchi <k@rhe.jp>2016-06-11 11:37:48 +0900
commitb95b2da23bed6b69cfbb1b75f0e6db73616533d4 (patch)
tree12b2f2718f48b9bc516612dccf63d0284e656607
parent0cfe60ecebea5808c8d97f3c98227c37d327d67d (diff)
downloadruby-topic/read-ahead.tar.gz
openssl: enable SSLContext read_ahead accessortopic/read-ahead
-rw-r--r--ext/openssl/extconf.rb3
-rw-r--r--ext/openssl/ossl_ssl.c41
-rw-r--r--test/openssl/test_ssl.rb12
3 files changed, 56 insertions, 0 deletions
diff --git a/ext/openssl/extconf.rb b/ext/openssl/extconf.rb
index ad92a28..b01ef73 100644
--- a/ext/openssl/extconf.rb
+++ b/ext/openssl/extconf.rb
@@ -84,6 +84,9 @@ engines.each { |name|
OpenSSL.check_func_or_macro("ENGINE_load_#{name}", "openssl/engine.h")
}
+OpenSSL.check_func_or_macro("SSL_CTX_set_read_ahead", "openssl/ssl.h")
+OpenSSL.check_func_or_macro("SSL_CTX_get_read_ahead", "openssl/ssl.h")
+
# added in 0.9.8X
have_func("EVP_CIPHER_CTX_new")
have_func("EVP_CIPHER_CTX_free")
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 5876946..d658886 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1074,6 +1074,45 @@ ossl_sslctx_set_ecdh_curves(VALUE self, VALUE arg)
/*
* call-seq:
+ * ctx.read_ahead -> true or false
+ */
+static VALUE
+ossl_sslctx_get_read_ahead(VALUE self)
+{
+#if defined(HAVE_SSL_CTX_GET_READ_AHEAD)
+ SSL_CTX *ctx;
+
+ GetSSLCTX(self, ctx);
+
+ return SSL_CTX_get_read_ahead(ctx) ? Qtrue : Qfalse;
+#else
+ return Qfalse;
+#endif
+}
+
+/*
+ * call-seq:
+ * ctx.read_ahead = boolean -> boolean
+ */
+#if defined(HAVE_SSL_CTX_SET_READ_AHEAD)
+static VALUE
+ossl_sslctx_set_read_ahead(VALUE self, VALUE boolean)
+{
+ SSL_CTX *ctx;
+
+ GetSSLCTX(self, ctx);
+ rb_check_frozen(self);
+
+ SSL_CTX_set_read_ahead(ctx, RTEST(boolean));
+
+ return boolean;
+}
+#else
+#define ossl_sslctx_set_read_ahead rb_f_notimplement
+#endif
+
+/*
+ * call-seq:
* ctx.security_level -> Integer
*
* Returns the security level for the context.
@@ -2449,6 +2488,8 @@ Init_ossl_ssl(void)
rb_define_method(cSSLContext, "ciphers", ossl_sslctx_get_ciphers, 0);
rb_define_method(cSSLContext, "ciphers=", ossl_sslctx_set_ciphers, 1);
rb_define_method(cSSLContext, "ecdh_curves=", ossl_sslctx_set_ecdh_curves, 1);
+ rb_define_method(cSSLContext, "read_ahead", ossl_sslctx_get_read_ahead, 0);
+ rb_define_method(cSSLContext, "read_ahead=", ossl_sslctx_set_read_ahead, 1);
rb_define_method(cSSLContext, "security_level", ossl_sslctx_get_security_level, 0);
rb_define_method(cSSLContext, "security_level=", ossl_sslctx_set_security_level, 1);
diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb
index b1dc223..f3ec8b6 100644
--- a/test/openssl/test_ssl.rb
+++ b/test/openssl/test_ssl.rb
@@ -1246,6 +1246,18 @@ end
skip "FIXME: SSLContext#key= currently does not raise because SSL_CTX_use_certificate() is delayed"
end
+ def test_read_ahead
+ ctx = OpenSSL::SSL::SSLContext.new
+ assert_equal(false, ctx.read_ahead)
+ begin
+ ctx.read_ahead = true
+ rescue NotImplementedError
+ assert_equal(false, ctx.read_ahead)
+ return
+ end
+ assert_equal(true, ctx.read_ahead)
+ end
+
private
def start_server_version(version, ctx_proc=nil, server_proc=nil, &blk)