From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] ssl: disable copying for writes
Date: Tue, 1 Mar 2016 01:30:24 +0000 [thread overview]
Message-ID: <20160301013024.GA5920@dcvr.yhbt.net> (raw)
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.
---
Consider this patch on hold. Of course we cannot expect
users to manually patch or run ruby-trunk in production.
Pushed to the "ruby-accept_moving_write_buffer" branch
in git://yhbt.net/yahns I will rebase this branch as
necessary.
lib/yahns/openssl_client.rb | 23 ++++++-----------------
1 file 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 @@ def sync
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 @@ def kgio_tryread(len, buf)
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
--
EW
reply other threads:[~2016-03-01 1:30 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/yahns/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160301013024.GA5920@dcvr.yhbt.net \
--to=e@80x24.org \
--cc=yahns-public@yhbt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/yahns.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).