Project

General

Profile

Actions

Bug #11778

closed

recv_io with mode breaks when klass arg is kind of BasicSocket

Added by normalperson (Eric Wong) over 8 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:71860]
Tags:

Description

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)

Updated by ko1 (Koichi Sasada) over 8 years ago

  • Description updated (diff)

Updated by jeremyevans0 (Jeremy Evans) over 3 years ago

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

Actions #3

Updated by jeremyevans (Jeremy Evans) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|ed27c2514c2f4140546dce2e8f5f64cb91712c47.


Update UnixSocket#recv_io tests to handle receiving a UnixSocket

Receiving UnixSocket works fine if you don't provide a mode, and
I think it is reasonable to expect that you should not provide
a mode if klass.for_fd would not accept a mode.

Fixes [Bug #11778]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0