1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 09:26:21 -05:00
v2fly/common/buf/readv_windows.go

40 lines
733 B
Go
Raw Normal View History

2018-08-18 17:12:22 -04:00
package buf
2018-08-25 16:41:36 -04:00
import (
"syscall"
)
2018-08-18 17:12:22 -04:00
type windowsReader struct {
2018-08-25 14:54:37 -04:00
bufs []syscall.WSABuf
2018-08-18 17:12:22 -04:00
}
func (r *windowsReader) Init(bs []*Buffer) {
if r.bufs == nil {
r.bufs = make([]syscall.WSABuf, 0, len(bs))
}
for _, b := range bs {
2018-08-25 17:27:09 -04:00
r.bufs = append(r.bufs, syscall.WSABuf{Len: uint32(Size), Buf: &b.v[0]})
2018-08-18 17:12:22 -04:00
}
}
func (r *windowsReader) Clear() {
for idx := range r.bufs {
r.bufs[idx].Buf = nil
}
r.bufs = r.bufs[:0]
}
func (r *windowsReader) Read(fd uintptr) int32 {
var nBytes uint32
2018-08-25 14:54:37 -04:00
var flags uint32
2018-08-25 15:40:30 -04:00
err := syscall.WSARecv(syscall.Handle(fd), &r.bufs[0], uint32(len(r.bufs)), &nBytes, &flags, nil, nil)
2018-08-18 17:12:22 -04:00
if err != nil {
return -1
}
return int32(nBytes)
}
func newMultiReader() multiReader {
return new(windowsReader)
}