mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-02 23:47:07 -05:00
add WriteMultiBuffer for interConn
This commit is contained in:
parent
010964f272
commit
3a1cf06dc1
@ -7,8 +7,9 @@ import (
|
||||
"time"
|
||||
|
||||
quic "github.com/lucas-clemente/quic-go"
|
||||
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/bytespool"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/transport/internet"
|
||||
)
|
||||
@ -142,6 +143,38 @@ func (c *interConn) Read(b []byte) (int, error) {
|
||||
return c.stream.Read(b)
|
||||
}
|
||||
|
||||
func (c *interConn) WriteMultiBuffer(mb buf.MultiBuffer) error {
|
||||
if mb.IsEmpty() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if len(mb) == 1 {
|
||||
_, err := c.Write(mb[0].Bytes())
|
||||
buf.ReleaseMulti(mb)
|
||||
return err
|
||||
}
|
||||
|
||||
b := bytespool.Alloc(32 * 1024)
|
||||
defer bytespool.Free(b)
|
||||
|
||||
reader := buf.MultiBufferContainer{
|
||||
MultiBuffer: mb,
|
||||
}
|
||||
defer reader.Close()
|
||||
|
||||
for {
|
||||
nBytes, err := reader.Read(b)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
if _, err := c.Write(b[:nBytes]); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *interConn) Write(b []byte) (int, error) {
|
||||
return c.stream.Write(b)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user