diff options
author | Samuel Williams <[email protected]> | 2024-04-22 20:48:40 +1200 |
---|---|---|
committer | git <[email protected]> | 2024-04-30 14:51:58 +0000 |
commit | 1699772ac4e62d783aab6e820f978c04a215a612 (patch) | |
tree | 2d274d752baa4eff79b444b43fb417f47e7788d7 | |
parent | 8fb430c1da0d27247c5b425487ab4766afe8165d (diff) |
[ruby/openssl] Introduce basic support for `close_read` and `close_write`.
https://github.com/ruby/openssl/commit/c99d24cee9
-rw-r--r-- | ext/openssl/lib/openssl/ssl.rb | 11 | ||||
-rw-r--r-- | test/openssl/test_ssl.rb | 24 |
2 files changed, 35 insertions, 0 deletions
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb index 75a74a3f51..0568276a1e 100644 --- a/ext/openssl/lib/openssl/ssl.rb +++ b/ext/openssl/lib/openssl/ssl.rb @@ -459,6 +459,17 @@ ssbzSibBsu/6iGtCOGEoXJf//////////wIBAg== nil end + # Close the stream for reading. + def close_read + # Unsupported and ignored. + # Just don't read any more. + end + + # Close the stream for writing. + def close_write + stop + end + private def using_anon_cipher? diff --git a/test/openssl/test_ssl.rb b/test/openssl/test_ssl.rb index 66d63a981d..3df391fac1 100644 --- a/test/openssl/test_ssl.rb +++ b/test/openssl/test_ssl.rb @@ -117,6 +117,30 @@ class OpenSSL::TestSSL < OpenSSL::SSLTestCase } end + def test_socket_close_write + server_proc = proc do |ctx, ssl| + message = ssl.read + ssl.write(message) + ssl.close_write + ensure + ssl.close + end + + start_server(server_proc: server_proc) do |port| + ctx = OpenSSL::SSL::SSLContext.new + ssl = OpenSSL::SSL::SSLSocket.open("127.0.0.1", port, context: ctx) + ssl.sync_close = true + ssl.connect + + message = "abc"*1024 + ssl.write message + ssl.close_write + assert_equal message, ssl.read + ensure + ssl&.close + end + end + def test_add_certificate ctx_proc = -> ctx { # Unset values set by start_server |