1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

use all buffers

This commit is contained in:
Darien Raymond 2017-11-21 22:03:43 +01:00
parent dd159cce6c
commit 97d886e1c9
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 3 additions and 6 deletions

View File

@ -193,10 +193,6 @@ func (r *AuthenticationReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
return mb, nil
}
const (
WriteSize = 1024
)
type AuthenticationWriter struct {
auth Authenticator
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 {
defer mb.Release()
payloadSize := buf.Size - w.auth.Overhead() - w.sizeParser.SizeBytes()
mb2Write := buf.NewMultiBufferCap(len(mb) + 10)
for {
b := buf.New()
common.Must(b.Reset(func(bb []byte) (int, error) {
return mb.Read(bb[:WriteSize])
return mb.Read(bb[:payloadSize])
}))
eb, err := w.seal(b)
b.Release()

View File

@ -43,7 +43,7 @@ func TestAuthenticationReaderWriter(t *testing.T) {
}, PlainChunkSizeParser{}, cache, protocol.TransferTypeStream)
assert(writer.WriteMultiBuffer(buf.NewMultiBufferValue(payload)), IsNil)
assert(cache.Len(), Equals, 83360)
assert(cache.Len(), Equals, 82658)
assert(writer.WriteMultiBuffer(buf.MultiBuffer{}), IsNil)
assert(err, IsNil)