1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-03 07:56:42 -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 return 0, io.ErrClosedPipe
} }
bytesWritten := 0
size := len(payload) size := len(payload)
for size > 0 { for size > 0 {
buffer := alloc.NewBuffer().Clear() buffer := alloc.NewBuffer().Clear()
@ -32,17 +33,19 @@ func (this *ChainWriter) Write(payload []byte) (int, error) {
buffer.Append(payload[:alloc.BufferSize]) buffer.Append(payload[:alloc.BufferSize])
size -= alloc.BufferSize size -= alloc.BufferSize
payload = payload[alloc.BufferSize:] payload = payload[alloc.BufferSize:]
bytesWritten += alloc.BufferSize
} else { } else {
buffer.Append(payload) buffer.Append(payload)
bytesWritten += size
size = 0 size = 0
} }
err := this.writer.Write(buffer) err := this.writer.Write(buffer)
if err != nil { if err != nil {
return 0, err return bytesWritten, err
} }
} }
return size, nil return bytesWritten, nil
} }
func (this *ChainWriter) Release() { func (this *ChainWriter) Release() {