// Read is a wrapper for gorilla's ReadMessage that satisfies websocketFeed.Read.
515170
func (client *socketClient) Read() (msg []byte, err error) {
	_, msg, err = client.conn.ReadMessage()
	return
}
103423
func Read(c context.Context, b []byte) (n int, err error) {
	return io.ReadFull(Get(c), b)
}
1274839
func read(conn *net.TCPConn, size int, data *bytes.Buffer) error {
	conn.SetReadDeadline(time.Now().Add(time.Second * 15))

	n, err := io.CopyN(data, conn, int64(size))
	if err != nil || n != int64(size) {
		return errors.New("read error")
	}
	return nil
}
1291311
func (c *Conn) Read(b []byte) (n int, err error) {
	if err = c.Handshake(); err != nil {
		return
	}
	if len(b) == 0 {
		// Put this after Handshake, in case people were calling
		// Read(nil) for the side effect of the Handshake.
		return
	}

	c.in.Lock()
	defer c.in.Unlock()

	// Some OpenSSL servers send empty records in order to randomize the
	// CBC IV. So this loop ignores a limited number of empty records.
	const maxConsecutiveEmptyRecords = 100
	for emptyRecordCount := 0; emptyRecordCount <= maxConsecutiveEmptyRecords; emptyRecordCount++ {
		for c.input == nil && c.in.err == nil {
			if err := c.readRecord(recordTypeApplicationData); err != nil {
				// Soft error, like EAGAIN
				return 0, err
			}
		}
		if err := c.in.err; err != nil {
			return 0, err
		}

		n, err = c.input.Read(b)
		if c.input.off >= len(c.input.data) {
			c.in.freeBlock(c.input)
			c.input = nil
		}

		// If a close-notify alert is waiting, read it so that
		// we can return (n, EOF) instead of (n, nil), to signal
		// to the HTTP response reading goroutine that the
		// connection is now closed. This eliminates a race
		// where the HTTP response reading goroutine would
		// otherwise not observe the EOF until its next read,
		// by which time a client goroutine might have already
		// tried to reuse the HTTP connection for a new
		// request.
		// See https://codereview.appspot.com/76400046
		// and https://golang.org/issue/3514
		if ri := c.rawInput; ri != nil &&
			n != 0 && err == nil &&
			c.input == nil && len(ri.data) > 0 && recordType(ri.data[0]) == recordTypeAlert {
			if recErr := c.readRecord(recordTypeApplicationData); recErr != nil {
				err = recErr // will be io.EOF on closeNotify
			}
		}

		if n != 0 || err != nil {
			return n, err
		}
	}

	return 0, io.ErrNoProgress
}
749486
func (c *Conn) Read(buf []byte) (int, error) {
	var n int
	for n < len(buf) {
		b, err := c.ReadByte()
		if err != nil {
			return n, err
		}
		//log.Printf("char: %d %q", b, b)
		buf[n] = b
		n++
		if c.r.Buffered() == 0 {
			// Try don't block if can return some data
			break
		}
	}
	return n, nil
}
1186852
func (r *Reader) Read(buffer []byte) (n int, err error) {
	if r.reader == nil {
		n = len(buffer)
	} else {
		n, err = r.reader.Read(buffer)
	}

	r.count += int64(n)
	if r.onRead != nil {
		r.onRead(r.count)
	}
	return
}
727321
func (l *tomlLexer) read() rune {
	r := l.peek()
	if r == '\n' {
		l.endbufferLine++
		l.endbufferCol = 1
	} else {
		l.endbufferCol++
	}
	l.inputIdx++
	return r
}
87121
func (r *cachingReadCloser) Read(p []byte) (n int, err error) {
	n, err = r.R.Read(p)
	r.buf.Write(p[:n])
	if err == io.EOF {
		r.OnEOF(bytes.NewReader(r.buf.Bytes()))
	}
	return n, err
}
146368
func (r *NBReader) Read(buffer []byte) (int, error) {
	var (
		remaining   time.Duration
		nextTimeout time.Duration
		start       = time.Now()
		lastStart   = time.Now()
	)

	if len(buffer) <= r.buffer.Len() {
		ret, _ := r.buffer.Read(buffer)
		return ret, nil
	}

	if r.isEOF {
		return r.buffer.Read(buffer)
	}

	for r.buffer.Len() < len(buffer) {
		lastStart = time.Now()
		remaining = r.forceTimeout - time.Now().Sub(start)
		if r.chunkTimeout == 0 || r.chunkTimeout > remaining {
			nextTimeout = remaining
		} else {
			nextTimeout = r.chunkTimeout
		}
		_, err := r.readWithTimeout(r.buffer, nextTimeout)
		duration := time.Now().Sub(lastStart)
		if err == errTimeout {
			if duration >= r.chunkTimeout {
				break
			}
		}
		if err == io.EOF {
			r.isEOF = true
			break
		}
		if time.Now().Sub(start) >= r.forceTimeout {
			break
		}
	}
	ret, _ := r.buffer.Read(buffer)
	return ret, nil
}
714307
func Read() (string, error) {
	keyPath, err := kiteKeyPath()
	if err != nil {
		return "", err
	}
	data, err := ioutil.ReadFile(keyPath)
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(string(data)), nil
}
167007
func (t *timeoutReader) Read(p []byte) (int, error) {
	// FIXME limit the amount of data read in one chunk so as to not exceed the timeout?
	// Do the read in the background
	type result struct {
		n   int
		err error
	}
	done := make(chan result, 1)
	go func() {
		n, err := t.reader.Read(p)
		done <- result{n, err}
	}()
	// Wait for the read or the timeout
	timer := time.NewTimer(t.timeout)
	defer timer.Stop()
	select {
	case r := <-done:
		return r.n, r.err
	case <-timer.C:
		t.cancel()
		return 0, TimeoutError
	}
	panic("unreachable") // for Go 1.0
}
818540
func (lc *LoopbackConn) Read(b []byte) (n int, err error) {
	lc.rMutex.Lock()
	defer lc.rMutex.Unlock()

	if lc.buf.Len() > 0 {
		return lc.buf.Read(b)
	}
	msg, ok := <-lc.partnerCh
	if !ok {
		return 0, io.EOF
	}
	lc.buf.Write(msg)
	return lc.buf.Read(b)
}
270691
func (c *conn) Read(b []byte) (int, error) {
	return c.buf.Read(b)
}
152004
func (c *Conn) Read(p []byte) (int, error) {
	return c.r.Read(p)
}
233929
func (c *IdleTimingConn) Read(b []byte) (int, error) {
	c.closeMutex.RLock()
	n, err := c.doRead(b)
	c.closeMutex.RUnlock()
	return n, err
}
107805
func (r *ByteReader) Read(b []byte) (n int, err error) {
	if len(b) == 0 {
		return 0, nil
	}
	if r.off >= len(r.buf) {
		return 0, io.EOF
	}
	n = copy(b, r.buf[r.off:])
	r.off += n
	return
}
1094974
func (w *Socket) readLoop() {
	defer func() {
		// Close the socket on defer.
		w.Close()
	}()

	// Set the limits.
	w.ws.SetReadLimit(maxMessageSize)

	// Set the pong handler.
	w.ws.SetPongHandler(func(string) error {
		// Reset the read deadline.
		w.ws.SetReadDeadline(time.Now().Add(readWait))
		return nil
	})

	for {
		// Reset the read deadline.
		w.ws.SetReadDeadline(time.Now().Add(readWait))

		// Read from the websocket.
		_, data, err := w.ws.ReadMessage()
		if err != nil {
			// Websocket close code.
			wsCode := -1 // -1 for not set.

			// Try to obtain the websocket close code if present.
			// Assert to gorilla websocket CloseError type if possible.
			if closeErr, ok := err.(*websocket.CloseError); ok {
				wsCode = closeErr.Code
			}

			// Only log errors if this is not EOF and
			// if the socket was not closed already.
			// Also check the websocket close code.
			if err != io.EOF && !w.IsClosed() &&
				wsCode != websocket.CloseNormalClosure &&
				wsCode != websocket.CloseGoingAway &&
				wsCode != websocket.CloseNoStatusReceived {
				// Log
				log.L.WithFields(logrus.Fields{
					"remoteAddress": w.RemoteAddr(),
					"userAgent":     w.UserAgent(),
				}).Warningf("failed to read data from websocket: %v", err)
			}

			// Return and release this goroutine.
			// This will close this socket connection.
			return
		}

		// Write the received data to the read channel.
		w.readChan <- string(data)
	}
}