lib/rubot/rubot.rb
# Read and handle all open sockets until they all disconnect.
Read and handle all open sockets until they all disconnect.
Read and handle all open sockets until they all disconnect .
def select_loop
		while @connections.size > 0
			sockets = @connections.map { |c| c.socket }
			want_idle = @connections.any? { |c| c.want_network_idle? }
			timeout = want_idle ? 1 * SECOND : nil
			rd, wr, err = IO::select(sockets, nil, sockets, timeout)
			if rd && rd.size > 0
				readables = @connections.select { |c| rd.include? c.socket }
				readables.each { |c| c.readlines }
			end
			if err && err.size > 0
				errored = @connections.select { |c| err.include?(c.socket) }
				errored.each do |c|
					puts "rubot.rb: IO::select(): error on #{c.host}, dropping connection"
				end
				@connections = @connections.select { |c| !err.include?(c.socket) }
			end
			@connections = @connections.select { |c| c.connected? }
			@connections.each { |c| c.emit_idle } if want_idle && rd.nil? && err.nil?
		end
		log "No connections left, quitting."
	end
def select_loop while @connections . size > 0 sockets = @connections . map { | c | c . socket } want_idle = @connections . any? { | c | c . want_network_idle? } timeout = want_idle ? 1 * SECOND : nil rd , wr , err = IO :: select ( sockets , nil , sockets , timeout ) if rd && rd . size > 0 readables = @connections . select { | c | rd . include? c . socket } readables . each { | c | c . readlines } end if err && err . size > 0 errored = @connections . select { | c | err . include? ( c . socket ) } errored . each do | c | puts "rubot.rb: IO::select(): error on #{c.host}, dropping connection" end @connections = @connections . select { | c | ! err . include? ( c . socket ) } end @connections = @connections . select { | c | c . connected? } @connections . each { | c | c . emit_idle } if want_idle && rd . nil? && err . nil? end log "No connections left, quitting." end
Read and handle all open sockets until they all disconnect.
Read and handle all open sockets until they all disconnect .