Skip to content

Commit

Permalink
Merge pull request #162 from rhenium/ky/ssl-write-multi
Browse files Browse the repository at this point in the history
buffering: let #write accept multiple arguments
  • Loading branch information
rhenium authored Nov 13, 2017
2 parents 37106e3 + cfa154f commit bd6add3
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 bd6add3

Please sign in to comment.