Issue #11778 has been updated by Koichi Sasada.

Description updated

----------------------------------------
Bug #11778: recv_io with mode breaks when klass arg is kind of BasicSocket
https://bugs.ruby-lang.org/issues/11778#change-55270

* Author: Eric Wong
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: 
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
Following test show the failure in the second recv_io call.
I was writing additional tests for FD passing when I noticed this.

I'm not sure if BasicSocket.for_fd should do with the mode flag if
we change its arity...

~~~
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -37,6 +37,28 @@ def test_fd_passing
     end
   end
 
+  def test_fd_passing_class_mode
+    UNIXSocket.pair do |s1, s2|
+      s1.send_io(s1.fileno)
+      r = s2.recv_io(nil)
+      assert_kind_of Integer, r, 'recv_io with klass=nil returns integer FD'
+      assert_not_equal s1.fileno, r
+      r = IO.for_fd(r)
+      assert_equal s1.stat.ino, r.stat.ino
+      r.close
+
+      s1.send_io(s1)
+      klass = UNIXSocket
+      # OK with File or IO, fails with any BasicSocket subclass since
+      # BasicSocket.for_fd only takes one arg
+      # klass = File
+      r = s2.recv_io(klass, 'r+')
+      assert_instance_of klass, r, 'recv_io with proper klass'
+      assert_not_equal s1.fileno, r.fileno
+      r.close
+    end
+  end
+
   def test_fd_passing_n
     io_ary = []
     return if !defined?(Socket::SCM_RIGHTS)
~~~




-- 
https://bugs.ruby-lang.org/