From fd614e89243566290458949cc4eef8d46ba7f707 Mon Sep 17 00:00:00 2001 From: tenderlove Date: Wed, 5 Aug 2015 23:17:33 +0000 Subject: * ext/openssl/lib/openssl/ssl.rb (module OpenSSL): move SSLSocket#sysclose to Ruby. * ext/openssl/ossl_ssl.c (ossl_ssl_close): ditto git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51497 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/openssl/ossl_ssl.c | 23 ++++++++--------------- lib/openssl/ssl.rb | 10 ++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index 286c447..881057f 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -68,7 +68,6 @@ static VALUE eSSLErrorWaitWritable; #define ossl_ssl_get_io(o) rb_iv_get((o),"@io") #define ossl_ssl_get_ctx(o) rb_iv_get((o),"@context") -#define ossl_ssl_get_sync_close(o) rb_iv_get((o),"@sync_close") #define ossl_ssl_get_x509(o) rb_iv_get((o),"@x509") #define ossl_ssl_get_key(o) rb_iv_get((o),"@key") @@ -1590,31 +1589,25 @@ ossl_ssl_write_nonblock(int argc, VALUE *argv, VALUE self) /* * call-seq: - * ssl.sysclose => nil + * ssl.stop => nil * - * Shuts down the SSL connection and prepares it for another connection. + * Stops the SSL connection and prepares it for another connection. */ static VALUE -ossl_ssl_close(VALUE self) +ossl_ssl_stop(VALUE self) { SSL *ssl; - VALUE io; /* ossl_ssl_data_get_struct() is not usable here because it may return * from this function; */ GetSSL(self, ssl); - io = ossl_ssl_get_io(self); - if (!RTEST(rb_funcall(io, rb_intern("closed?"), 0))) { - if (ssl) { - ossl_ssl_shutdown(ssl); - SSL_free(ssl); - } - DATA_PTR(self) = NULL; - if (RTEST(ossl_ssl_get_sync_close(self))) - rb_funcall(io, rb_intern("close"), 0); + if (ssl) { + ossl_ssl_shutdown(ssl); + SSL_free(ssl); } + DATA_PTR(self) = NULL; return Qnil; } @@ -2287,7 +2280,7 @@ Init_ossl_ssl(void) rb_define_private_method(cSSLSocket, "sysread_nonblock", ossl_ssl_read_nonblock, -1); rb_define_method(cSSLSocket, "syswrite", ossl_ssl_write, 1); rb_define_private_method(cSSLSocket, "syswrite_nonblock", ossl_ssl_write_nonblock, -1); - rb_define_method(cSSLSocket, "sysclose", ossl_ssl_close, 0); + rb_define_private_method(cSSLSocket, "stop", ossl_ssl_stop, 0); rb_define_method(cSSLSocket, "cert", ossl_ssl_get_cert, 0); rb_define_method(cSSLSocket, "peer_cert", ossl_ssl_get_peer_cert, 0); rb_define_method(cSSLSocket, "peer_cert_chain", ossl_ssl_get_peer_cert_chain, 0); diff --git a/lib/openssl/ssl.rb b/lib/openssl/ssl.rb index 1e398fc..03d0ebe 100644 --- a/lib/openssl/ssl.rb +++ b/lib/openssl/ssl.rb @@ -291,6 +291,16 @@ module OpenSSL end end + # call-seq: + # ssl.sysclose => nil + # + # Shuts down the SSL connection and prepares it for another connection. + def sysclose + return if closed? + stop + io.close if sync_close + end + ## # Perform hostname verification after an SSL connection is established # -- cgit v1.2.3