// Connect is invoked by the broker to connect to a capability
169254
func (pe *providerEndpoint) Connect(args *ConnectRequest, resp *ConnectResponse) error {
	defer metrics.IncrCounter([]string{"scada", "connect", args.Capability}, 1)
	pe.p.logger.Printf("[INFO] scada-client: connect requested (capability: %s)",
		args.Capability)

	// Handle potential flash
	if args.Severity != "" && args.Message != "" {
		pe.p.logger.Printf("[%s] scada-client: %s", args.Severity, args.Message)
	}

	// Look for the handler
	handler := pe.p.config.Handlers[args.Capability]
	if handler == nil {
		pe.p.logger.Printf("[WARN] scada-client: requested capability '%s' not available",
			args.Capability)
		return fmt.Errorf("invalid capability")
	}

	// Hijack the connection
	pe.setHijack(func(a io.ReadWriteCloser) {
		if err := handler(args.Capability, args.Meta, a); err != nil {
			pe.p.logger.Printf("[ERR] scada-client: '%s' handler error: %v",
				args.Capability, err)
		}
	})
	resp.Success = true
	return nil
}
548760
func (s *Server) Connect(path string, h HandlerFunc, opts ...HandlerOption) {
	s.register(http.MethodConnect, path, h, opts...)
}
371981
func (l *Adaptor) Connect() (err error) {
	ws, e := l.connect(l.Port())
	if e != nil {
		return e
	}

	l.ws = ws
	return
}
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
}
872379
func (b *ClientAdaptor) Connect() (err error) {
	bleMutex.Lock()
	defer bleMutex.Unlock()

	b.device, err = getBLEDevice(b.DeviceName)
	if err != nil {
		return errors.Wrap(err, "can't connect to device "+b.DeviceName)
	}

	var cln blelib.Client

	cln, err = blelib.Connect(context.Background(), filter(b.Address()))
	if err != nil {
		return errors.Wrap(err, "can't connect to peripheral "+b.Address())
	}

	b.addr = cln.Addr()
	b.address = cln.Addr().String()
	b.SetName(cln.Name())
	b.client = cln

	p, err := b.client.DiscoverProfile(true)
	if err != nil {
		return errors.Wrap(err, "can't discover profile")
	}

	b.profile = p
	b.connected = true
	return
}
1129436
func (f *Adaptor) Connect() (err error) {
	if f.conn == nil {
		sp, e := f.PortOpener(f.Port())
		if e != nil {
			return e
		}
		f.conn = sp
	}
	if err = f.Board.Connect(f.conn); err != nil {
		return err
	}

	f.Board.On("SysexResponse", func(data interface{}) {
		f.Publish("SysexResponse", data)
	})

	return
}
664340
func (s *service) Connect(ctx context.Context, r *taskAPI.ConnectRequest) (*taskAPI.ConnectResponse, error) {
	var pid int
	if s.container != nil {
		pid = s.container.Pid()
	}
	return &taskAPI.ConnectResponse{
		ShimPid: uint32(os.Getpid()),
		TaskPid: uint32(pid),
	}, nil
}
318794
func Connect(protoAddr string) (net.Conn, error) {
	proto, address := ProtocolAndAddress(protoAddr)
	conn, err := net.Dial(proto, address)
	return conn, err
}
398629
func (stanOpts *StanOptions) Connect() (*Stan, error) {
	if len(stanOpts.ClientId) == 0 {
		panic("Must set client id in StanOptions")
	}
	if len(stanOpts.ClusterId) == 0 {
		panic("Must set cluster id in StanOptions")
	}

	con, err := stanOpts.Options.Connect()
	if err != nil {
		return nil, fmt.Errorf("Failed to connect to underlying nats: %s", err)
	}

	stanCon, err := stan.Connect(stanOpts.ClusterId, stanOpts.ClientId, stan.NatsConn(con))
	if err != nil {
		return nil, fmt.Errorf("Failed to get stan con: %s", err)
	}

	return &Stan{Con: stanCon, Opts: stanOpts}, nil
}
763871
func (p *Producer) Connect(addr string) (err error) {
	return p.ConnectConfig(addr, nsq.NewConfig())
}
287382
func (w *Writer) connect() (err error) {
	if w.conn != nil {
		// ignore err from close, it makes sense to continue anyway
		w.conn.close()
		w.conn = nil
	}

	var c net.Conn
	c, err = net.Dial(w.network, w.raddr)
	if err == nil {
		w.conn = &netConn{conn: c}
		if w.hostname == "" {
			w.hostname = c.LocalAddr().String()
		}
	}
	return
}
67742
func (w *builtinWriter) connect() (err error) {
	if w.conn != nil {
		// ignore err from close, it makes sense to continue anyway
		w.conn.close()
		w.conn = nil
	}

	if w.network == "" {
		w.conn, err = unixSyslog()
		if w.hostname == "" {
			w.hostname = "localhost"
		}
	} else {
		var c net.Conn
		c, err = net.DialTimeout(w.network, w.raddr, remoteDeadline)
		if err == nil {
			w.conn = &netConn{conn: c}
			if w.hostname == "" {
				w.hostname = c.LocalAddr().String()
			}
		}
	}
	return
}
783922
func Connect(token string) (*Logger, error) {
	logger := Logger{
		token: token,
	}

	if err := logger.openConnection(); err != nil {
		return nil, err
	}

	return &logger, nil
}
914363
func (f *PeerEventsFilter) Connect() *PeerEventsFilter {
	f.eventType = simulations.EventTypeConn
	b := true
	f.connUp = &b
	return f
}
586901
func (c *Client) Connect() (client.Session, error) {
	if c.conn == nil {
		if err := c.initConnection(); err != nil {
			return nil, err
		}
	}
	return &Session{c.conn, c.ch}, nil
}
623408
func (c *Conn) Connect() error {
	// Make sure the existing connection is closed
	if c.NetConn != nil {
		c.NetConn.Close()
	}

	conn, err := net.Dial("tcp", c.gateway)
	if err != nil {
		return err
	}

	tlsConn := tls.Client(conn, c.Conf)
	err = tlsConn.Handshake()
	if err != nil {
		return err
	}

	c.NetConn = tlsConn
	return nil
}
819944
func Connect(config ConnConfig) (c *Conn, err error) {
	return connect(config, minimalConnInfo)
}