// Connect connects the endpoint to its peer. Specifying a NIC is optional.
327282
func (e *endpoint) Connect(addr tcpip.FullAddress) *tcpip.Error {
	if addr.Port == 0 {
		// We don't support connecting to port zero.
		return tcpip.ErrInvalidEndpointState
	}

	e.mu.Lock()
	defer e.mu.Unlock()

	nicid := addr.NIC
	var localPort uint16
	switch e.state {
	case stateInitial:
	case stateBound, stateConnected:
		localPort = e.id.LocalPort
		if e.bindNICID == 0 {
			break
		}

		if nicid != 0 && nicid != e.bindNICID {
			return tcpip.ErrInvalidEndpointState
		}

		nicid = e.bindNICID
	default:
		return tcpip.ErrInvalidEndpointState
	}

	r, nicid, netProto, err := e.connectRoute(nicid, addr)
	if err != nil {
		return err
	}
	defer r.Release()

	id := stack.TransportEndpointID{
		LocalAddress:  r.LocalAddress,
		LocalPort:     localPort,
		RemotePort:    addr.Port,
		RemoteAddress: r.RemoteAddress,
	}

	// Even if we're connected, this endpoint can still be used to send
	// packets on a different network protocol, so we register both even if
	// v6only is set to false and this is an ipv6 endpoint.
	netProtos := []tcpip.NetworkProtocolNumber{netProto}
	if netProto == header.IPv6ProtocolNumber && !e.v6only {
		netProtos = []tcpip.NetworkProtocolNumber{
			header.IPv4ProtocolNumber,
			header.IPv6ProtocolNumber,
		}
	}

	id, err = e.registerWithStack(nicid, netProtos, id)
	if err != nil {
		return err
	}

	// Remove the old registration.
	if e.id.LocalPort != 0 {
		e.stack.UnregisterTransportEndpoint(e.regNICID, e.effectiveNetProtos, ProtocolNumber, e.id, e)
	}

	e.id = id
	e.route = r.Clone()
	e.dstPort = addr.Port
	e.regNICID = nicid
	e.effectiveNetProtos = netProtos

	e.state = stateConnected

	e.rcvMu.Lock()
	e.rcvReady = true
	e.rcvMu.Unlock()

	return nil
}
649262
func Connect(address string, dialOptions []grpc.DialOption) (*grpc.ClientConn, error) {
	u, err := url.Parse(address)
	if err == nil && (!u.IsAbs() || u.Scheme == "unix") {
		dialOptions = append(dialOptions,
			grpc.WithDialer(
				func(addr string, timeout time.Duration) (net.Conn, error) {
					return net.DialTimeout("unix", u.Path, timeout)
				}))
	}

	dialOptions = append(dialOptions, grpc.WithBackoffMaxDelay(time.Second))
	conn, err := grpc.Dial(address, dialOptions...)
	if err != nil {
		return nil, err
	}

	// We wait for 1 minute until conn.GetState() is READY.
	// The interval for this check is 1 second.
	if err := util.WaitFor(1*time.Minute, 10*time.Millisecond, func() (bool, error) {
		if conn.GetState() == connectivity.Ready {
			return false, nil
		}
		return true, nil
	}); err != nil {
		return nil, fmt.Errorf("Connection timed out")
	}

	return conn, nil
}
838629
func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) {
	return nil, errdefs.ErrNotImplemented
}
456898
func (m *Adaptor) Connect() (err error) {
	if sp, e := m.connect(m.Port()); e != nil {
		return e
	} else {
		m.sp = sp
	}
	return
}
729957
func (s *Session) connect(host *HostInfo, errorHandler ConnErrorHandler) (*Conn, error) {
	return s.dial(host, s.connCfg, errorHandler)
}
812319
func (ep *endpoint) Connect(addr tcpip.FullAddress) *tcpip.Error {
	ep.mu.Lock()
	defer ep.mu.Unlock()

	if ep.closed {
		return tcpip.ErrInvalidEndpointState
	}

	// We don't support IPv6 yet.
	if len(addr.Addr) != header.IPv4AddressSize {
		return tcpip.ErrInvalidEndpointState
	}

	nic := addr.NIC
	if ep.bound {
		if ep.boundNIC == 0 {
			// If we're bound, but not to a specific NIC, the NIC
			// in addr will be used. Nothing to do here.
		} else if addr.NIC == 0 {
			// If we're bound to a specific NIC, but addr doesn't
			// specify a NIC, use the bound NIC.
			nic = ep.boundNIC
		} else if addr.NIC != ep.boundNIC {
			// We're bound and addr specifies a NIC. They must be
			// the same.
			return tcpip.ErrInvalidEndpointState
		}
	}

	// Find a route to the destination.
	route, err := ep.stack.FindRoute(nic, tcpip.Address(""), addr.Addr, ep.netProto, false)
	if err != nil {
		return err
	}
	defer route.Release()

	// Re-register the endpoint with the appropriate NIC.
	if err := ep.stack.RegisterRawTransportEndpoint(addr.NIC, ep.netProto, ep.transProto, ep); err != nil {
		return err
	}
	ep.stack.UnregisterRawTransportEndpoint(ep.registeredNIC, ep.netProto, ep.transProto, ep)

	// Save the route and NIC we've connected via.
	ep.route = route.Clone()
	ep.registeredNIC = nic
	ep.connected = true

	return nil
}
505341
func (megaPi *Adaptor) Connect() error {
	if megaPi.connection == nil {
		sp, err := serial.Open(megaPi.port, megaPi.serialMode)
		if err != nil {
			return err
		}

		// sleeping is required to give the board a chance to reset
		time.Sleep(2 * time.Second)
		megaPi.connection = sp
	}

	// kick off thread to send bytes to the board
	go func() {
		for {
			select {
			case bytes := <-megaPi.writeBytesChannel:
				megaPi.connection.Write(bytes)
				time.Sleep(10 * time.Millisecond)
			case <-megaPi.finalizeChannel:
				megaPi.finalizeChannel <- struct{}{}
				return
			default:
				time.Sleep(10 * time.Millisecond)
			}
		}
	}()
	return nil
}
1034905
func Connect(prot, dest string) (rv *Client, err error) {
	conn, err := dialFun(prot, dest)
	if err != nil {
		return nil, err
	}
	return Wrap(conn)
}
879602
func (c *DefaultClient) Connect() error {
	_, err := c.connect(false)
	return err
}
548760
func (s *Server) Connect(path string, h HandlerFunc, opts ...HandlerOption) {
	s.register(http.MethodConnect, path, h, opts...)
}
953805
func (c *Client) Connect() error {
	// An SSH client is represented with a ClientConn.
	//
	// To authenticate with the remote server you must pass at least one
	// implementation of AuthMethod via the Auth field in ClientConfig.
	var co *ssh.ClientConfig
	var err error

	if c.useAgent {
		co, err = AgentConfig(c.credentials.Username)
		if err != nil {
			return err
		}
	} else {
		co, err = KeyConfig(c.credentials.Username, c.key)
		if err != nil {
			return err
		}
	}

	client, err := ssh.Dial("tcp", net.JoinHostPort(c.addr, c.port), co)
	if err != nil {
		return err
	}

	c.client = client

	return nil
}
720967
func Connect(path string, getConnection GetConnection) <-chan client.Connection {
	connc := make(chan client.Connection, 1)
	go func() {
		if c, err := getConnection(path); err == ErrNotInitialized {
			// (remote) connection not initialized, so don't send anything
			return
		} else if err != nil {
			close(connc)
		} else {
			connc <- c
		}
	}()
	return connc
}
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
}
819944
func Connect(config ConnConfig) (c *Conn, err error) {
	return connect(config, minimalConnInfo)
}
82081
func (a *Adaptor) Connect() (err error) {
	a.client, err = a.connect()
	return
}
1165410
func (cli *Client) Connect(opts *ConnectOptions) error {
	// Lock for the connection.
	cli.muConn.Lock()

	// Unlock.
	defer cli.muConn.Unlock()

	// Return an error if the Client has already connected to the Server.
	if cli.conn != nil {
		return ErrAlreadyConnected
	}

	// Initialize the options.
	if opts == nil {
		opts = &ConnectOptions{}
	}

	// Establish a Network Connection.
	conn, err := newConnection(opts.Network, opts.Address, opts.TLSConfig)
	if err != nil {
		return err
	}

	// Set the Network Connection to the Client.
	cli.conn = conn

	// Lock for reading and updating the Session.
	cli.muSess.Lock()

	// Create a Session or reuse the current Session.
	if opts.CleanSession || cli.sess == nil {
		// Create a Session and set it to the Client.
		cli.sess = newSession(opts.CleanSession, opts.ClientID)
	} else {
		// Reuse the Session and set its Client Identifier to the options.
		opts.ClientID = cli.sess.clientID
	}

	// Unlock.
	cli.muSess.Unlock()

	// Send a CONNECT Packet to the Server.
	err = cli.sendCONNECT(&packet.CONNECTOptions{
		ClientID:     opts.ClientID,
		UserName:     opts.UserName,
		Password:     opts.Password,
		CleanSession: opts.CleanSession,
		KeepAlive:    opts.KeepAlive,
		WillTopic:    opts.WillTopic,
		WillMessage:  opts.WillMessage,
		WillQoS:      opts.WillQoS,
		WillRetain:   opts.WillRetain,
	})

	if err != nil {
		// Close the Network Connection.
		cli.conn.Close()

		// Clean the Network Connection and the Session if necessary.
		cli.clean()

		return err
	}

	// Launch a goroutine which waits for receiving the CONNACK Packet.
	cli.conn.wg.Add(1)
	go cli.waitPacket(cli.conn.connack, opts.CONNACKTimeout, ErrCONNACKTimeout)

	// Launch a goroutine which receives a Packet from the Server.
	cli.conn.wg.Add(1)
	go cli.receivePackets()

	// Launch a goroutine which sends a Packet to the Server.
	cli.conn.wg.Add(1)
	go cli.sendPackets(time.Duration(opts.KeepAlive), opts.PINGRESPTimeout)

	// Resend the unacknowledged PUBLISH and PUBREL Packets to the Server
	// if the Clean Session is false.
	if !opts.CleanSession {
		// Lock for reading and updating the Session.
		cli.muSess.Lock()

		// Unlock.
		defer cli.muSess.Unlock()

		for id, p := range cli.sess.sendingPackets {
			// Extract the MQTT Control MQTT Control Packet type.
			ptype, err := p.Type()
			if err != nil {
				return err
			}

			switch ptype {
			case packet.TypePUBLISH:
				// Set the DUP flag of the PUBLISH Packet to true.
				p.(*packet.PUBLISH).DUP = true
				// Resend the PUBLISH Packet to the Server.
				cli.conn.send <- p
			case packet.TypePUBREL:
				// Resend the PUBREL Packet to the Server.
				cli.conn.send <- p
			default:
				// Delete the Packet from the Session.
				delete(cli.sess.sendingPackets, id)
			}
		}
	}

	return nil
}
3302
func (c *TCPClient) Connect() error {
	c.t.Go(func() error {
		return c.runRequestQueue()
	})
	connection, err := net.DialTimeout("tcp", c.addr, c.timeout)
	if err != nil {
		return err
	}
	if c.tls {
		tlsConn := tls.Client(connection, c.tlsConfig)
		err = tlsConn.Handshake()
		if err != nil {
			return err
		}
		c.conn = tlsConn
	} else {
		c.conn = connection
	}
	return nil
}