Last active
December 22, 2015 13:18
-
-
Save headius/6477733 to your computer and use it in GitHub Desktop.
Start to remove the extra buffering in openssl/buffering.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/ruby/1.9/openssl/buffering.rb b/lib/ruby/1.9/openssl/buffering.rb | |
index 51bc968..f07a55f 100644 | |
--- a/lib/ruby/1.9/openssl/buffering.rb | |
+++ b/lib/ruby/1.9/openssl/buffering.rb | |
@@ -81,24 +81,7 @@ module OpenSSL::Buffering | |
# See IO#read for full details. | |
def read(size=nil, buf=nil) | |
- if size == 0 | |
- if buf | |
- buf.clear | |
- return buf | |
- else | |
- return "" | |
- end | |
- end | |
- until @eof | |
- break if size && size <= @rbuffer.size | |
- fill_rbuff | |
- end | |
- ret = consume_rbuff(size) || "" | |
- if buf | |
- buf.replace(ret) | |
- ret = buf | |
- end | |
- (size && ret.empty?) ? nil : ret | |
+ sysread(size, buf) | |
end | |
## | |
@@ -108,28 +91,11 @@ module OpenSSL::Buffering | |
# See IO#readpartial for full details. | |
def readpartial(maxlen, buf=nil) | |
- if maxlen == 0 | |
- if buf | |
- buf.clear | |
- return buf | |
- else | |
- return "" | |
- end | |
- end | |
- if @rbuffer.empty? | |
- begin | |
- return sysread(maxlen, buf) | |
- rescue Errno::EAGAIN | |
- retry | |
- end | |
- end | |
- ret = consume_rbuff(maxlen) | |
- if buf | |
- buf.replace(ret) | |
- ret = buf | |
+ begin | |
+ return sysread(maxlen, buf) | |
+ rescue Errno::EAGAIN | |
+ retry | |
end | |
- raise EOFError if ret.empty? | |
- ret | |
end | |
## | |
@@ -162,24 +128,7 @@ module OpenSSL::Buffering | |
# more details. http://www.openssl.org/support/faq.html | |
def read_nonblock(maxlen, buf=nil) | |
- if maxlen == 0 | |
- if buf | |
- buf.clear | |
- return buf | |
- else | |
- return "" | |
- end | |
- end | |
- if @rbuffer.empty? | |
- return sysread_nonblock(maxlen, buf) | |
- end | |
- ret = consume_rbuff(maxlen) | |
- if buf | |
- buf.replace(ret) | |
- ret = buf | |
- end | |
- raise EOFError if ret.empty? | |
- ret | |
+ sysread_nonblock(maxlen, buf) | |
end | |
## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment