about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-03-01 01:20:44 +0000
committerEric Wong <e@80x24.org>2016-03-01 01:20:44 +0000
commitcf166e989fa31ea2fb8547fc19f7337308444984 (patch)
treeb93df2825c9b0db6350c3214d557918f901b99d6
parent7ee064f52ee740eeafa49089911f6eca18c67e38 (diff)
downloadyahns-ruby-accept_moving_write_buffer.tar.gz
This is a partial revert of 551e670281bea77e727a732ba94275265ccae5f6
"fix output buffering with SSL_write".

With the patch to enable SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
in <https://bugs.ruby-lang.org/issues/12126>, we can avoid
the hacky workaround we do.

We still implement our own trysendfile to avoid overhead
of string allocation kgio_trywrite and we still fill in
the missing kgio_trywritev addition.
-rw-r--r--lib/yahns/openssl_client.rb23
1 files changed, 6 insertions, 17 deletions
diff --git a/lib/yahns/openssl_client.rb b/lib/yahns/openssl_client.rb
index cd7d210..30ac0e0 100644
--- a/lib/yahns/openssl_client.rb
+++ b/lib/yahns/openssl_client.rb
@@ -36,18 +36,15 @@ module Yahns::OpenSSLClient # :nodoc:
   def yahns_init_ssl(ssl_ctx)
     @need_accept = true
     @ssl = OpenSSL::SSL::SSLSocket.new(self, ssl_ctx)
-    @ssl_blocked = nil
   end
 
   def kgio_trywrite(buf)
-    buf = @ssl_blocked = buf.dup
     case rv = @ssl.write_nonblock(buf, exception: false)
     when :wait_readable, :wait_writable
-      return rv # do not clear ssl_blocked
+      return rv
     when Integer
       rv = buf.bytesize == rv ? nil : buf.byteslice(rv, buf.bytesize - rv)
     end
-    @ssl_blocked = nil
     rv
   end
 
@@ -75,22 +72,14 @@ module Yahns::OpenSSLClient # :nodoc:
   def trysendfile(io, offset, count)
     return 0 if count == 0
 
-    unless buf = @ssl_blocked
-      count = 0x4000 if count > 0x4000
-      buf = Thread.current[:yahns_sfbuf] ||= ''.dup
-      io.pos = offset
-      buf = io.read(count, buf) or return # nil for EOF
-      buf = @ssl_blocked = buf.dup
-    end
+    count = 0x4000 if count > 0x4000
+    buf = Thread.current[:yahns_sfbuf] ||= ''.dup
+    io.pos = offset
+    buf = io.read(count, buf) or return # nil for EOF
 
     # call write_nonblock directly since kgio_trywrite allocates
     # an unnecessary string
-    case rv = @ssl.write_nonblock(buf, exception: false)
-    when :wait_readable, :wait_writable
-      return rv # do not clear ssl_blocked
-    end
-    @ssl_blocked = nil
-    rv
+    @ssl.write_nonblock(buf, exception: false)
   end
 
   def close