1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/socket/test_unix.rb

31 lines
665 B
Ruby
Raw Normal View History

begin
require "socket"
require "test/unit"
rescue LoadError
end
class TestUNIXSocket < Test::Unit::TestCase
def test_fd_passing
r1, w = IO.pipe
s1, s2 = UNIXSocket.pair
begin
s1.send_io(nil)
rescue NotImplementedError
assert_raise(NotImplementedError) { s2.recv_io }
rescue TypeError
s1.send_io(r1)
r2 = s2.recv_io
assert_equal(r1.stat.ino, r2.stat.ino)
assert_not_equal(r1.fileno, r2.fileno)
w.syswrite "a"
assert_equal("a", r2.sysread(10))
ensure
s1.close
s2.close
w.close
r1.close
r2.close if r2 && !r2.closed?
end
end
end if defined?(UNIXSocket)