1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
| package buf
|
| import (
| "syscall"
| )
|
| type windowsReader struct {
| bufs []syscall.WSABuf
| }
|
| func (r *windowsReader) Init(bs []*Buffer) {
| 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(Size), Buf: &b.v[0]})
| }
| }
|
| 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
| var flags uint32
| err := syscall.WSARecv(syscall.Handle(fd), &r.bufs[0], uint32(len(r.bufs)), &nBytes, &flags, nil, nil)
| if err != nil {
| return -1
| }
| return int32(nBytes)
| }
|
| func newMultiReader() multiReader {
| return new(windowsReader)
| }
|
|