Skip to content

Commit bd6add3

Browse files
authored
Merge pull request #162 from rhenium/ky/ssl-write-multi
buffering: let #write accept multiple arguments
2 parents 37106e3 + cfa154f commit bd6add3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/openssl/buffering.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,11 @@ def do_write(s)
339339
# Writes _s_ to the stream. If the argument is not a String it will be
340340
# converted using +.to_s+ method. Returns the number of bytes written.
341341

342-
def write(s)
343-
do_write(s)
344-
s.bytesize
342+
def write(*s)
343+
s.inject(0) do |written, str|
344+
do_write(str)
345+
written + str.bytesize
346+
end
345347
end
346348

347349
##

test/test_pair.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,15 @@ def test_write_zero
362362
}
363363
end
364364

365+
def test_write_multiple_arguments
366+
ssl_pair {|s1, s2|
367+
str1 = "foo"; str2 = "bar"
368+
assert_equal 6, s1.write(str1, str2)
369+
s1.close
370+
assert_equal "foobar", s2.read
371+
}
372+
end
373+
365374
def test_partial_tls_record_read_nonblock
366375
ssl_pair { |s1, s2|
367376
# the beginning of a TLS record

0 commit comments

Comments
 (0)