def EventMachine::attach_io io, watch_mode, handler=nil, *args
klass = klass_from_handler(Connection, handler, *args)
if !watch_mode and klass.public_instance_methods.any?{|m| [:notify_readable, :notify_writable].include? m.to_sym }
raise ArgumentError, "notify_readable/writable with EM.attach is not supported. Use EM.watch(io){ |c| c.notify_readable = true }"
end
if io.respond_to?(:fileno)
fd = defined?(JRuby) ? JRuby.runtime.getDescriptorByFileno(io.fileno).getChannel : io.fileno
else
fd = io
end
s = attach_fd fd, watch_mode
c = klass.new s, *args
c.instance_variable_set(:@io, io)
c.instance_variable_set(:@watch_mode, watch_mode)
c.instance_variable_set(:@fd, fd)
@conns[s] = c
block_given? and yield c
c
end