// UnixListenerTimeoutReadWrite sets the read and write timeout for connections
// from external signing processes.
501323
func UnixListenerTimeoutReadWrite(timeout time.Duration) UnixListenerOption {
	return func(ul *unixListener) { ul.timeoutReadWrite = timeout }
}
448593
func (c *Client) readListener() {
	for {
		select {
		case <-c.done:
			// Delete our connection
			c.hub.Unregister(c)

			// Tell writer to stop
			c.done <- true

			//exit processing loop
			return
		default:
			// Read from websocket
			var msg Message
			err := websocket.JSON.Receive(c.ws, &msg)

			switch {
			case err == io.EOF:
				// website connection closed
				c.done <- true
				return
			case err != nil:
				// Error, abort!
				c.done <- true
				return
			default:
				if msg.Event == "close" {
					c.done <- true
					return
				}
			}
		}
	}
}
969862
func (s *IndicesOpenService) Timeout(timeout string) *IndicesOpenService {
	s.timeout = timeout
	return s
}
361477
func (s *CloseIndexService) Timeout(timeout string) *CloseIndexService {
	s.timeout = timeout
	return s
}
506930
func UnixConnection(socket string, timeout time.Duration) Option {
	return func(d *Database) error {
		if socket == "" {
			socket = defaultSocket
		}
		d.address = socket
		d.network = "unix"
		if timeout < 0 {
			return errors.New(ErrInvalidConfiguration, errorMessages, "timeout", timeout)
		} else if timeout == 0 {
			timeout = defaultTimeout
		}
		d.timeout = timeout
		return nil
	}
}
1029547
func (w *Writer) Write(b []byte) (int, error) {
	if len(b) == 0 {
		return 0, nil
	}

	var h = w.handler
	var e = eventPool.Get().(*events.Event)
	var s = *(*string)(unsafe.Pointer(&reflect.StringHeader{
		Data: uintptr(unsafe.Pointer(&b[0])),
		Len:  len(b),
	}))
	var t time.Time
	var src string

	if h == nil {
		h = events.DefaultHandler
	}

	w.mutex.Lock()
	flags, prefix := w.flags, w.prefix

	if strings.HasPrefix(s, prefix) {
		s = s[len(prefix):]
	}

	if format := timeFormat(flags); len(format) != 0 {
		var tz *time.Location
		var ts string

		if n := len(format); len(s) >= n {
			ts, s = s[:n], s[n:]
		} else {
			ts, s = s, ""
		}

		if (flags & LUTC) != 0 {
			tz = time.UTC
		} else {
			tz = time.Local
		}

		t, _ = time.ParseInLocation(format, ts, tz)
	}

	if (flags & (Llongfile | Lshortfile)) != 0 {
		var base string
		var file string
		var line string

		s = skip(s, ' ')
		base = s
		file, s = parse(s, ':') // parse the file name or path
		line, s = parse(s, ':') // parse the line number

		src = base[:len(file)+len(line)+1]
	}

	s = skip(s, ' ')

	if n := strings.IndexByte(s, '\n'); n >= 0 {
		s = s[:n]
	}

	if t == (time.Time{}) {
		t = time.Now()
	}

	e.Message = s
	e.Source = src
	e.Time = t

	h.HandleEvent(e)
	w.mutex.Unlock()

	e.Message = ""
	e.Source = ""
	e.Time = time.Time{}
	eventPool.Put(e)

	return len(b), nil
}
445768
func (c ConnWithTimeouts) Write(b []byte) (int, error) {
	if c.writeTimeout == 0 {
		return c.Conn.Write(b)
	}
	if err := c.Conn.SetWriteDeadline(time.Now().Add(c.writeTimeout)); err != nil {
		return 0, err
	}
	return c.Conn.Write(b)
}
1257672
func (tw *timeoutWriter) Write(p []byte) (int, error) {
	if tw.err != nil {
		return 0, tw.err
	}

	var n int
	tw.conn.SetWriteDeadline(time.Now().Add(tw.timeout))
	n, tw.err = tw.conn.Write(p)
	tw.conn.SetWriteDeadline(time.Time{})
	return n, tw.err
}
376911
func (ctn *Connection) Write(buf []byte) (total int, err error) {
	// make sure all bytes are written
	// Don't worry about the loop, timeout has been set elsewhere
	length := len(buf)
	for total < length {
		var r int
		if err = ctn.updateDeadline(); err != nil {
			break
		}
		r, err = ctn.conn.Write(buf[total:])
		total += r
		if err != nil {
			break
		}
	}

	// If all bytes are written, ignore any potential error
	// The error will bubble up on the next network io if it matters.
	if total == len(buf) {
		return total, nil
	}

	if ctn.node != nil {
		atomic.AddInt64(&ctn.node.stats.ConnectionsFailed, 1)
	}

	ctn.Close()

	return total, errToTimeoutErr(ctn, err)
}
521227
func (s *NodesStatsService) Timeout(timeout string) *NodesStatsService {
	s.timeout = timeout
	return s
}
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
		}
	}
}
245162
func (o *ClientOptions) SetWriteTimeout(t time.Duration) *ClientOptions {
	o.WriteTimeout = t
	return o
}
1661
func WriteFileFromReader(ctx context.Context, bs blobserver.StatReceiver, filename string, r io.Reader) (blob.Ref, error) {
	return WriteFileFromReaderWithModTime(ctx, bs, filename, time.Time{}, r)
}
895721
func (s *OpenIndexService) Timeout(timeout string) *OpenIndexService {
	s.timeout = timeout
	return s
}
482114
func (lp *lookupPeer) Write(data []byte) (int, error) {
	lp.conn.SetWriteDeadline(time.Now().Add(time.Second))
	return lp.conn.Write(data)
}
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
	}
}
1158849
func (ri *ReindexRemoteInfo) ConnectTimeout(timeout string) *ReindexRemoteInfo {
	ri.connectTimeout = timeout
	return ri
}