1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-26 13:56:12 -04:00

don't copy leftoever if at head

This commit is contained in:
Darien Raymond 2017-02-06 14:06:41 +01:00
parent 775b4ef542
commit 2897df5a7a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 10 additions and 1 deletions

View File

@ -128,8 +128,10 @@ func (v *AuthenticationReader) CopyChunk(b []byte) int {
}
func (v *AuthenticationReader) EnsureChunk() error {
atHead := false
if v.buffer.IsEmpty() {
v.buffer.Clear()
atHead = true
}
for {
@ -139,7 +141,7 @@ func (v *AuthenticationReader) EnsureChunk() error {
}
leftover := v.buffer.Bytes()
if len(leftover) > 0 {
if !atHead && len(leftover) > 0 {
common.Must(v.buffer.Reset(func(b []byte) (int, error) {
return copy(b, leftover), nil
}))

View File

@ -91,6 +91,8 @@ func TestAuthenticationReaderWriterPartial(t *testing.T) {
AdditionalDataGenerator: &NoOpBytesGenerator{},
}, cache)
writer.Write([]byte{'a', 'b', 'c', 'd'})
nBytes, err := writer.Write(payload)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(payload))
@ -120,6 +122,11 @@ func TestAuthenticationReaderWriterPartial(t *testing.T) {
}, pr)
actualPayload := make([]byte, 7*1024)
nBytes, err = reader.Read(actualPayload)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(4)
assert.Bytes(actualPayload[:nBytes]).Equals([]byte{'a', 'b', 'c', 'd'})
nBytes, err = reader.Read(actualPayload)
assert.Error(err).IsNil()
assert.Int(nBytes).Equals(len(actualPayload))