1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-04 08:15:21 -05:00

remove ToNetBuffers

This commit is contained in:
Darien Raymond
2018-08-17 11:51:59 +02:00
parent 950612544b
commit 2594f7027a
3 changed files with 25 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ package buf
import (
"io"
"net"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
@@ -10,6 +11,8 @@ import (
// BufferToBytesWriter is a Writer that writes alloc.Buffer into underlying writer.
type BufferToBytesWriter struct {
io.Writer
cache [][]byte
}
// WriteMultiBuffer implements Writer. This method takes ownership of the given buffer.
@@ -25,10 +28,16 @@ func (w *BufferToBytesWriter) WriteMultiBuffer(mb MultiBuffer) error {
return WriteAllBytes(w.Writer, mb[0].Bytes())
}
bs := mb.ToNetBuffers()
bs := w.cache
for _, b := range mb {
bs = append(bs, b.Bytes())
}
w.cache = bs[:0]
nb := net.Buffers(bs)
for size > 0 {
n, err := bs.WriteTo(w.Writer)
n, err := nb.WriteTo(w.Writer)
if err != nil {
return err
}