mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
27 lines
559 B
Go
27 lines
559 B
Go
package rw
|
|
|
|
import (
|
|
"io"
|
|
"runtime"
|
|
|
|
"github.com/sagernet/sing/common"
|
|
"github.com/sagernet/sing/common/buf"
|
|
)
|
|
|
|
func WriteVC(conn io.Writer, data ...[]byte) (int, error) {
|
|
if fd, err := common.TryFileDescriptor(conn); err == nil {
|
|
return WriteV(fd, data...)
|
|
}
|
|
var bufLen int
|
|
for _, dataItem := range data {
|
|
bufLen += len(dataItem)
|
|
}
|
|
_buffer := buf.Make(bufLen)
|
|
defer runtime.KeepAlive(_buffer)
|
|
buffer := common.Dup(_buffer)
|
|
var bufN int
|
|
for _, dataItem := range data {
|
|
bufN += copy(buffer[bufN:], dataItem)
|
|
}
|
|
return conn.Write(buffer)
|
|
}
|