github.com/xraypb/xray-core@v1.6.6/common/buf/readv_windows.go (about) 1 package buf 2 3 import ( 4 "syscall" 5 ) 6 7 type windowsReader struct { 8 bufs []syscall.WSABuf 9 } 10 11 func (r *windowsReader) Init(bs []*Buffer) { 12 if r.bufs == nil { 13 r.bufs = make([]syscall.WSABuf, 0, len(bs)) 14 } 15 for _, b := range bs { 16 r.bufs = append(r.bufs, syscall.WSABuf{Len: uint32(Size), Buf: &b.v[0]}) 17 } 18 } 19 20 func (r *windowsReader) Clear() { 21 for idx := range r.bufs { 22 r.bufs[idx].Buf = nil 23 } 24 r.bufs = r.bufs[:0] 25 } 26 27 func (r *windowsReader) Read(fd uintptr) int32 { 28 var nBytes uint32 29 var flags uint32 30 err := syscall.WSARecv(syscall.Handle(fd), &r.bufs[0], uint32(len(r.bufs)), &nBytes, &flags, nil, nil) 31 if err != nil { 32 return -1 33 } 34 return int32(nBytes) 35 } 36 37 func newMultiReader() multiReader { 38 return new(windowsReader) 39 }