aboutsummaryrefslogtreecommitdiffstats
path: root/lib/openssl/buffering.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/openssl/buffering.rb')
-rw-r--r--lib/openssl/buffering.rb17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/openssl/buffering.rb b/lib/openssl/buffering.rb
index 9570f14f..4df90746 100644
--- a/lib/openssl/buffering.rb
+++ b/lib/openssl/buffering.rb
@@ -345,13 +345,18 @@ module OpenSSL::Buffering
@wbuffer << s
@wbuffer.force_encoding(Encoding::BINARY)
@sync ||= false
- if @sync or @wbuffer.size > BLOCK_SIZE
- until @wbuffer.empty?
- begin
- nwrote = syswrite(@wbuffer)
- rescue Errno::EAGAIN
- retry
+ buffer_size = @wbuffer.size
+ if @sync or buffer_size > BLOCK_SIZE
+ nwrote = 0
+ begin
+ while nwrote < buffer_size do
+ begin
+ nwrote += syswrite(@wbuffer[nwrote, buffer_size - nwrote])
+ rescue Errno::EAGAIN
+ retry
+ end
end
+ ensure
@wbuffer[0, nwrote] = ""
end
end