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
4b898093
Commit
4b898093
authored
Jun 14, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make the maximum message size configurable
parent
2471ea54
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
msgio.go
msgio.go
+15
-4
varint.go
varint.go
+16
-7
No files found.
msgio.go
View file @
4b898093
...
@@ -138,10 +138,21 @@ func NewReader(r io.Reader) ReadCloser {
...
@@ -138,10 +138,21 @@ func NewReader(r io.Reader) ReadCloser {
return
NewReaderWithPool
(
r
,
pool
.
GlobalPool
)
return
NewReaderWithPool
(
r
,
pool
.
GlobalPool
)
}
}
// NewReaderWithPool wraps an io.Reader with a msgio framed reader. The msgio.Reader
// NewReaderSize is equivalent to NewReader but allows one to
// will read whole messages at a time (using the length). Assumes an equivalent
// specify a max message size.
// writer on the other side. It uses a given pool.BufferPool
func
NewReaderSize
(
r
io
.
Reader
,
maxMessageSize
int
)
ReadCloser
{
return
NewReaderSizeWithPool
(
r
,
maxMessageSize
,
pool
.
GlobalPool
)
}
// NewReaderWithPool is the same as NewReader but allows one to specify a buffer
// pool.
func
NewReaderWithPool
(
r
io
.
Reader
,
p
*
pool
.
BufferPool
)
ReadCloser
{
func
NewReaderWithPool
(
r
io
.
Reader
,
p
*
pool
.
BufferPool
)
ReadCloser
{
return
NewReaderSizeWithPool
(
r
,
defaultMaxSize
,
p
)
}
// NewReaderWithPool is the same as NewReader but allows one to specify a buffer
// pool and a max message size.
func
NewReaderSizeWithPool
(
r
io
.
Reader
,
maxMessageSize
int
,
p
*
pool
.
BufferPool
)
ReadCloser
{
if
p
==
nil
{
if
p
==
nil
{
panic
(
"nil pool"
)
panic
(
"nil pool"
)
}
}
...
@@ -149,7 +160,7 @@ func NewReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser {
...
@@ -149,7 +160,7 @@ func NewReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser {
R
:
r
,
R
:
r
,
next
:
-
1
,
next
:
-
1
,
pool
:
p
,
pool
:
p
,
max
:
defaultMax
Size
,
max
:
maxMessage
Size
,
}
}
}
}
...
...
varint.go
View file @
4b898093
...
@@ -74,15 +74,24 @@ type varintReader struct {
...
@@ -74,15 +74,24 @@ type varintReader struct {
// Varints read according to https://golang.org/pkg/encoding/binary/#ReadUvarint
// Varints read according to https://golang.org/pkg/encoding/binary/#ReadUvarint
// Assumes an equivalent writer on the other side.
// Assumes an equivalent writer on the other side.
func
NewVarintReader
(
r
io
.
Reader
)
ReadCloser
{
func
NewVarintReader
(
r
io
.
Reader
)
ReadCloser
{
return
NewVarintReader
WithPool
(
r
,
pool
.
GlobalPool
)
return
NewVarintReader
Size
(
r
,
defaultMaxSize
)
}
}
// NewVarintReaderWithPool wraps an io.Reader with a varint msgio framed reader.
// NewVarintReaderSize is equivalent to NewVarintReader but allows one to
// The msgio.Reader will read whole messages at a time (using the length).
// specify a max message size.
// Varints read according to https://golang.org/pkg/encoding/binary/#ReadUvarint
func
NewVarintReaderSize
(
r
io
.
Reader
,
maxMessageSize
int
)
ReadCloser
{
// Assumes an equivalent writer on the other side. It uses a given
return
NewVarintReaderSizeWithPool
(
r
,
maxMessageSize
,
pool
.
GlobalPool
)
// pool.BufferPool.
}
// NewVarintReaderWithPool is the same as NewVarintReader but allows one to
// specify a buffer pool.
func
NewVarintReaderWithPool
(
r
io
.
Reader
,
p
*
pool
.
BufferPool
)
ReadCloser
{
func
NewVarintReaderWithPool
(
r
io
.
Reader
,
p
*
pool
.
BufferPool
)
ReadCloser
{
return
NewVarintReaderSizeWithPool
(
r
,
defaultMaxSize
,
p
)
}
// NewVarintReaderWithPool is the same as NewVarintReader but allows one to
// specify a buffer pool and a max message size.
func
NewVarintReaderSizeWithPool
(
r
io
.
Reader
,
maxMessageSize
int
,
p
*
pool
.
BufferPool
)
ReadCloser
{
if
p
==
nil
{
if
p
==
nil
{
panic
(
"nil pool"
)
panic
(
"nil pool"
)
}
}
...
@@ -91,7 +100,7 @@ func NewVarintReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser {
...
@@ -91,7 +100,7 @@ func NewVarintReaderWithPool(r io.Reader, p *pool.BufferPool) ReadCloser {
br
:
&
simpleByteReader
{
R
:
r
},
br
:
&
simpleByteReader
{
R
:
r
},
next
:
-
1
,
next
:
-
1
,
pool
:
p
,
pool
:
p
,
max
:
defaultMax
Size
,
max
:
maxMessage
Size
,
}
}
}
}
...
...
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