Skip to content

Commit

Permalink
buffering: let #write accept multiple arguments
Browse files Browse the repository at this point in the history
As of Ruby 2.5, IO#write accepts multiple input strings and writes them
at once[1]. Follow that.

[1] https://bugs.ruby-lang.org/issues/9323
  • Loading branch information
rhenium committed Oct 23, 2017
1 parent e72d960 commit cfa154f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/openssl/buffering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,11 @@ def do_write(s)
# Writes _s_ to the stream. If the argument is not a String it will be
# converted using +.to_s+ method. Returns the number of bytes written.

def write(s)
do_write(s)
s.bytesize
def write(*s)
s.inject(0) do |written, str|
do_write(str)
written + str.bytesize
end
end

##
Expand Down
9 changes: 9 additions & 0 deletions test/test_pair.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ def test_write_zero
}
end

def test_write_multiple_arguments
ssl_pair {|s1, s2|
str1 = "foo"; str2 = "bar"
assert_equal 6, s1.write(str1, str2)
s1.close
assert_equal "foobar", s2.read
}
end

def test_partial_tls_record_read_nonblock
ssl_pair { |s1, s2|
# the beginning of a TLS record
Expand Down

0 comments on commit cfa154f

Please sign in to comment.