Parcourir la source

use all buffers

Darien Raymond il y a 8 ans
Parent
commit
97d886e1c9
2 fichiers modifiés avec 3 ajouts et 6 suppressions
  1. 2 5
      common/crypto/auth.go
  2. 1 1
      common/crypto/auth_test.go

+ 2 - 5
common/crypto/auth.go

@@ -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()

+ 1 - 1
common/crypto/auth_test.go

@@ -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)