summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-17 15:53:28 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2006-06-17 15:53:28 +0000
commite997ab09ba5fd6c9e92880d754e2f9e6767a03fc (patch)
tree0b0f16e4e07a427af17418bc1f3607c84580d04a /test
parent35c8ae84e5ca20a9263ce7b60cc5b656386c7842 (diff)
* ext/socket/socket.c (bsock_recv_nonblock): new method
BasicSocket#recv_nonblock. (udp_recvfrom_nonblock): renamed from ip_recvfrom_nonblock. IPSocket#recvfrom_nonblock is moved to UDPSocket#recvfrom_nonblock. (unix_recvfrom_nonblock): removed. UNIXSocket#is removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@10305 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/socket/test_nonblock.rb59
-rw-r--r--test/socket/test_unix.rb12
2 files changed, 36 insertions, 35 deletions
diff --git a/test/socket/test_nonblock.rb b/test/socket/test_nonblock.rb
index 33123fb..07d0004 100644
--- a/test/socket/test_nonblock.rb
+++ b/test/socket/test_nonblock.rb
@@ -71,38 +71,25 @@ class TestNonblockSocket < Test::Unit::TestCase
u2.close if u2
end
- def bound_unix_socket(klass)
- tmpfile = Tempfile.new("testrubysock")
- path = tmpfile.path
- tmpfile.close(true)
- return klass.new(path), path
- end
-
- def test_unix_recvfrom_nonblock
- serv, serv_path = bound_unix_socket(UNIXServer)
- c = UNIXSocket.new(serv_path)
- s = serv.accept
- assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { s.recvfrom_nonblock(100) }
- assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { c.recvfrom_nonblock(100) }
- s.write "aaa"
- IO.select [c]
- mesg, unix_addr = c.recvfrom_nonblock(100)
+ def test_udp_recv_nonblock
+ u1 = UDPSocket.new
+ u2 = UDPSocket.new
+ u1.bind("127.0.0.1", 0)
+ assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { u1.recv_nonblock(100) }
+ assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK, Errno::EINVAL) { u2.recv_nonblock(100) }
+ u2.send("aaa", 0, u1.getsockname)
+ IO.select [u1]
+ mesg = u1.recv_nonblock(100)
assert_equal("aaa", mesg)
- assert_equal(2, unix_addr.length)
- af, path = unix_addr
- if path != "" # connection-oriented socket may not return the peer address.
- assert_equal(serv_path, path)
- end
- s.close
- IO.select [c]
- mesg, unix_addr = c.recvfrom_nonblock(100)
+ assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { u1.recv_nonblock(100) }
+ u2.send("", 0, u1.getsockname)
+ IO.select [u1]
+ mesg = u1.recv_nonblock(100)
assert_equal("", mesg)
ensure
- File.unlink serv_path if serv_path && File.socket?(serv_path)
- serv.close if serv
- c.close if c
- s.close if s && !s.closed?
- end if defined?(UNIXSocket)
+ u1.close if u1
+ u2.close if u2
+ end
def test_socket_recvfrom_nonblock
s1 = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0)
@@ -132,6 +119,20 @@ class TestNonblockSocket < Test::Unit::TestCase
serv.close if serv
end
+ def test_tcp_recv_nonblock
+ c, s = tcp_pair
+ assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { c.recv_nonblock(100) }
+ assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { s.recv_nonblock(100) }
+ c.write("abc")
+ IO.select [s]
+ assert_equal("a", s.recv_nonblock(1))
+ assert_equal("bc", s.recv_nonblock(100))
+ assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { s.recv_nonblock(100) }
+ ensure
+ c.close if c
+ s.close if s
+ end
+
def test_read_nonblock
c, s = tcp_pair
assert_raise(Errno::EAGAIN, Errno::EWOULDBLOCK) { c.read_nonblock(100) }
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index 80fc3b4..008a970 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -101,11 +101,11 @@ class TestUNIXSocket < Test::Unit::TestCase
s2.close
end
- def test_noname_recvfrom_nonblock
+ def test_noname_recv_nonblock
s1, s2 = UNIXSocket.pair
s2.write("a")
IO.select [s1]
- assert_equal(["a", ["AF_UNIX", ""]], s1.recvfrom_nonblock(10))
+ assert_equal("a", s1.recv_nonblock(10))
ensure
s1.close
s2.close
@@ -123,7 +123,7 @@ class TestUNIXSocket < Test::Unit::TestCase
def test_dgram_pair
s1, s2 = UNIXSocket.pair(Socket::SOCK_DGRAM)
- assert_raise(Errno::EAGAIN) { s1.recvfrom_nonblock(10) }
+ assert_raise(Errno::EAGAIN) { s1.recv_nonblock(10) }
s2.send("", 0)
s2.send("haha", 0)
s2.send("", 0)
@@ -132,7 +132,7 @@ class TestUNIXSocket < Test::Unit::TestCase
assert_equal("haha", s1.recv(10))
assert_equal("", s1.recv(10))
assert_equal("", s1.recv(10))
- assert_raise(Errno::EAGAIN) { s1.recvfrom_nonblock(10) }
+ assert_raise(Errno::EAGAIN) { s1.recv_nonblock(10) }
ensure
s1.close
s2.close
@@ -140,7 +140,7 @@ class TestUNIXSocket < Test::Unit::TestCase
def test_seqpacket_pair
s1, s2 = UNIXSocket.pair(Socket::SOCK_SEQPACKET)
- assert_raise(Errno::EAGAIN) { s1.recvfrom_nonblock(10) }
+ assert_raise(Errno::EAGAIN) { s1.recv_nonblock(10) }
s2.send("", 0)
s2.send("haha", 0)
s2.send("", 0)
@@ -149,7 +149,7 @@ class TestUNIXSocket < Test::Unit::TestCase
assert_equal("haha", s1.recv(10))
assert_equal("", s1.recv(10))
assert_equal("", s1.recv(10))
- assert_raise(Errno::EAGAIN) { s1.recvfrom_nonblock(10) }
+ assert_raise(Errno::EAGAIN) { s1.recv_nonblock(10) }
rescue Errno::EPROTONOSUPPORT
ensure
s1.close if s1