1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 10:08:15 -05:00

return correct number of bytes written

This commit is contained in:
Darien Raymond 2016-11-19 22:38:24 +01:00
parent 18cd10be2b
commit 1169476e69
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -25,6 +25,7 @@ func (this *ChainWriter) Write(payload []byte) (int, error) {
return 0, io.ErrClosedPipe
}
bytesWritten := 0
size := len(payload)
for size > 0 {
buffer := alloc.NewBuffer().Clear()
@ -32,17 +33,19 @@ func (this *ChainWriter) Write(payload []byte) (int, error) {
buffer.Append(payload[:alloc.BufferSize])
size -= alloc.BufferSize
payload = payload[alloc.BufferSize:]
bytesWritten += alloc.BufferSize
} else {
buffer.Append(payload)
bytesWritten += size
size = 0
}
err := this.writer.Write(buffer)
if err != nil {
return 0, err
return bytesWritten, err
}
}
return size, nil
return bytesWritten, nil
}
func (this *ChainWriter) Release() {