1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-10 06:16:53 -05:00
v2fly/common/buf/readv_posix.go
database64128 c78ee5aac7
🏡 Housekeeping: Update to Go 1.17 (#1215)
* ⬆ Update to Go 1.17

* 🏗 Update workflows and add windows-arm64

* 💾 Update generated files

* 📛 Update not-so-friendly filenames
2021-08-21 13:20:40 +08:00

47 lines
844 B
Go

//go:build !windows && !wasm && !illumos
// +build !windows,!wasm,!illumos
package buf
import (
"syscall"
"unsafe"
)
type posixReader struct {
iovecs []syscall.Iovec
}
func (r *posixReader) Init(bs []*Buffer) {
iovecs := r.iovecs
if iovecs == nil {
iovecs = make([]syscall.Iovec, 0, len(bs))
}
for idx, b := range bs {
iovecs = append(iovecs, syscall.Iovec{
Base: &(b.v[0]),
})
iovecs[idx].SetLen(int(Size))
}
r.iovecs = iovecs
}
func (r *posixReader) Read(fd uintptr) int32 {
n, _, e := syscall.Syscall(syscall.SYS_READV, fd, uintptr(unsafe.Pointer(&r.iovecs[0])), uintptr(len(r.iovecs)))
if e != 0 {
return -1
}
return int32(n)
}
func (r *posixReader) Clear() {
for idx := range r.iovecs {
r.iovecs[idx].Base = nil
}
r.iovecs = r.iovecs[:0]
}
func newMultiReader() multiReader {
return &posixReader{}
}