mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-03 07:56:42 -05:00
simplify chain writing
This commit is contained in:
parent
8c8f0a53fd
commit
88c9947285
@ -29,16 +29,10 @@ func (v *ChainWriter) Write(payload []byte) (int, error) {
|
|||||||
size := len(payload)
|
size := len(payload)
|
||||||
for size > 0 {
|
for size > 0 {
|
||||||
buffer := alloc.NewBuffer()
|
buffer := alloc.NewBuffer()
|
||||||
if size > alloc.BufferSize {
|
nBytes, _ := buffer.Write(payload)
|
||||||
buffer.Append(payload[:alloc.BufferSize])
|
size -= nBytes
|
||||||
size -= alloc.BufferSize
|
payload = payload[nBytes:]
|
||||||
payload = payload[alloc.BufferSize:]
|
bytesWritten += nBytes
|
||||||
bytesWritten += alloc.BufferSize
|
|
||||||
} else {
|
|
||||||
buffer.Append(payload)
|
|
||||||
bytesWritten += size
|
|
||||||
size = 0
|
|
||||||
}
|
|
||||||
err := v.writer.Write(buffer)
|
err := v.writer.Write(buffer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return bytesWritten, err
|
return bytesWritten, err
|
||||||
|
Loading…
Reference in New Issue
Block a user