Godeps/_workspace/src/gopkg.in/mgo.v2/server.go
func (server *mongoServer) Connect(timeout time.Duration) (*mongoSocket, error) {
	server.RLock()
	master := server.info.Master
	dial := server.dial
	server.RUnlock()

	logf("Establishing new connection to %s (timeout=%s)...", server.Addr, timeout)
	var conn net.Conn
	var err error
	switch {
	case !dial.isSet():
		// Cannot do this because it lacks timeout support. :-(
		//conn, err = net.DialTCP("tcp", nil, server.tcpaddr)
		conn, err = net.DialTimeout("tcp", server.ResolvedAddr, timeout)
	case dial.old != nil:
		conn, err = dial.old(server.tcpaddr)
	case dial.new != nil:
		conn, err = dial.new(&ServerAddr{server.Addr, server.tcpaddr})
	default:
		panic("dialer is set, but both dial.old and dial.new are nil")
	}
	if err != nil {
		logf("Connection to %s failed: %v", server.Addr, err.Error())
		return nil, err
	}
	logf("Connection to %s established.", server.Addr)

	stats.conn(+1, master)
	return newSocket(server, conn, timeout), nil
}
func (server *mongoServer) Connect(timeout time.Duration) (*mongoSocket, error) {
	server.RLock()
	master := server.info.Master
	dial := server.dial
	server.RUnlock()

	logf("Establishing new connection to %s (timeout=%s)...", server.Addr, timeout)
	var conn net.Conn
	var err error
	switch {
	case !dial.isSet():
		// Cannot do this because it lacks timeout support. :-(
		//conn, err = net.DialTCP("tcp", nil, server.tcpaddr)
		conn, err = net.DialTimeout("tcp", server.ResolvedAddr, timeout)
	case dial.old != nil:
		conn, err = dial.old(server.tcpaddr)
	case dial.new != nil:
		conn, err = dial.new(&ServerAddr{server.Addr, server.tcpaddr})
	default:
		panic("dialer is set, but both dial.old and dial.new are nil")
	}
	if err != nil {
		logf("Connection to %s failed: %v", server.Addr, err.Error())
		return nil, err
	}
	logf("Connection to %s established.", server.Addr)

	stats.conn(+1, master)
	return newSocket(server, conn, timeout), nil
}
func ( server * mongoServer ) Connect ( timeout time . Duration ) ( * mongoSocket , error ) { server . RLock ( ) master := server . info . Master dial := server . dial server . RUnlock ( ) logf ( " " , server . Addr , timeout ) var conn net . Conn var err error switch { case ! dial . isSet ( ) : // Cannot do this because it lacks timeout support. :-( //conn, err = net.DialTCP("tcp", nil, server.tcpaddr) conn , err = net . DialTimeout ( " " , server . ResolvedAddr , timeout ) case dial . old != nil : conn , err = dial . old ( server . tcpaddr ) case dial . new != nil : conn , err = dial . new ( & ServerAddr { server . Addr , server . tcpaddr } ) default : panic ( " " ) } if err != nil { logf ( " " , server . Addr , err . Error ( ) ) return nil , err } logf ( " " , server . Addr ) stats . conn ( + 1 , master ) return newSocket ( server , conn , timeout ) , nil }
// Connect establishes a new connection to the server. This should
// generally be done through server.AcquireSocket().
Connect establishes a new connection to the server . This should generally be done through server . AcquireSocket () .