mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2025-10-16 13:50:51 +08:00

在四点链接的情况下,我们只终端中间两点是不够的,要切三刀; 总之实践很简单,就是copy完成之后,要Close所有的链接 readv的话,系统readv数组和buffer不要在put进pool后相互引用 添加-bl 选项,可以自定义buf大小;注意越小可能越慢,建议buf大小保持在4k以上 添加-pp选项,可以生成cpu.pprof文件 修复其它小问题.
48 lines
925 B
Go
48 lines
925 B
Go
package utils
|
|
|
|
import (
|
|
"syscall"
|
|
)
|
|
|
|
func GetReadVReader() SystemReadver {
|
|
return new(windowsReader)
|
|
}
|
|
|
|
type windowsReader struct {
|
|
bufs []syscall.WSABuf
|
|
}
|
|
|
|
func (r *windowsReader) Init(bs [][]byte, singleBufLen int) {
|
|
if r.bufs == nil {
|
|
r.bufs = make([]syscall.WSABuf, 0, len(bs))
|
|
}
|
|
for _, b := range bs {
|
|
r.bufs = append(r.bufs, syscall.WSABuf{Len: uint32(singleBufLen), Buf: &b[0]})
|
|
}
|
|
}
|
|
|
|
func (r *windowsReader) Clear() {
|
|
for idx := range r.bufs {
|
|
r.bufs[idx].Buf = nil
|
|
}
|
|
r.bufs = r.bufs[:0]
|
|
}
|
|
|
|
func (r *windowsReader) Recover(bsLen int, bs [][]byte) {
|
|
r.bufs = r.bufs[:len(bs)]
|
|
|
|
for idx := range r.bufs {
|
|
r.bufs[idx].Buf = &(bs[idx][0])
|
|
}
|
|
}
|
|
|
|
func (r *windowsReader) Read(fd uintptr) (uint32, error) {
|
|
var nBytes uint32
|
|
var flags uint32
|
|
err := syscall.WSARecv(syscall.Handle(fd), &r.bufs[0], uint32(len(r.bufs)), &nBytes, &flags, nil, nil)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
return nBytes, nil
|
|
}
|