mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
v1.0.0
This commit is contained in:
parent
47d23e9972
commit
c7f7c08ead
711 changed files with 82154 additions and 2 deletions
47
common/buf/readv_posix.go
Normal file
47
common/buf/readv_posix.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
// +build !windows
|
||||
// +build !wasm
|
||||
// +build !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{}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue