mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 18:17:52 -05:00
use all buffers
This commit is contained in:
parent
dd159cce6c
commit
97d886e1c9
@ -193,10 +193,6 @@ func (r *AuthenticationReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
|
|||||||
return mb, nil
|
return mb, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
|
||||||
WriteSize = 1024
|
|
||||||
)
|
|
||||||
|
|
||||||
type AuthenticationWriter struct {
|
type AuthenticationWriter struct {
|
||||||
auth Authenticator
|
auth Authenticator
|
||||||
writer buf.Writer
|
writer buf.Writer
|
||||||
@ -235,12 +231,13 @@ func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) {
|
|||||||
func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
|
func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
|
||||||
defer mb.Release()
|
defer mb.Release()
|
||||||
|
|
||||||
|
payloadSize := buf.Size - w.auth.Overhead() - w.sizeParser.SizeBytes()
|
||||||
mb2Write := buf.NewMultiBufferCap(len(mb) + 10)
|
mb2Write := buf.NewMultiBufferCap(len(mb) + 10)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
b := buf.New()
|
b := buf.New()
|
||||||
common.Must(b.Reset(func(bb []byte) (int, error) {
|
common.Must(b.Reset(func(bb []byte) (int, error) {
|
||||||
return mb.Read(bb[:WriteSize])
|
return mb.Read(bb[:payloadSize])
|
||||||
}))
|
}))
|
||||||
eb, err := w.seal(b)
|
eb, err := w.seal(b)
|
||||||
b.Release()
|
b.Release()
|
||||||
|
@ -43,7 +43,7 @@ func TestAuthenticationReaderWriter(t *testing.T) {
|
|||||||
}, PlainChunkSizeParser{}, cache, protocol.TransferTypeStream)
|
}, PlainChunkSizeParser{}, cache, protocol.TransferTypeStream)
|
||||||
|
|
||||||
assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil)
|
assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil)
|
||||||
assert(cache.Len(), Equals, 83360)
|
assert(cache.Len(), Equals, 82658)
|
||||||
assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil)
|
assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil)
|
||||||
assert(err, IsNil)
|
assert(err, IsNil)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user