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

* ext/socket/ancdata.c (ancillary_rights): new method.

(make_io_for_rights): new function to allocate
  IOs for FDs in SCM_RIGHTS message.
  (bsock_recvmsg_internal): use make_io_for_rights.  So the FDs can be
  closed by GC.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22426 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2009-02-18 18:43:15 +00:00
parent 2485ed5177
commit 18afbc891c
3 changed files with 73 additions and 10 deletions

View file

@ -53,7 +53,7 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
recv_io_ary = []
ctls.each {|ctl|
next if ctl.level != Socket::SOL_SOCKET || ctl.type != Socket::SCM_RIGHTS
recv_io_ary.concat ctl.data.unpack("i!*").map {|fd| IO.new(fd) }
recv_io_ary.concat ctl.rights
}
assert_equal(send_io_ary.length, recv_io_ary.length)
send_io_ary.length.times {|i|
@ -126,13 +126,14 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
assert_instance_of(Addrinfo, srcaddr)
assert_instance_of(Array, ctls)
assert_equal(1, ctls.length)
assert_instance_of(Socket::AncillaryData, ctls[0])
assert_equal(Socket::SOL_SOCKET, ctls[0].level)
assert_equal(Socket::SCM_RIGHTS, ctls[0].type)
assert_instance_of(String, ctls[0].data)
fd, rest = ctls[0].data.unpack("i!a*")
assert_equal("", rest)
r2 = IO.new(fd)
ctl = ctls[0]
assert_instance_of(Socket::AncillaryData, ctl)
assert_equal(Socket::SOL_SOCKET, ctl.level)
assert_equal(Socket::SCM_RIGHTS, ctl.type)
assert_instance_of(String, ctl.data)
ios = ctl.rights
assert_equal(1, ios.length)
r2 = ios[0]
begin
assert(File.identical?(r1, r2))
ensure