// get prunes stale connections and returns a connection from the idle list or
// creates a new connection.
483929
func (p *Pool) get(ctx context.Context) (*poolConn, error) {

	// Handle limit for p.Wait == true.
	var waited time.Duration
	if p.Wait && p.MaxActive > 0 {
		p.lazyInit()

		// wait indicates if we believe it will block so its not 100% accurate
		// however for stats it should be good enough.
		wait := len(p.ch) == 0
		var start time.Time
		if wait {
			start = time.Now()
		}
		if ctx == nil {
			<-p.ch
		} else {
			select {
			case <-p.ch:
			case <-ctx.Done():
				return nil, ctx.Err()
			}
		}
		if wait {
			waited = time.Since(start)
		}
	}

	p.mu.Lock()

	if waited > 0 {
		p.waitCount++
		p.waitDuration += waited
	}

	// Prune stale connections at the back of the idle list.
	if p.IdleTimeout > 0 {
		n := p.idle.count
		for i := 0; i < n && p.idle.back != nil && p.idle.back.t.Add(p.IdleTimeout).Before(nowFunc()); i++ {
			pc := p.idle.back
			p.idle.popBack()
			p.mu.Unlock()
			pc.c.Close()
			p.mu.Lock()
			p.active--
		}
	}

	// Get idle connection from the front of idle list.
	for p.idle.front != nil {
		pc := p.idle.front
		p.idle.popFront()
		p.mu.Unlock()
		if (p.TestOnBorrow == nil || p.TestOnBorrow(pc.c, pc.t) == nil) &&
			(p.MaxConnLifetime == 0 || nowFunc().Sub(pc.created) < p.MaxConnLifetime) {
			return pc, nil
		}
		pc.c.Close()
		p.mu.Lock()
		p.active--
	}

	// Check for pool closed before dialing a new connection.
	if p.closed {
		p.mu.Unlock()
		return nil, errors.New("redigo: get on closed pool")
	}

	// Handle limit for p.Wait == false.
	if !p.Wait && p.MaxActive > 0 && p.active >= p.MaxActive {
		p.mu.Unlock()
		return nil, ErrPoolExhausted
	}

	p.active++
	p.mu.Unlock()
	c, err := p.dial(ctx)
	if err != nil {
		c = nil
		p.mu.Lock()
		p.active--
		if p.ch != nil && !p.closed {
			p.ch <- struct{}{}
		}
		p.mu.Unlock()
	}
	return &poolConn{c: c, created: nowFunc()}, err
}
266743
func (client *Client) GetConnection() (Connection, error) {
	request := newOpClientRequest(opClientRequestConnection, nil)
	client.opRequests <- request
	response := <-request.response
	switch response.(type) {
	case error:
		return nil, response.(error)
	case Connection:
		return response.(Connection), nil
	}
	panic("unreachable")
}
1276899
func (i *Interfaces) Get(index int) (iface *Interface, _ error) {
	if index < 0 || index >= len(i.objects) {
		return nil, errors.New("index out of bounds")
	}
	return &Interface{i.objects[index]}, nil
}
1077387
func (p *Pool) Get(ctx context.Context) (conn *Disque, err error) {
	var r pools.Resource
	if r, err = p.pool.Get(ctx); err == nil && r != nil {
		conn = r.(*Disque)
	}
	return conn, err
}
1470
func (s *Server) GetConnection(connID string) Connection {
	conn, ok := s.getConnection(connID)
	if !ok {
		return nil
	}

	return conn
}
1343181
func (e *delayedEnvironment) Get(key string) (string, bool) {
	e.Load()
	return e.env.Get(key)
}
330641
func (fhc *FakeHealthCheck) GetConnection(key string) queryservice.QueryService {
	fhc.mu.RLock()
	defer fhc.mu.RUnlock()
	if item := fhc.items[key]; item != nil {
		return item.conn
	}
	return nil
}
574531
func (f FakeGetter) Get(api.ListOptions) (*api.ReplicationController, error) {
	return f.RC, f.Err
}
674136
func (t *Transport) getConn(cm *connectMethod) (*persistConn, error) {
	if pc := t.getIdleConn(cm); pc != nil {
		return pc, nil
	}

	conn, raddr, ip, err := t.dial("tcp", cm.addr())
	if err != nil {
		if cm.proxyURL != nil {
			err = fmt.Errorf("http: error connecting to proxy %s: %v", cm.proxyURL, err)
		}
		return nil, err
	}

	pa := cm.proxyAuth()

	pconn := &persistConn{
		t:        t,
		cacheKey: cm.String(),
		conn:     conn,
		reqch:    make(chan requestAndChan, 50),
		host:     raddr,
		ip:       ip,
	}

	switch {
	case cm.proxyURL == nil:
		// Do nothing.
	case cm.targetScheme == "http":
		pconn.isProxy = true
		if pa != "" {
			pconn.mutateHeaderFunc = func(h http.Header) {
				h.Set("Proxy-Authorization", pa)
			}
		}
	case cm.targetScheme == "https":
		connectReq := &http.Request{
			Method: "CONNECT",
			URL:    &url.URL{Opaque: cm.targetAddr},
			Host:   cm.targetAddr,
			Header: make(http.Header),
		}
		if pa != "" {
			connectReq.Header.Set("Proxy-Authorization", pa)
		}
		connectReq.Write(conn)

		// Read response.
		// Okay to use and discard buffered reader here, because
		// TLS server will not speak until spoken to.
		br := bufio.NewReader(conn)
		resp, err := http.ReadResponse(br, connectReq)
		if err != nil {
			conn.Close()
			return nil, err
		}
		if resp.StatusCode != 200 {
			f := strings.SplitN(resp.Status, " ", 2)
			conn.Close()
			return nil, errors.New(f[1])
		}
	}

	if cm.targetScheme == "https" {
		// Initiate TLS and check remote host name against certificate.
		conn = tls.Client(conn, t.TLSClientConfig)
		if err = conn.(*tls.Conn).Handshake(); err != nil {
			return nil, err
		}
		if t.TLSClientConfig == nil || !t.TLSClientConfig.InsecureSkipVerify {
			if err = conn.(*tls.Conn).VerifyHostname(cm.tlsHost()); err != nil {
				return nil, err
			}
		}
		pconn.conn = conn
	}

	pconn.br = bufio.NewReader(pconn.conn)
	pconn.bw = bufio.NewWriter(pconn.conn)
	go pconn.readLoop()
	return pconn, nil
}
1053571
func (l *Lock) get(ctx context.Context) (*LockRecord, error) {
	// Pooling
	l.backend.permitPool.Acquire()
	defer l.backend.permitPool.Release()

	// Read
	row, err := l.backend.client.Single().ReadRow(ctx, l.backend.haTable, spanner.Key{l.key}, []string{"Key", "Value", "Timestamp", "Identity"})
	if spanner.ErrCode(err) == codes.NotFound {
		return nil, nil
	}
	if err != nil {
		return nil, errwrap.Wrapf(fmt.Sprintf("failed to read value for %q: {{err}}", l.key), err)
	}

	var r LockRecord
	if err := row.ToStruct(&r); err != nil {
		return nil, errwrap.Wrapf("failed to decode lock: {{err}}", err)
	}
	return &r, nil
}
603031
func (s *Server) GetConnections() []Connection {
	// first call of Range to get the total length, we don't want to use append or manually grow the list here for many reasons.
	length := s.GetTotalConnections()
	conns := make([]Connection, length, length)
	i := 0
	// second call of Range.
	s.connections.Range(func(k, v interface{}) bool {
		conn, ok := v.(*connection)
		if !ok {
			// if for some reason (should never happen), the value is not stored as *connection
			// then stop the iteration and don't continue insertion of the result connections
			// in order to avoid any issues while end-dev will try to iterate a nil entry.
			return false
		}
		conns[i] = conn
		i++
		return true
	})

	return conns
}
463865
func Get() (Interface, error) {
	v, err := value.Get()
	if err != nil {
		return nil, err
	}
	return v.(Interface), nil
}
93824
func (d *logDrain) getConnection(forceNew bool) (net.Conn, error) {
	// If we have a connection, it's not old, and we're not focing a new one...
	if d.conn != nil && !forceNew {
		// then return the existing connection
		return d.conn, nil
	}
	// If ANY of those conditions weren't met, it's time for a new connection.
	// If we have an existing one, close it and nil it out, too for good measure.
	if d.conn != nil {
		if err := d.conn.Close(); err != nil {
			log.Println("drain: Error closing connection.  Drain may be leaking connections.", err)
		}
		d.conn = nil
	}
	// Try a few times...
	var err error
	for attempt := 1; attempt <= maxFailedConns; attempt++ {
		d.conn, err = net.DialTimeout(d.proto, d.uri, dialTimeout)
		if err == nil {
			// We got our connection...
			// Make it good for only so long.  See comment above on connRefreshInterval.
			err = d.conn.SetWriteDeadline(time.Now().Add(connRefreshInterval))
			if err != nil {
				return nil, err
			}
			// Break out of the loop and return
			return d.conn, nil
		}
	}
	// Multiple attempts to dial have failed.  Whatever the problem is, we shouldn't expect that
	// it will resolve itself quickly.
	log.Printf("drain: Experienced %d consecutive failed connection attempts; muting drain for %s.", maxFailedConns, mutePeriod)
	// Immediately "mute" the drain.  This will prevent us from wasting resources repeatedly dialing
	// and failing while the message queue gets backed up.  This will give the network a break and
	// allow us to empty the queue.
	d.muted = true
	// Unmute the drain when the mute interval has elapsed
	go func() {
		time.Sleep(mutePeriod)
		d.muted = false
	}()
	// Return the error from the last failed connection attempt
	return nil, err
}
1362474
func (cp *ConnectionPool) Get(ctx context.Context) (*PooledDBConnection, error) {
	p := cp.pool()
	if p == nil {
		return nil, ErrConnPoolClosed
	}
	r, err := p.Get(ctx)
	if err != nil {
		return nil, err
	}

	// Check that the RemoteAddr is still a valid Address
	if cp.resolutionFrequency > 0 &&
		cp.hostIsNotIP &&
		!cp.validAddress(net.ParseIP(r.(*PooledDBConnection).RemoteAddr().String())) {
		err := r.(*PooledDBConnection).Reconnect()
		if err != nil {
			p.Put(r)
			return nil, err
		}
	}
	return r.(*PooledDBConnection), nil
}
453439
func Get(dest interface{}, q *gocql.Query) error {
	return Iter(q).Get(dest)
}
1242263
func (obj *Doc) GetConnections(ctx context.Context) ([]*Connection, error) {
	result := &struct {
		Connections []*Connection	`json:"qConnections"`
	} {}
	err := obj.rpc(ctx, "GetConnections", result)
	return result.Connections, err 
}
253303
func (c *client) get(rawurl string, out interface{}) error {
	return c.do(rawurl, "GET", nil, out)
}