Commit 345e83f4 authored by Steven Allen's avatar Steven Allen

fix: never claim to read more than read

Not sure if this is the _right_ thing to do but it's better than reporting the
wrong length.
parent fd3a1c8f
...@@ -179,9 +179,13 @@ func (s *reader) Read(msg []byte) (int, error) { ...@@ -179,9 +179,13 @@ func (s *reader) Read(msg []byte) (int, error) {
return 0, io.ErrShortBuffer return 0, io.ErrShortBuffer
} }
_, err = io.ReadFull(s.R, msg[:length]) read, err := io.ReadFull(s.R, msg[:length])
s.next = -1 // signal we've consumed this msg if read < length {
return length, err s.next = length - read // we only partially consumed the message.
} else {
s.next = -1 // signal we've consumed this msg
}
return read, err
} }
func (s *reader) ReadMsg() ([]byte, error) { func (s *reader) ReadMsg() ([]byte, error) {
...@@ -203,9 +207,13 @@ func (s *reader) ReadMsg() ([]byte, error) { ...@@ -203,9 +207,13 @@ func (s *reader) ReadMsg() ([]byte, error) {
} }
msg := s.pool.Get(length) msg := s.pool.Get(length)
_, err = io.ReadFull(s.R, msg) read, err := io.ReadFull(s.R, msg)
s.next = -1 // signal we've consumed this msg if read < length {
return msg, err s.next = length - read // we only partially consumed the message.
} else {
s.next = -1 // signal we've consumed this msg
}
return msg[:read], err
} }
func (s *reader) ReleaseMsg(msg []byte) { func (s *reader) ReleaseMsg(msg []byte) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment