Skip to content

Commit

Permalink
fix #collect_set_fds; kind of works now
Browse files Browse the repository at this point in the history
  • Loading branch information
chuckremes committed Oct 1, 2015
1 parent 9581c69 commit acd40bd
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions kernel/common/io.rb
Expand Up @@ -677,7 +677,19 @@ def self.fd_set_from_array(array)

def self.collect_set_fds(array, fd_set)
return [] unless fd_set
array.select { |io| fd_set.set?(io.descriptor) || io.descriptor < 0 }
array.map do |io|
key, io = if io.is_a?(Array)
[io[0], io[1]]
else
[io, io]
end

if fd_set.set?(io.descriptor) || io.descriptor < 0
key
else
nil
end
end.compact
end

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

time_limit, future = make_timeval_timeout(timeout)
# debugging only...
File.open("/tmp/select", 'w+') { |file|
set = read_set.to_set
file.puts set.class
file.puts set.inspect
file.puts set.address
#file.puts(set.read_array_of_char(128))
}

# file = File.open("/tmp/select", 'w+')
# set = read_set.to_set
# file.puts set.class
# file.puts set.inspect
# file.puts(sprintf("0x%x", set.address))
# set.read_array_of_char(10).each { |char| file.puts(sprintf("%b ", char)) }

events = 0
loop do
if FFI.call_failed?(events = FFI::Platform::POSIX.select(max_fd + 1,
read_set ? read_set.to_set : nil,
Expand All @@ -765,12 +777,11 @@ def self.select(readables, writables, errorables, timeout)

Errno.handle("select(2) failed")
end

break
end

return nil if events.zero?

# this will blow up because read/write/error_set were all reset to fd_sets instead
# of being an FDSet instance. Fix after debugging why #select is SEGVing.

output_fds = []
output_fds << collect_set_fds(readables, read_set)
Expand Down

0 comments on commit acd40bd

Please sign in to comment.