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