summaryrefslogtreecommitdiff
path: root/test/socket/test_unix.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/socket/test_unix.rb')
-rw-r--r--test/socket/test_unix.rb68
1 files changed, 65 insertions, 3 deletions
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index e206339db0..3e7d85befc 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -152,7 +152,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
lock = Thread::Mutex.new
nr = 0
x = 2
- y = 1000
+ y = 400
begin
s1.send_io(nil)
rescue NotImplementedError
@@ -420,9 +420,10 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
s1.recv_nonblock(10)
fail
rescue => e
- assert(IO::EAGAINWaitReadable === e)
- assert(IO::WaitReadable === e)
+ assert_kind_of(IO::EWOULDBLOCKWaitReadable, e)
+ assert_kind_of(IO::WaitReadable, e)
end
+
s2.send("", 0)
s2.send("haha", 0)
s2.send("", 0)
@@ -446,6 +447,67 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
s2.close if s2
end
+ def test_stream_pair
+ s1, s2 = UNIXSocket.pair(Socket::SOCK_STREAM)
+ begin
+ s1.recv_nonblock(10)
+ fail
+ rescue => e
+ assert_kind_of(IO::EWOULDBLOCKWaitReadable, e)
+ assert_kind_of(IO::WaitReadable, e)
+ end
+
+ s2.send("", 0)
+ s2.send("haha", 0)
+ assert_equal("haha", s1.recv(10))
+ assert_raise(IO::EWOULDBLOCKWaitReadable) { s1.recv_nonblock(10) }
+
+ buf = "".dup
+ s2.send("BBBBBB", 0)
+ IO.select([s1])
+ rv = s1.recv(100, 0, buf)
+ assert_equal buf.object_id, rv.object_id
+ assert_equal "BBBBBB", rv
+
+ s2.close
+ assert_nil(s1.recv(10))
+ rescue Errno::EPROTOTYPE => error
+ omit error.message
+ ensure
+ s1.close if s1
+ s2.close if s2
+ end
+
+ def test_seqpacket_pair
+ s1, s2 = UNIXSocket.pair(Socket::SOCK_SEQPACKET)
+ begin
+ s1.recv_nonblock(10)
+ fail
+ rescue => e
+ assert_kind_of(IO::EWOULDBLOCKWaitReadable, e)
+ assert_kind_of(IO::WaitReadable, e)
+ end
+
+ s2.send("haha", 0)
+ assert_equal("haha", s1.recv(10))
+ assert_raise(IO::EWOULDBLOCKWaitReadable) { s1.recv_nonblock(10) }
+
+ buf = "".dup
+ s2.send("BBBBBB", 0)
+ IO.select([s1])
+ rv = s1.recv(100, 0, buf)
+ assert_equal buf.object_id, rv.object_id
+ assert_equal "BBBBBB", rv
+
+ s2.close
+ assert_nil(s1.recv(10))
+ rescue Errno::EPROTOTYPE, Errno::EPROTONOSUPPORT => error
+ omit error.message
+ ensure
+ s1.close if s1
+ s2.close if s2
+ end
+
def test_dgram_pair_sendrecvmsg_errno_set
if /mswin|mingw/ =~ RUBY_PLATFORM
omit("AF_UNIX + SOCK_DGRAM is not supported on windows")