readv_windows.go 752 B

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