Issue #11778 has been updated by jeremyevans0 (Jeremy Evans).


I don't think this is a bug.  If you pass a non-nil mode argument to `recv_io`, you should ensure that `klass.for_fd` accepts the mode argument.  The example works correctly if you don't pass a mode argument to `recv_io`.  I have submitted a pull request that updates the tests so that UnixSocket is used as the klass in recv_io without a mode argument, showing it works correctly: https://github.com/ruby/ruby/pull/3566

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

* Author: normalperson (Eric Wong)
* Status: Open
* Priority: Normal
* 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/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>