2005-06-03 22:40:40 -04:00
|
|
|
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
|
2005-07-02 09:45:08 -04:00
|
|
|
s1.send_io(nil)
|
2005-06-03 22:40:40 -04:00
|
|
|
rescue NotImplementedError
|
|
|
|
assert_raise(NotImplementedError) { s2.recv_io }
|
2005-07-02 09:45:08 -04:00
|
|
|
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?
|
2005-06-03 22:40:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end if defined?(UNIXSocket)
|