Skip to content

Commit acd40bd

Browse files
committed
fix #collect_set_fds; kind of works now
1 parent 9581c69 commit acd40bd

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

kernel/common/io.rb

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,19 @@ def self.fd_set_from_array(array)
677677

678678
def self.collect_set_fds(array, fd_set)
679679
return [] unless fd_set
680-
array.select { |io| fd_set.set?(io.descriptor) || io.descriptor < 0 }
680+
array.map do |io|
681+
key, io = if io.is_a?(Array)
682+
[io[0], io[1]]
683+
else
684+
[io, io]
685+
end
686+
687+
if fd_set.set?(io.descriptor) || io.descriptor < 0
688+
key
689+
else
690+
nil
691+
end
692+
end.compact
681693
end
682694

683695
def self.timer_add(time1, time2, result)
@@ -742,14 +754,14 @@ def self.select(readables, writables, errorables, timeout)
742754

743755
time_limit, future = make_timeval_timeout(timeout)
744756
# debugging only...
745-
File.open("/tmp/select", 'w+') { |file|
746-
set = read_set.to_set
747-
file.puts set.class
748-
file.puts set.inspect
749-
file.puts set.address
750-
#file.puts(set.read_array_of_char(128))
751-
}
752-
757+
# file = File.open("/tmp/select", 'w+')
758+
# set = read_set.to_set
759+
# file.puts set.class
760+
# file.puts set.inspect
761+
# file.puts(sprintf("0x%x", set.address))
762+
# set.read_array_of_char(10).each { |char| file.puts(sprintf("%b ", char)) }
763+
764+
events = 0
753765
loop do
754766
if FFI.call_failed?(events = FFI::Platform::POSIX.select(max_fd + 1,
755767
read_set ? read_set.to_set : nil,
@@ -765,12 +777,11 @@ def self.select(readables, writables, errorables, timeout)
765777

766778
Errno.handle("select(2) failed")
767779
end
780+
781+
break
768782
end
769783

770784
return nil if events.zero?
771-
772-
# this will blow up because read/write/error_set were all reset to fd_sets instead
773-
# of being an FDSet instance. Fix after debugging why #select is SEGVing.
774785

775786
output_fds = []
776787
output_fds << collect_set_fds(readables, read_set)

0 commit comments

Comments
 (0)