         # File lib/eventmachine.rb, line 681
    681:   def EventMachine::connect server, port=nil, handler=nil, *args
    682:     begin
    683:       port = Integer(port)
    684:     rescue ArgumentError, TypeError
    685:       # there was no port, so server must be a unix domain socket
    686:       # the port argument is actually the handler, and the handler is one of the args
    687:       args.unshift handler if handler
    688:       handler = port
    689:       port = nil
    690:     end if port
    691:
    692:     klass = if (handler and handler.is_a?(Class))
    693:       raise ArgumentError, 'must provide module or subclass of EventMachine::Connection' unless Connection > handler
    694:       handler
    695:     else
    696:       Class.new( Connection ) {handler and include handler}
    697:     end
    698:
    699:     arity = klass.instance_method(:initialize).arity
    700:     expected = arity >= 0 ? arity : -(arity + 1)
    701:     if (arity >= 0 and args.size != expected) or (arity < 0 and args.size < expected)
    702:       raise ArgumentError, "wrong number of arguments for #{klass}#initialize (#{args.size} for #{expected})"
    703:     end
    704:
    705:     s = if port
    706:           connect_server server, port
    707:         else
    708:           connect_unix_server server
    709:         end
    710:
    711:     c = klass.new s, *args
    712:     @conns[s] = c
    713:     block_given? and yield c
    714:     c
    715:   end