1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-05 16:55:27 -05:00

Fix test break

This commit is contained in:
Darien Raymond
2016-12-07 15:00:04 +01:00
parent 943d43040b
commit 6d0915cc8c
3 changed files with 27 additions and 26 deletions

View File

@@ -121,38 +121,38 @@ func (v *AuthenticationReader) CopyChunk(b []byte) int {
return nBytes
}
func (v *AuthenticationReader) EnsureChunk() error {
for {
err := v.NextChunk()
if err == nil {
return nil
}
if err == errInsufficientBuffer {
if !v.buffer.IsEmpty() {
leftover := v.buffer.Bytes()
v.buffer.SetBytesFunc(func(b []byte) int {
return copy(b, leftover)
})
}
_, err = v.buffer.FillFrom(v.reader)
}
return err
}
}
func (v *AuthenticationReader) Read(b []byte) (int, error) {
if len(v.chunk) > 0 {
nBytes := v.CopyChunk(b)
return nBytes, nil
}
totalBytes := 0
for {
err := v.NextChunk()
if err == errInsufficientBuffer {
if totalBytes > 0 {
return totalBytes, nil
}
leftover := v.buffer.Bytes()
v.buffer.SetBytesFunc(func(b []byte) int {
return copy(b, leftover)
})
_, err = v.buffer.FillFrom(v.reader)
}
if err != nil {
return 0, err
}
nBytes := v.CopyChunk(b)
b = b[nBytes:]
totalBytes += nBytes
if !v.aggressive {
return totalBytes, nil
}
err := v.EnsureChunk()
if err != nil {
return 0, err
}
nBytes := v.CopyChunk(b)
return nBytes, nil
}
type AuthenticationWriter struct {