conn_read_legacy.go 440 B

123456789101112131415161718192021
  1. // Copyright 2016 The Gorilla WebSocket Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build !go1.5
  5. package websocket
  6. import "io"
  7. func (c *Conn) read(n int) ([]byte, error) {
  8. p, err := c.br.Peek(n)
  9. if err == io.EOF {
  10. err = errUnexpectedEOF
  11. }
  12. if len(p) > 0 {
  13. // advance over the bytes just read
  14. io.ReadFull(c.br, p)
  15. }
  16. return p, err
  17. }