diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-21 15:57:52 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-21 15:57:52 +0000 |
commit | 9cfe35ad503cd6bb598dea85517949b932719afe (patch) | |
tree | 00b50c4b264d237624d19632bc9b086feaeac4a8 /test | |
parent | 6adda0379c0dc2b2f881060cba2ad40493e59608 (diff) |
* io.c (io_getpartial): error message describes what should be
waited after nonblocking error.
(rb_io_write_nonblock): ditto.
* ext/socket/init.c (s_recvfrom_nonblock): ditto.
(s_accept_nonblock): ditto.
* ext/socket/socket.c (sock_connect_nonblock): ditto.
* ext/socket/ancdata.c (bsock_sendmsg_internal): ditto.
(bsock_recvmsg_internal): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_io.rb | 24 | ||||
-rw-r--r-- | test/socket/test_nonblock.rb | 74 |
2 files changed, 96 insertions, 2 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index 0c1c6b2d2b..0f448dbf39 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -857,6 +857,30 @@ class TestIO < Test::Unit::TestCase end) end + def test_read_nonblock_error + return if !have_nonblock? + with_pipe {|r, w| + begin + r.read_nonblock 4096 + rescue Errno::EWOULDBLOCK + assert_match(/WANT_READ/, $!.message) + end + } + end + + def test_write_nonblock_error + return if !have_nonblock? + with_pipe {|r, w| + begin + loop { + w.write_nonblock "a"*100000 + } + rescue Errno::EWOULDBLOCK + assert_match(/WANT_WRITE/, $!.message) + end + } + end + def test_gets pipe(proc do |w| w.write "foobarbaz" diff --git a/test/socket/test_nonblock.rb b/test/socket/test_nonblock.rb index abc844ceb8..665648a358 100644 --- a/test/socket/test_nonblock.rb +++ b/test/socket/test_nonblock.rb @@ -124,9 +124,18 @@ class TestSocketNonblock < Test::Unit::TestCase af, port, host, addr = serv.addr c = TCPSocket.new(addr, port) s = serv.accept - return c, s + if block_given? + begin + yield c, s + ensure + c.close if !c.closed? + s.close if !s.closed? + end + else + return c, s + end ensure - serv.close if serv + serv.close if serv && !serv.closed? end def test_tcp_recv_nonblock @@ -181,4 +190,65 @@ class TestSocketNonblock < Test::Unit::TestCase end =end + def test_sendmsg_nonblock_error + tcp_pair {|c, s| + begin + loop { + c.sendmsg_nonblock("a" * 100000) + } + rescue Errno::EWOULDBLOCK + assert_match(/WANT_WRITE/, $!.message) + end + } + end + + def test_recvmsg_nonblock_error + tcp_pair {|c, s| + begin + c.recvmsg_nonblock(4096) + rescue Errno::EWOULDBLOCK + assert_match(/WANT_READ/, $!.message) + end + } + end + + def test_recv_nonblock_error + tcp_pair {|c, s| + begin + c.recv_nonblock(4096) + rescue Errno::EWOULDBLOCK + assert_match(/WANT_READ/, $!.message) + end + } + end + + def test_connect_nonblock_error + serv = TCPServer.new("127.0.0.1", 0) + af, port, host, addr = serv.addr + c = Socket.new(:INET, :STREAM) + begin + c.connect_nonblock(Socket.sockaddr_in(port, "127.0.0.1")) + rescue Errno::EINPROGRESS + assert_match(/WANT_WRITE/, $!.message) + end + ensure + serv.close if serv && !serv.closed? + c.close if c && !c.closed? + end + + def test_accept_nonblock_error + serv = Socket.new(:INET, :STREAM) + serv.bind(Socket.sockaddr_in(0, "127.0.0.1")) + serv.listen(5) + port = serv.local_address.ip_port + begin + s, _ = serv.accept_nonblock + rescue Errno::EWOULDBLOCK, Errno::ECONNABORTED, Errno::EPROTO + assert_match(/WANT_READ/, $!.message) + end + ensure + serv.close if serv && !serv.closed? + s.close if s && !s.closed? + end + end if defined?(Socket) |