// ReadTimeout acts as Read but takes a timeout. If that timeout is reached, it's assumed
// there's no proxy protocol header.
8281
func ReadTimeout(reader *bufio.Reader, timeout time.Duration) (*Header, error) {
	type header struct {
		h *Header
		e error
	}
	read := make(chan *header, 1)

	go func() {
		h := &header{}
		h.h, h.e = Read(reader)
		read <- h
	}()

	timer := time.NewTimer(timeout)
	select {
	case result := <-read:
		timer.Stop()
		return result.h, result.e
	case <-timer.C:
		return nil, ErrNoProxyProtocol
	}
}
880735
func (r *SubReply) Timeout() bool {
	if r.Err == nil {
		return false
	}
	t, ok := r.Err.(*net.OpError)
	return ok && t.Timeout()
}
193465
func (s *XPackWatcherPutWatchService) MasterTimeout(masterTimeout string) *XPackWatcherPutWatchService {
	s.masterTimeout = masterTimeout
	return s
}
1325493
func WithReadTimeout(timeout string) ClientOptionFunc {
	return func(c *Client) error {
		if timeout == "" {
			c.readTimeout = DefaultTimeout
			return nil
		}

		t, err := time.ParseDuration(timeout)
		if err != nil {
			return client.InvalidTimeoutError{Timeout: timeout}
		}
		c.readTimeout = t
		return nil
	}
}
198931
func (s *ReindexService) Timeout(timeout string) *ReindexService {
	s.timeout = timeout
	return s
}
1123798
func (r *SearchRequest) Timeout(timeout string) *SearchRequest {
	r.searchSource = r.searchSource.Timeout(timeout)
	return r
}
270253
func (r *Request) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *Request {
	r.setting.ConnectTimeout = connectTimeout
	r.setting.ReadWriteTimeout = readWriteTimeout
	return r
}
1073586
func (_m *Client) GetTimeout() *time.Duration {
	ret := _m.Called()

	var r0 *time.Duration
	if rf, ok := ret.Get(0).(func() *time.Duration); ok {
		r0 = rf()
	} else {
		if ret.Get(0) != nil {
			r0 = ret.Get(0).(*time.Duration)
		}
	}

	return r0
}
1090256
func (e *OpError) Timeout() bool {
	if ne, ok := e.Err.(*os.SyscallError); ok {
		t, ok := ne.Err.(timeout)
		return ok && t.Timeout()
	}
	t, ok := e.Err.(timeout)
	return ok && t.Timeout()
}
790376
func WithHTTPTimeout(timeout time.Duration) Option {
	return func(c *Client) {
		c.timeout = timeout
	}
}
718817
func (s *SnapshotDeleteRepositoryService) Timeout(timeout string) *SnapshotDeleteRepositoryService {
	s.timeout = timeout
	return s
}
681065
func (s *SnapshotVerifyRepositoryService) Timeout(timeout string) *SnapshotVerifyRepositoryService {
	s.timeout = timeout
	return s
}
778559
func (d *DNSProvider) Timeout() (timeout, interval time.Duration) {
	return d.config.PropagationTimeout, d.config.PollingInterval
}
614789
func (s *ClusterRerouteService) Timeout(timeout string) *ClusterRerouteService {
	s.timeout = timeout
	return s
}
392787
func (c *Client) SetTimeout(timeout time.Duration) *Client {
	c.httpClient.Timeout = timeout
	return c
}
962200
func (s *clientIOSession) ReadTimeout(timeout time.Duration) (interface{}, error) {
	for {
		doRead, msg, err := s.doPreRead()
		if err != nil {
			return nil, err
		}
		if !doRead {
			return msg, nil
		}

		var complete bool
		for {
			if s.in.Readable() > 0 {
				complete, msg, err = s.svr.opts.decoder.Decode(s.in)

				if !complete && err == nil {
					complete, msg, err = s.readFromConn(timeout)
				}
			} else {
				complete, msg, err = s.readFromConn(timeout)
			}

			if nil != err {
				s.in.Clear()
				return nil, err
			}

			if complete {
				break
			}
		}

		if s.in.Readable() == 0 {
			s.in.Clear()
		}

		returnRead, readedMsg, err := s.doPostRead(msg)
		if err != nil {
			return nil, err
		}

		if returnRead {
			return readedMsg, err
		}
	}
}
1308820
func (r *NBReader) readWithTimeout(buffer bytes.Buffer, timeout time.Duration) (int, error) {
	select {
	case data, ok := <-r.dataChan:
		r.buffer.Write(data)
		if !ok {
			return len(data), io.EOF
		}
		return len(data), nil
	case <-time.After(timeout):
		return 0, errTimeout
	}
}