// ObeyIdleTimeout wraps an existing network connection with timeout-obeying
// Write() and Read() - it will drop the connection after 'timeout' on idle
//
// Example:
// ObeyIdletimeout(conn, time.Second * 60, "api server").
346704
func ObeyIdleTimeout(conn net.Conn, timeout time.Duration, ownerName string) net.Conn {
	return &TimeoutConn{
		Conn:            conn,
		TimeoutDuration: timeout,
		OwnerName:       ownerName,
	}
}
818960
func (f *Fibre) SetIdleTimeout(wait string) {
	f.itimeout, _ = time.ParseDuration(wait)
}
143209
func (s *CreateIndexService) Timeout(timeout string) *CreateIndexService {
	s.timeout = timeout
	return s
}
1166889
func doAsyncTimeout(f func() error, tmFunc func(error), timeout time.Duration) error {
	errs := make(chan error)
	go func() {
		err := f()
		select {
		case errs <- err:
		default:
			if tmFunc != nil {
				tmFunc(err)
			}
		}
	}()
	select {
	case err := <-errs:
		return err
	case <-time.After(timeout):
		return errors.New("operation timeout")
	}
}
1188177
func (p *Plugin) Timeout() time.Duration {
	p.mu.RLock()
	t := p.timeout
	p.mu.RUnlock()
	return t
}
199655
func (s *DeleteService) Timeout(timeout string) *DeleteService {
	s.timeout = timeout
	return s
}
504588
func (s *UpdateByQueryService) Timeout(timeout string) *UpdateByQueryService {
	s.timeout = timeout
	return s
}
1294698
func (s *IndexService) Timeout(timeout string) *IndexService {
	s.timeout = timeout
	return s
}
187434
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
	// Since Linode only updates their zone files every X minutes, we need
	// to figure out how many minutes we have to wait until we hit the next
	// interval of X.  We then wait another couple of minutes, just to be
	// safe.  Hopefully at some point during all of this, the record will
	// have propagated throughout Linode's network.
	minsRemaining := dnsUpdateFreqMins - (time.Now().Minute() % dnsUpdateFreqMins)

	timeout = (time.Duration(minsRemaining) * time.Minute) +
		(minTTL * time.Second) +
		(dnsUpdateFudgeSecs * time.Second)
	interval = d.config.PollingInterval
	return
}
523603
func (gr *GoReq) Timeout(timeout time.Duration) *GoReq {
	gr.Transport.Dial = func(network, addr string) (net.Conn, error) {
		conn, err := net.DialTimeout(network, addr, timeout)
		if err != nil {
			gr.Errors = append(gr.Errors, err)
			return nil, err
		}
		conn.SetDeadline(time.Now().Add(timeout))
		return conn, nil
	}
	return gr
}
1034188
func (p *ConnPool) DialTimeout(dc string, addr net.Addr, timeout time.Duration, useTLS bool) (net.Conn, HalfCloser, error) {
	p.once.Do(p.init)

	// Try to dial the conn
	d := &net.Dialer{LocalAddr: p.SrcAddr, Timeout: timeout}
	conn, err := d.Dial("tcp", addr.String())
	if err != nil {
		return nil, nil, err
	}

	// Cast to TCPConn
	var hc HalfCloser
	if tcp, ok := conn.(*net.TCPConn); ok {
		tcp.SetKeepAlive(true)
		tcp.SetNoDelay(true)
		hc = tcp
	}

	// Check if TLS is enabled
	if (useTLS || p.ForceTLS) && p.TLSWrapper != nil {
		// Switch the connection into TLS mode
		if _, err := conn.Write([]byte{byte(RPCTLS)}); err != nil {
			conn.Close()
			return nil, nil, err
		}

		// Wrap the connection in a TLS client
		tlsConn, err := p.TLSWrapper(dc, conn)
		if err != nil {
			conn.Close()
			return nil, nil, err
		}
		conn = tlsConn
	}

	return conn, hc, nil
}
136921
func (c *challengeHTTP) Timeout() (timeout, interval time.Duration) {
	return 60 * time.Second, 5 * time.Second
}
1285069
func (s *BulkService) Timeout(timeout string) *BulkService {
	s.timeout = timeout
	return s
}
198931
func (s *ReindexService) Timeout(timeout string) *ReindexService {
	s.timeout = timeout
	return s
}
614789
func (s *ClusterRerouteService) Timeout(timeout string) *ClusterRerouteService {
	s.timeout = timeout
	return s
}
539422
func ConnectWait(t time.Duration) Option {
	return func(o *Options) error {
		o.ConnectTimeout = t
		return nil
	}
}
115733
func (eng *Engine) CloseTimeout(err error, timeout time.Duration) {
	_ = eng.Inject(func() { CloseError(eng.Connection(), err) })
	select {
	case <-eng.running:
	case <-time.After(timeout):
		eng.Disconnect(err)
	}
}