1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00

Fix test break

This commit is contained in:
Darien Raymond 2016-12-07 15:00:04 +01:00
parent 943d43040b
commit 6d0915cc8c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
3 changed files with 27 additions and 26 deletions

View File

@ -108,6 +108,7 @@ func (b *Buffer) Bytes() []byte {
} }
func (b *Buffer) SetBytesFunc(writer BytesWriter) { func (b *Buffer) SetBytesFunc(writer BytesWriter) {
b.start = defaultOffset
b.end = b.start + writer(b.v[b.start:]) b.end = b.start + writer(b.v[b.start:])
} }

View File

@ -121,38 +121,38 @@ func (v *AuthenticationReader) CopyChunk(b []byte) int {
return nBytes 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) { func (v *AuthenticationReader) Read(b []byte) (int, error) {
if len(v.chunk) > 0 { if len(v.chunk) > 0 {
nBytes := v.CopyChunk(b) nBytes := v.CopyChunk(b)
return nBytes, nil return nBytes, nil
} }
totalBytes := 0 err := v.EnsureChunk()
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 { if err != nil {
return 0, err return 0, err
} }
nBytes := v.CopyChunk(b) nBytes := v.CopyChunk(b)
b = b[nBytes:] return nBytes, nil
totalBytes += nBytes
if !v.aggressive {
return totalBytes, nil
}
}
} }
type AuthenticationWriter struct { type AuthenticationWriter struct {

View File

@ -25,5 +25,5 @@ func TestAdaptiveReader(t *testing.T) {
b2, err := reader.Read() b2, err := reader.Read()
assert.Error(err).IsNil() assert.Error(err).IsNil()
assert.Bool(b2.IsFull()).IsTrue() assert.Bool(b2.IsFull()).IsTrue()
assert.Int(buffer.Len()).Equals(778272) assert.Int(buffer.Len()).Equals(1007648)
} }