diff options
author | gotoyuzo <gotoyuzo@ruby-lang.org> | 2005-03-05 21:36:11 +0000 |
---|---|---|
committer | gotoyuzo <gotoyuzo@ruby-lang.org> | 2005-03-05 21:36:11 +0000 |
commit | 07765e33b4c652c0068ece9346ea22e0c38c25fd (patch) | |
tree | 984576337f1f94c6c4a35daf63b77721c3ffefc2 /lib | |
parent | ec9198ef9fdca99af2447f7852ed1de458eb5981 (diff) | |
download | ruby-openssl-history-07765e33b4c652c0068ece9346ea22e0c38c25fd.tar.gz |
* ext/openssl/ossl_ssl.c (ossl_start_ssl): should wait for that
the underlying IO become readable or writable if the error was
SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE. [ruby-dev:25795]
* ext/openssl/ossl_ssl.c (ossl_ssl_read, ossl_ssl_write): ditto.
* ext/openssl/lib/openssl/buffering.rb
(Buffering#consume_rbuf): pointless eof flag resetting is deleted.
(Buffering#read): should return an empty string if the specified
size is zero.
(Buffering#readpartial): new method.
(Buffering#readline): fix typo.
(Buffering#getc): return the first character of string correctly.
(Buffering#readchar): fix typo.
(Buffering#eof?): should read again it the input buffer is empty.
(Buffering#do_write): should rescue Errno::EAGAIN.
(Buffering#puts): use "\n" as the output field separator.
* ext/openssl/extconf.rb: get rid of GNUmakefile generation.
* text/openssl/test_pair.rb: test for IO like methods.
* test/ruby/ut_eof.rb: test about empty file.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8081 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r-- | lib/openssl/buffering.rb | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/lib/openssl/buffering.rb b/lib/openssl/buffering.rb index 7ad12d7..39c442b 100644 --- a/lib/openssl/buffering.rb +++ b/lib/openssl/buffering.rb @@ -41,7 +41,6 @@ module Buffering def consume_rbuff(size=nil) if @rbuffer.size == 0 - @eof = nil nil else size = @rbuffer.size unless size @@ -54,6 +53,14 @@ module Buffering public def read(size=nil, buf=nil) + if size == 0 + if buf + buf.clear + return buf + else + return "" + end + end fill_rbuff unless defined? @rbuffer @eof ||= nil until @eof @@ -68,6 +75,31 @@ module Buffering (size && ret.empty?) ? nil : ret end + def readpartial(maxlen, buf=nil) + if maxlen == 0 + if buf + buf.clear + return buf + else + return "" + end + end + if !defined?(@rbuffer) || @rbuffer.size == 0 + begin + return sysread(maxlen, buf) + rescue Errno::EAGAIN + retry + end + end + ret = consume_rbuff(maxlen) + if buf + buf.replace(ret) + ret = buf + end + raise EOFError if ret.empty? + ret + end + def gets(eol=$/) fill_rbuff unless defined? @rbuffer idx = @rbuffer.index(eol) @@ -101,13 +133,13 @@ module Buffering end def readline(eol=$/) - raise EOFErorr if eof? + raise EOFError if eof? gets(eol) end def getc c = read(1) - c ? c.to_i : nil + c ? c[0] : nil end def each_byte @@ -117,7 +149,7 @@ module Buffering end def readchar - raise EOFErorr if eof? + raise EOFError if eof? getc end @@ -127,6 +159,7 @@ module Buffering def eof? @eof ||= nil + fill_rbuff if !@eof && (!defined?(@rbuffer) || @rbuffer.size == 0) @eof && @rbuffer.size == 0 end alias eof eof? @@ -144,7 +177,12 @@ module Buffering remain = idx ? idx + $/.size : @wbuffer.length nwritten = 0 while remain > 0 - nwrote = syswrite(@wbuffer[nwritten,remain]) + str = @wbuffer[nwritten,remain] + begin + nwrote = syswrite(str) + rescue Errno::EAGAIN + retry + end remain -= nwrote nwritten += nwrote end @@ -166,10 +204,13 @@ module Buffering def puts(*args) s = "" + if args.empty? + s << "\n" + end args.each{|arg| s << arg.to_s - unless /#{$/}\z/o =~ s - s << $/ + if $/ && /\n\z/ !~ s + s << "\n" end } do_write(s) |