Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-msgio
Commits
b47fa43a
Unverified
Commit
b47fa43a
authored
Apr 20, 2019
by
Steven Allen
Committed by
GitHub
Apr 20, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #12 from libp2p/fix/read-partial
fix: never claim to read more than read
parents
fd3a1c8f
345e83f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
6 deletions
+14
-6
msgio.go
msgio.go
+14
-6
No files found.
msgio.go
View file @
b47fa43a
...
...
@@ -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
)
{
...
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment