// pathConnectionRead reads out the connection configuration
428321
func (b *backend) pathConnectionRead(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
	entry, err := req.Storage.Get(ctx, "config/connection")
	if err != nil {
		return nil, fmt.Errorf("failed to read connection configuration")
	}
	if entry == nil {
		return nil, nil
	}

	var config connectionConfig
	if err := entry.DecodeJSON(&config); err != nil {
		return nil, err
	}

	return &logical.Response{
		Data: map[string]interface{}{
			"max_open_connections": config.MaxOpenConnections,
		},
	}, nil
}
692953
func (cp *connProducer) NewConnection() (*grpc.ClientConn, string, error) {
	cp.Lock()
	defer cp.Unlock()

	for endpoint, timeout := range cp.disabledEndpoints {
		if time.Since(timeout) >= EndpointDisableInterval {
			delete(cp.disabledEndpoints, endpoint)
		}
	}

	endpoints := shuffle(cp.endpoints)
	checkedEndpoints := make([]string, 0)
	for _, endpoint := range endpoints {
		if _, ok := cp.disabledEndpoints[endpoint]; !ok {
			checkedEndpoints = append(checkedEndpoints, endpoint)
			conn, err := cp.connect(endpoint)
			if err != nil {
				logger.Error("Failed connecting to", endpoint, ", error:", err)
				continue
			}
			return conn, endpoint, nil
		}
	}
	return nil, "", fmt.Errorf("Could not connect to any of the endpoints: %v", checkedEndpoints)
}
1162785
func ReadConnectionID(r io.Reader, len int) (ConnectionID, error) {
	if len == 0 {
		return nil, nil
	}
	c := make(ConnectionID, len)
	_, err := io.ReadFull(r, c)
	if err == io.ErrUnexpectedEOF {
		return nil, io.EOF
	}
	return c, err
}
95465
func (p *Pool) GetConnection(t time.Time) (conn *Connection, err error) {
	series := p.seriesFromTime(t)
	path := p.pathFromSeries(series)
	if _, err = os.Stat(path); os.IsNotExist(err) {
		err = ErrUnknownDB
		return
	} else if err != nil {
		return
	}
	c, err := p.pool.Get(path)
	if err != nil {
		return nil, err
	}
	return &Connection{
		Connection: c,
		pool:       p,
		series:     series,
	}, nil
}
1367266
func ReadConfig(path string) (c Config, err error) {
	f, err := os.Open(path)
	if err != nil {
		return c, err
	}
	defer f.Close()

	c, err = readConfig(f)
	c.applyDefaults()
	return
}
802529
func (gitter *Gitter) newStreamConnection(wait time.Duration, retries int) *streamConnection {
	return &streamConnection{
		closed:  true,
		wait:    wait,
		retries: retries,
	}
}
329106
func (n *NotifyRouter) HandleFSPathUpdated(path string) {
	if n == nil {
		return
	}
	// For all connections we currently have open...
	n.cm.ApplyAll(func(id ConnectionID, xp rpc.Transporter) bool {
		// If the connection wants the `Kbfs` notification type
		if n.getNotificationChannels(id).Kbfs {
			// In the background do...
			go func() {
				// A send of a `FSPathUpdated` RPC with the notification
				(keybase1.NotifyFSClient{
					Cli: rpc.NewClient(xp, NewContextifiedErrorUnwrapper(n.G()), nil),
				}).FSPathUpdated(context.Background(), path)
			}()
		}
		return true
	})

	n.runListeners(func(listener NotifyListener) {
		listener.FSPathUpdated(path)
	})
}
160303
func (i *IdentityStore) pathEntityNameRead() framework.OperationFunc {
	return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
		entityName := d.Get("name").(string)
		if entityName == "" {
			return logical.ErrorResponse("missing entity name"), nil
		}

		entity, err := i.MemDBEntityByName(ctx, entityName, false)
		if err != nil {
			return nil, err
		}
		if entity == nil {
			return nil, nil
		}

		return i.handleEntityReadCommon(ctx, entity)
	}
}
1348521
func getConnection() (conn redis.Conn, err error) {
	if currClient == nil {
		return nil, errors.New("No current Redis client: create a new client before getting a connection from it")
	}

	conn = currClient.Pool.Get()
	return conn, nil
}
1311934
func UserConnectOption(user *url.Userinfo) ConnectOption {
	return func(opts *ConnectOptions) {
		opts.User = user
	}
}
558594
func LoadConnectionTable(r io.Reader) (t ConnectionTable, err error) {
	if err = binary.Read(r, binary.LittleEndian, &t.Row); err != nil {
		return
	}
	if err = binary.Read(r, binary.LittleEndian, &t.Col); err != nil {
		return
	}
	t.Vec = make([]int16, t.Row*t.Col)
	for i := range t.Vec {
		if err = binary.Read(r, binary.LittleEndian, &t.Vec[i]); err != nil {
			return
		}
	}
	return
}
242510
func OnlyConnect(a agent.Agent, apiOpen api.OpenFunc) (api.Connection, error) {
	agentConfig := a.CurrentConfig()
	info, ok := agentConfig.APIInfo()
	if !ok {
		return nil, errors.New("API info not available")
	}
	conn, _, err := connectFallback(apiOpen, info, agentConfig.OldPassword())
	if err != nil {
		return nil, errors.Trace(err)
	}
	return conn, nil
}
360954
func Read(path string) (Config, error) {
	c, err := defaultConfig()

	if err != nil {
		return Config{}, errors.WithMessage(err, "initializing default config")
	}

	c, err = readPath(c, path)
	if err != nil {
		return Config{}, err
	}

	for _, c := range []converter{&c.API, &c.Log, &c.Timeout, &c.FeedManager, &c.Popularity} {
		c.Convert()
	}

	return c, nil

}
693281
func (driver *Driver) GetConnection(dsn, basePath string) (client.Connection, error) {

	dsnVal, err := ParseDSN(dsn)
	if err != nil {
		return nil, err
	}

	conn, event, err := zklib.Connect(dsnVal.Servers,
		dsnVal.SessionTimeout,
		zklib.WithConnectTimeout(dsnVal.ConnectTimeout),
		zklib.WithReconnectDelay(dsnVal.ReconnectStartDelay),
		zklib.WithPerHostConnectDelay(dsnVal.PerHostConnectDelay),
		zklib.WithBackoff(&client.Backoff{
			InitialDelay: dsnVal.ReconnectStartDelay,
			MaxDelay:     dsnVal.ReconnectMaxDelay,
		}))
	if err != nil {
		return nil, err
	}

	// wait for session event
	connected := false
	for !connected {
		select {
		case e := <-event:
			if e.State == zklib.StateHasSession {
				connected = true
				plog.WithField("event", e).Debug("zk connection has session")
			} else {
				plog.WithField("event", e).Debug("waiting for zk connection to have session")
			}
		}
	}
	go func() {
		for {
			select {
			case e, ok := <-event:
				if !ok {
					plog.WithField("event", e).Debug("zk event channel closed")
					return
				} else {
					plog.WithField("event", e).Debug("zk state change event received")
				}
			}
		}
	}()
	return &Connection{
		basePath: basePath,
		conn:     conn,
	}, nil
}
588664
func (fc *FuzzedConnection) SetReadDeadline(t time.Time) error {
	return fc.conn.SetReadDeadline(t)
}
782018
func (b *Broker) muCloseDeadConnection(conn *connection) {
	b.mu.Lock()
	defer b.mu.Unlock()

	for nid, c := range b.conns {
		if c == conn {
			b.conf.Logger.Debug("closing dead connection",
				"nodeID", nid)
			delete(b.conns, nid)
			_ = c.Close()
			if err := b.refreshMetadata(); err != nil {
				b.conf.Logger.Debug("cannot refresh metadata",
					"error", err)
			}
			return
		}
	}
}
643077
func (zclient *zclient) GetConnection(path string) (client.Connection, error) {
	zclient.connectionsLock.Lock()
	defer zclient.connectionsLock.Unlock()
	if _, ok := zclient.connections[path]; !ok {
		zclient.connections[path] = newzconn(zclient.client, path)
	}
	zconn := zclient.connections[path]
	return zconn.connect(DefaultConnectionTimeout)
}