class Invoker::Reactor::Reader
Attributes
read_array[RW]
Public Class Methods
new()
click to toggle source
# File lib/invoker/reactor/reader.rb, line 5 def initialize @read_array = [] end
Public Instance Methods
handle_read_event(read_ready_fds)
click to toggle source
# File lib/invoker/reactor/reader.rb, line 13 def handle_read_event(read_ready_fds) ready_fds = read_ready_fds.flatten.compact ready_fds.each { |ready_fd| process_read(ready_fd) } end
watch_for_read(socket)
click to toggle source
# File lib/invoker/reactor/reader.rb, line 9 def watch_for_read(socket) @read_array << socket end
Private Instance Methods
process_read(ready_fd)
click to toggle source
# File lib/invoker/reactor/reader.rb, line 20 def process_read(ready_fd) command_worker = Invoker.commander.get_worker_from_fd(ready_fd) return unless command_worker begin data = read_data(ready_fd) command_worker.receive_data(data) rescue Invoker::Errors::ProcessTerminated remove_from_read_monitoring(command_worker.pipe_end, command_worker) end end
read_data(ready_fd)
click to toggle source
# File lib/invoker/reactor/reader.rb, line 39 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 Invoker::Errors::ProcessTerminated.new(ready_fd,sock_data.join) end end
remove_from_read_monitoring(fd, command_worker)
click to toggle source
# File lib/invoker/reactor/reader.rb, line 31 def remove_from_read_monitoring(fd, command_worker) read_array.delete(fd) command_worker.unbind rescue StandardError => error Invoker::Logger.puts(error.message) Invoker::Logger.puts(error.backtrace) end