diff options
author | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-26 22:41:44 +0000 |
---|---|---|
committer | tenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-26 22:41:44 +0000 |
commit | 988ca60565a5ba6661f7215026f008afebcf7aee (patch) | |
tree | bc196f4e6ce27e3ea505c18269a08f3910b99ba5 /test/ruby | |
parent | eadad2c9000f8cc1d5ef58d7d58569793f3db901 (diff) | |
download | ruby-988ca60565a5ba6661f7215026f008afebcf7aee.tar.gz |
* io.c (io_read_nonblock): support non-blocking reads without raising
exceptions. As in: `io.read_nonblock(size, exception: false)`
[ruby-core:38666] [Feature #5138]
* ext/openssl/ossl_ssl.c (ossl_ssl_read_internal): ditto
* ext/stringio/stringio.c (strio_sysread): ditto
* io.c (rb_io_write_nonblock): support non-blocking writes without
raising an exception.
* ext/openssl/ossl_ssl.c (ossl_ssl_write_internal): ditto
* test/openssl/test_pair.rb (class OpenSSL): tests
* test/ruby/test_io.rb (class TestIO): ditto
* test/socket/test_nonblock.rb (class TestSocketNonblock): ditto
* test/stringio/test_stringio.rb (class TestStringIO): ditto
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42695 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_io.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 5cda6c9e5a..4f002e8b3d 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -1205,6 +1205,16 @@ class TestIO < Test::Unit::TestCase } end + def test_write_nonblock_simple_no_exceptions + skip "IO#write_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM + pipe(proc do |w| + w.write_nonblock('1', exception: false) + w.close + end, proc do |r| + assert_equal("1", r.read) + end) + end + def test_read_nonblock_error return if !have_nonblock? skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM @@ -1215,6 +1225,41 @@ class TestIO < Test::Unit::TestCase assert_kind_of(IO::WaitReadable, $!) end } + + with_pipe {|r, w| + begin + r.read_nonblock 4096, "" + rescue Errno::EWOULDBLOCK + assert_kind_of(IO::WaitReadable, $!) + end + } + end + + def test_read_nonblock_no_exceptions + return if !have_nonblock? + skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM + with_pipe {|r, w| + assert_equal :wait_readable, r.read_nonblock(4096, exception: false) + w.puts "HI!" + assert_equal "HI!\n", r.read_nonblock(4096, exception: false) + w.close + assert_equal nil, r.read_nonblock(4096, exception: false) + } + end + + def test_read_nonblock_with_buffer_no_exceptions + return if !have_nonblock? + skip "IO#read_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM + with_pipe {|r, w| + assert_equal :wait_readable, r.read_nonblock(4096, "", exception: false) + w.puts "HI!" + buf = "buf" + value = r.read_nonblock(4096, buf, exception: false) + assert_equal value, "HI!\n" + assert buf.equal?(value) + w.close + assert_equal nil, r.read_nonblock(4096, "", exception: false) + } end def test_write_nonblock_error @@ -1231,6 +1276,20 @@ class TestIO < Test::Unit::TestCase } end + def test_write_nonblock_no_exceptions + return if !have_nonblock? + skip "IO#write_nonblock is not supported on file/pipe." if /mswin|bccwin|mingw/ =~ RUBY_PLATFORM + with_pipe {|r, w| + loop { + ret = w.write_nonblock("a"*100000, exception: false) + if ret.is_a?(Symbol) + assert_equal :wait_writable, ret + break + end + } + } + end + def test_gets pipe(proc do |w| w.write "foobarbaz" |