58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/lightio/module/io.rb', line 58
def select(read_fds, write_fds=nil, _except_fds=nil, timeout=nil)
timer = timeout && Time.now
read_fds ||= []
write_fds ||= []
loop do
read_fds.each {|fd| LightIO::Module::IO.get_io_watcher(fd).tap {|io| io.readable?; io.clear_status}}
write_fds.each {|fd| LightIO::Module::IO.get_io_watcher(fd).tap {|io| io.writable?; io.clear_status}}
LightIO.sleep 0
r_fds = read_fds.select {|fd|
io = LightIO::Module::IO.convert_to_io(fd)
io.closed? ? raise(IOError, 'closed stream') : LightIO::Module::IO.get_io_watcher(io).readable?
}
w_fds = write_fds.select {|fd|
io = LightIO::Module::IO.convert_to_io(fd)
io.closed? ? raise(IOError, 'closed stream') : LightIO::Module::IO.get_io_watcher(io).writable?
}
e_fds = []
if r_fds.empty? && w_fds.empty?
if timeout && Time.now - timer > timeout
return nil
end
else
return [r_fds, w_fds, e_fds]
end
end
end
|