class Necro::Reactor
Attributes
monitored_fds[RW]
Public Class Methods
new()
click to toggle source
# File lib/necro/reactor.rb, line 4 def initialize @monitored_fds = [] end
Public Instance Methods
add_to_monitor(fd)
click to toggle source
# File lib/necro/reactor.rb, line 8 def add_to_monitor(fd) @monitored_fds << fd end
handle_read_event(ready_read_fds)
click to toggle source
# File lib/necro/reactor.rb, line 30 def handle_read_event(ready_read_fds) ready_fds = ready_read_fds.flatten.compact ready_fds.each {|ready_fd| process_read(ready_fd) } end
process_read(ready_fd)
click to toggle source
# File lib/necro/reactor.rb, line 35 def process_read(ready_fd) command_worker = Necro::COMMANDER.get_worker_from_fd(ready_fd) begin data = read_data(ready_fd) command_worker.receive_data(data) rescue Necro::Errors::ProcessTerminated command_worker.unbind() end end
read_data(ready_fd)
click to toggle source
# File lib/necro/reactor.rb, line 45 def read_data(ready_fd) sock_data = [] begin while(t_data = ready_fd.read_nonblock(64)) sock_data << t_data end rescue Errno::EAGAIN return sock_data.join rescue Errno::EWOULDBLOCK return sock_data.join rescue raise Necro::Errors::ProcessTerminated.new(ready_fd,sock_data.join) end end
remove_from_monitoring(fd)
click to toggle source
# File lib/necro/reactor.rb, line 12 def remove_from_monitoring(fd) @monitored_fds.delete(fd) end
start()
click to toggle source
# File lib/necro/reactor.rb, line 16 def start loop do watch_on_pipe end end
watch_on_pipe()
click to toggle source
# File lib/necro/reactor.rb, line 22 def watch_on_pipe ready_read_fds,ready_write_fds,read_error_fds = select(monitored_fds,[],[],0.05) if ready_read_fds && !ready_read_fds.empty? handle_read_event(ready_read_fds) end end