@@ -677,7 +677,19 @@ def self.fd_set_from_array(array)
677
677
678
678
def self . collect_set_fds ( array , fd_set )
679
679
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
681
693
end
682
694
683
695
def self . timer_add ( time1 , time2 , result )
@@ -742,14 +754,14 @@ def self.select(readables, writables, errorables, timeout)
742
754
743
755
time_limit , future = make_timeval_timeout ( timeout )
744
756
# 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
753
765
loop do
754
766
if FFI . call_failed? ( events = FFI ::Platform ::POSIX . select ( max_fd + 1 ,
755
767
read_set ? read_set . to_set : nil ,
@@ -765,12 +777,11 @@ def self.select(readables, writables, errorables, timeout)
765
777
766
778
Errno . handle ( "select(2) failed" )
767
779
end
780
+
781
+ break
768
782
end
769
783
770
784
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.
774
785
775
786
output_fds = [ ]
776
787
output_fds << collect_set_fds ( readables , read_set )
0 commit comments