Skip to content

Commit c99d24c

Browse files
committed
Introduce basic support for close_read and close_write.
1 parent 362a69a commit c99d24c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

lib/openssl/ssl.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ def session
459459
nil
460460
end
461461

462+
# Close the stream for reading.
463+
def close_read
464+
# Unsupported and ignored.
465+
# Just don't read any more.
466+
end
467+
468+
# Close the stream for writing.
469+
def close_write
470+
stop
471+
end
472+
462473
private
463474

464475
def using_anon_cipher?

test/openssl/test_ssl.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ def test_socket_open_with_local_address_port_context
117117
}
118118
end
119119

120+
def test_socket_close_write
121+
server_proc = proc do |ctx, ssl|
122+
message = ssl.read
123+
ssl.write(message)
124+
ssl.close_write
125+
ensure
126+
ssl.close
127+
end
128+
129+
start_server(server_proc: server_proc) do |port|
130+
ctx = OpenSSL::SSL::SSLContext.new
131+
ssl = OpenSSL::SSL::SSLSocket.open("127.0.0.1", port, context: ctx)
132+
ssl.sync_close = true
133+
ssl.connect
134+
135+
message = "abc"*1024
136+
ssl.write message
137+
ssl.close_write
138+
assert_equal message, ssl.read
139+
ensure
140+
ssl&.close
141+
end
142+
end
143+
120144
def test_add_certificate
121145
ctx_proc = -> ctx {
122146
# Unset values set by start_server

0 commit comments

Comments
 (0)