Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: never claim to read more than read #12

Merged
merged 1 commit into from
Apr 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions msgio.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,13 @@ func (s *reader) Read(msg []byte) (int, error) {
return 0, io.ErrShortBuffer
}

_, err = io.ReadFull(s.R, msg[:length])
s.next = -1 // signal we've consumed this msg
return length, err
read, err := io.ReadFull(s.R, msg[:length])
if read < length {
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) {
Expand All @@ -203,9 +207,13 @@ func (s *reader) ReadMsg() ([]byte, error) {
}

msg := s.pool.Get(length)
_, err = io.ReadFull(s.R, msg)
s.next = -1 // signal we've consumed this msg
return msg, err
read, err := io.ReadFull(s.R, msg)
if read < length {
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) {
Expand Down