Skip to content

Commit

Permalink
Expose IO#timeout and IO#timeout= if available
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 6, 2023
1 parent c9b48f9 commit a0417ef
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/openssl/ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
17 changes: 17 additions & 0 deletions test/openssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0417ef

Please sign in to comment.