// Main connect function. Will connect to the nats-server
435885
func (nc *Conn) connect() error {
	var returnedErr error

	// Create actual socket connection
	// For first connect we walk all servers in the pool and try
	// to connect immediately.
	nc.mu.Lock()
	nc.initc = true
	// The pool may change inside the loop iteration due to INFO protocol.
	for i := 0; i < len(nc.srvPool); i++ {
		nc.current = nc.srvPool[i]

		if err := nc.createConn(); err == nil {
			// This was moved out of processConnectInit() because
			// that function is now invoked from doReconnect() too.
			nc.setup()

			err = nc.processConnectInit()

			if err == nil {
				nc.srvPool[i].didConnect = true
				nc.srvPool[i].reconnects = 0
				returnedErr = nil
				break
			} else {
				returnedErr = err
				nc.mu.Unlock()
				nc.close(DISCONNECTED, false)
				nc.mu.Lock()
				nc.current = nil
			}
		} else {
			// Cancel out default connection refused, will trigger the
			// No servers error conditional
			if strings.Contains(err.Error(), "connection refused") {
				returnedErr = nil
			}
		}
	}
	nc.initc = false
	if returnedErr == nil && nc.status != CONNECTED {
		returnedErr = ErrNoServers
	}
	nc.mu.Unlock()
	return returnedErr
}
1365836
func (c *Client) Connect() error {
	if c.maxConnAttempts == 1 {
		return c.connect()
	}
	return c.connectWithRetry(c.maxConnAttempts, c.timeBetweenConnAttempts)
}
288591
func (c *UDPClient) Connect() error {
	c.t.Go(func() error {
		return c.runRequestQueue()
	})
	udp, err := net.DialTimeout("udp", c.addr, c.timeout)
	if err != nil {
		return err
	}
	c.conn = udp
	return nil
}
307909
func Connect() (*mgo.Session, *mgo.Database, string) {
	uri := os.Getenv("MONGODB_URL")

	if uri == "" {
		uri = "mongodb://localhost:27017/notifications_testing"
	}

	const SSL_STRING = "ssl=true"
	useSsl := false

	if strings.Contains(uri, SSL_STRING) {
		if strings.Contains(uri, SSL_STRING+"&") {
			uri = strings.Replace(uri, SSL_STRING+"&", "", 1)
		} else {
			uri = strings.Replace(uri, SSL_STRING, "", 1)
		}
		useSsl = true
	}

	dialInfo, err := mgo.ParseURL(uri)
	if err != nil {
		panic(err)
	}

	dialInfo.Timeout = 10 * time.Second

	if useSsl {
		config := tls.Config{}
		config.InsecureSkipVerify = true

		dialInfo.DialServer = func(addr *mgo.ServerAddr) (net.Conn, error) {
			return tls.Dial("tcp", addr.String(), &config)
		}
	}

	// get a mgo session
	session, err := mgo.DialWithInfo(dialInfo)
	sess := session.Clone()

	return session, sess.DB(dialInfo.Database), dialInfo.Database
}
75443
func (m *MockConnector) Nats() *go_nats.Conn {
	ret := m.ctrl.Call(m, "Nats")
	ret0, _ := ret[0].(*go_nats.Conn)
	return ret0
}
879602
func (c *DefaultClient) Connect() error {
	_, err := c.connect(false)
	return err
}
914363
func (f *PeerEventsFilter) Connect() *PeerEventsFilter {
	f.eventType = simulations.EventTypeConn
	b := true
	f.connUp = &b
	return f
}
821713
func (c *Consumer) Connect(addrs ...string) error {
	for _, q := range c.handlers {
		for _, addr := range addrs {
			if err := q.ConnectToNSQD(addr); err != nil {
				return err
			}
		}
	}
	return nil
}
845913
func (c *client) connect() (byte, bool) {
	DEBUG.Println(NET, "connect started")

	ca, err := packets.ReadPacket(c.conn)
	if err != nil {
		ERROR.Println(NET, "connect got error", err)
		return packets.ErrNetworkError, false
	}
	if ca == nil {
		ERROR.Println(NET, "received nil packet")
		return packets.ErrNetworkError, false
	}

	msg, ok := ca.(*packets.ConnackPacket)
	if !ok {
		ERROR.Println(NET, "received msg that was not CONNACK")
		return packets.ErrNetworkError, false
	}

	DEBUG.Println(NET, "received connack")
	return msg.ReturnCode, msg.SessionPresent
}
359068
func (nmgr *natManager) NAT() *inat.NAT {
	nmgr.natmu.Lock()
	defer nmgr.natmu.Unlock()
	return nmgr.nat
}
570364
func (_m *DBClient) Connect() error {
	ret := _m.Called()

	var r0 error
	if rf, ok := ret.Get(0).(func() error); ok {
		r0 = rf()
	} else {
		r0 = ret.Error(0)
	}

	return r0
}
1370045
func main() {
	// Init DB and plan to close it at the end of the programme
	dbconn.Connect()
	defer dbconn.DB.Close()

	// Set GIN in production mode if run in production
	if !config.GDevEnv {
		gin.SetMode(gin.ReleaseMode)
	}

	// Init router
	router := gin.Default()
	router.Use(cors.New(apitool.DefaultCORSConfig()))

	// Init statics
	if !config.GUnitTestingEnv {
		router.LoadHTMLGlob("component/oauth2/rest/statics/templates/*")
		router.Static("authentication/styles", "component/oauth2/rest/statics/styles")
	}

	// Oauth2 components
	oauth2Component := oauth2.New(rest.New(initOAuthServer(), service.New(repo.New())))
	oauth2Component.AttachPublicAPI(router.Group("/authentication"))
	oauth2Component.AttachPrivateAPI(router.Group("/api/private-v1/authentication"))

	// Start router
	go log.Println("Service oauth2 started: Navigate to " + config.GAppUrl)
	router.Run(":" + config.GPort)
}
632700
func Connect(addr string) (*Client, error) {
	conn, err := net.Dial("tcp", addr)
	if err != nil {
		return nil, err
	}

	return NewClient(conn), nil
}
763871
func (p *Producer) Connect(addr string) (err error) {
	return p.ConnectConfig(addr, nsq.NewConfig())
}
879131
func (c *Client) Connect() (client.Session, error) {
	if c.mgoSession == nil {
		if err := c.initConnection(); err != nil {
			return nil, err
		}
	}
	return c.session(), nil
}
585426
func (c *Client) Connect() error {
	dialer := new(net.Dialer)
	rawConn, err := dialer.Dial("tcp", fmt.Sprintf("%s:%d", c.settings.Hostname, c.settings.Port))
	if err != nil {
		return err
	}

	err = enableKeepAlive(rawConn, 10*time.Second, 2, 5*time.Second)
	if err != nil {
		return err
	}

	c.conn = tls.Client(rawConn, &tls.Config{
		ServerName:         c.settings.Hostname,
		InsecureSkipVerify: true, // x509: cannot verify signature: algorithm unimplemented
	})

	if c.settings.Logger != nil {
		c.settings.Logger.Printf("connected to %s:%d\n", c.settings.Hostname, c.settings.Port)
	}

	// perform login
	resp, err := c.rpc("daemon.login", rencode.NewList(c.settings.Login, c.settings.Password), rencode.Dictionary{})
	if err != nil {
		return err
	}
	if resp.IsError() {
		return resp.RPCError
	}

	// get class of logged-in user
	err = resp.returnValue.Scan(&c.classID)
	if err != nil {
		return err
	}

	if c.settings.Logger != nil {
		c.settings.Logger.Println("login successful as user", c.settings.Login)
	}

	return nil
}
1269446
func (self *FSock) Connect() error {
	if self.stopReadEvents != nil {
		close(self.stopReadEvents) // we have read events already processing, request stop
	}
	// Reinit readEvents channels so we avoid concurrency issues between goroutines
	self.stopReadEvents = make(chan struct{})
	self.errReadEvents = make(chan error)
	return self.connect()

}