From a0417ef392ec1c31baee9394accfd6662200a1e6 Mon Sep 17 00:00:00 2001 From: Jean Boussier Date: Mon, 6 Nov 2023 14:52:29 +0100 Subject: [PATCH] Expose `IO#timeout` and `IO#timeout=` if available Ref: https://bugs.ruby-lang.org/issues/18630 --- lib/openssl/ssl.rb | 12 ++++++++++++ test/openssl/test_ssl.rb | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/lib/openssl/ssl.rb b/lib/openssl/ssl.rb index e557b8b48..1ab815a8a 100644 --- a/lib/openssl/ssl.rb +++ b/lib/openssl/ssl.rb @@ -421,6 +421,18 @@ def session nil end + if IO.method_defined?(:timeout) + def timeout + @io.timeout + end + end + + if IO.method_defined?(:timeout=) + def timeout=(timeout) + @io.timeout = timeout + end + end + private def using_anon_cipher? diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index 07dc9a343..4d33626cb 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -81,6 +81,23 @@ def test_socket_open } end + def test_socket_timeout + start_server { |port| + begin + ssl = OpenSSL::SSL::SSLSocket.open("127.0.0.1", port) + ssl.sync_close = true + assert_nil ssl.timeout + ssl.timeout = 1 + assert_equal 1, ssl.timeout + ssl.connect + + ssl.puts "abc"; assert_equal "abc\n", ssl.gets + ensure + ssl&.close + end + } + end + def test_socket_open_with_context start_server { |port| begin