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-yamux
Commits
96b99cb4
Commit
96b99cb4
authored
Feb 17, 2021
by
Marten Seemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
consistently use uint32 for len and cap of the buffer
parent
fad228ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
13 deletions
+11
-13
stream.go
stream.go
+1
-1
util.go
util.go
+8
-10
util_test.go
util_test.go
+2
-2
No files found.
stream.go
View file @
96b99cb4
...
...
@@ -429,7 +429,7 @@ func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error {
}
// Copy into buffer
if
err
:=
s
.
recvBuf
.
Append
(
conn
,
int
(
length
)
)
;
err
!=
nil
{
if
err
:=
s
.
recvBuf
.
Append
(
conn
,
length
);
err
!=
nil
{
s
.
session
.
logger
.
Printf
(
"[ERR] yamux: Failed to read stream data: %v"
,
err
)
return
err
}
...
...
util.go
View file @
96b99cb4
...
...
@@ -84,11 +84,10 @@ func newSegmentedBuffer(initialCapacity uint32) segmentedBuffer {
}
// Len is the amount of data in the receive buffer.
func
(
s
*
segmentedBuffer
)
Len
()
int
{
func
(
s
*
segmentedBuffer
)
Len
()
u
int
32
{
s
.
bm
.
Lock
()
len
:=
s
.
len
s
.
bm
.
Unlock
()
return
int
(
len
)
defer
s
.
bm
.
Unlock
()
return
s
.
len
}
// Cap is the remaining capacity in the receive buffer.
...
...
@@ -97,9 +96,8 @@ func (s *segmentedBuffer) Len() int {
// buffer is len+cap.
func
(
s
*
segmentedBuffer
)
Cap
()
uint32
{
s
.
bm
.
Lock
()
cap
:=
s
.
cap
s
.
bm
.
Unlock
()
return
cap
defer
s
.
bm
.
Unlock
()
return
s
.
cap
}
// If the space to write into + current buffer size has grown to half of the window size,
...
...
@@ -154,8 +152,8 @@ func (s *segmentedBuffer) Read(b []byte) (int, error) {
return
n
,
nil
}
func
(
s
*
segmentedBuffer
)
Append
(
input
io
.
Reader
,
length
int
)
error
{
dst
:=
pool
.
Get
(
length
)
func
(
s
*
segmentedBuffer
)
Append
(
input
io
.
Reader
,
length
u
int
32
)
error
{
dst
:=
pool
.
Get
(
int
(
length
)
)
n
,
err
:=
io
.
ReadFull
(
input
,
dst
)
if
err
==
io
.
EOF
{
err
=
io
.
ErrUnexpectedEOF
...
...
@@ -165,7 +163,7 @@ func (s *segmentedBuffer) Append(input io.Reader, length int) error {
if
n
>
0
{
s
.
len
+=
uint32
(
n
)
s
.
cap
-=
uint32
(
n
)
s
.
pending
=
s
.
pending
-
uint32
(
length
)
s
.
pending
=
s
.
pending
-
length
s
.
b
=
append
(
s
.
b
,
dst
[
0
:
n
])
}
return
err
...
...
util_test.go
View file @
96b99cb4
...
...
@@ -54,11 +54,11 @@ func TestMin(t *testing.T) {
func
TestSegmentedBuffer
(
t
*
testing
.
T
)
{
buf
:=
newSegmentedBuffer
(
100
)
assert
:=
func
(
len
,
cap
int
)
{
assert
:=
func
(
len
,
cap
u
int
32
)
{
if
buf
.
Len
()
!=
len
{
t
.
Fatalf
(
"expected length %d, got %d"
,
len
,
buf
.
Len
())
}
if
buf
.
Cap
()
!=
uint32
(
cap
)
{
if
buf
.
Cap
()
!=
cap
{
t
.
Fatalf
(
"expected length %d, got %d"
,
len
,
buf
.
Len
())
}
}
...
...
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