1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-28 06:46:14 -04: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 { if err != nil {
err := v.NextChunk() return 0, err
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
}
} }
nBytes := v.CopyChunk(b)
return nBytes, 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)
} }