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:
parent
18cd10be2b
commit
1169476e69
@ -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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user