1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-02 23:47:07 -05:00

rework multibuf copy

This commit is contained in:
Darien Raymond 2018-07-29 03:38:54 +02:00
parent 9ee9af9e02
commit a3fd81dfff
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -392,7 +392,11 @@ func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
}
}()
mbPtr := &mb
f := func(x *buf.MultiBuffer) buf.Supplier {
return func(bb []byte) (int, error) {
return x.Read(bb[:c.mss])
}
}(&mb)
for {
for {
@ -400,13 +404,11 @@ func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) error {
return io.ErrClosedPipe
}
if !c.sendingWorker.Push(func(bb []byte) (int, error) {
return mbPtr.Read(bb[:c.mss])
}) {
if !c.sendingWorker.Push(f) {
break
}
updatePending = true
if mbPtr.IsEmpty() {
if mb.IsEmpty() {
return nil
}
}