Skip to content

Commit

Permalink
Introduce basic support for close_read and close_write.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Apr 22, 2024
1 parent d3d857c commit 7b37a24
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/openssl/ssl.rb
Expand Up @@ -459,6 +459,17 @@ def session
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?
Expand Down
23 changes: 23 additions & 0 deletions test/openssl/test_ssl.rb
Expand Up @@ -117,6 +117,29 @@ def test_socket_open_with_local_address_port_context
}
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

ssl.puts "abc"
ssl.close_write
assert_equal "abc\n", ssl.gets
ensure
ssl&.close
end
end

def test_add_certificate
ctx_proc = -> ctx {
# Unset values set by start_server
Expand Down

0 comments on commit 7b37a24

Please sign in to comment.