mode int32
// fields used only by net package
- buf syscall.WSABuf
- msg windows.WSAMsg
- sa syscall.Sockaddr
- rsa *syscall.RawSockaddrAny
- rsan int32
- flags uint32
- qty uint32
- bufs []syscall.WSABuf
+ buf syscall.WSABuf
+ msg windows.WSAMsg
+ sa syscall.Sockaddr
+ rsa *syscall.RawSockaddrAny
+ rsan int32
+ bufs []syscall.WSABuf
}
func (o *operation) setEvent() {
// It supports both synchronous and asynchronous IO.
// o.qty and o.flags are set to zero before calling submit
// to avoid reusing the values from a previous call.
-func (fd *FD) execIO(o *operation, submit func(o *operation) error) (int, error) {
+func (fd *FD) execIO(o *operation, submit func(o *operation) (uint32, error)) (int, error) {
// Notify runtime netpoll about starting IO.
err := fd.pd.prepare(int(o.mode), fd.isFile)
if err != nil {
// event to wait for the IO to complete.
o.setEvent()
}
- o.qty = 0
- o.flags = 0
- err = submit(o)
+ qty, err := submit(o)
var waitErr error
// Blocking operations shouldn't return ERROR_IO_PENDING.
// Continue without waiting if that happens.
// before the cancellation request runs.
}
if fd.isFile {
- err = windows.GetOverlappedResult(fd.Sysfd, &o.o, &o.qty, false)
+ err = windows.GetOverlappedResult(fd.Sysfd, &o.o, &qty, false)
} else {
- err = windows.WSAGetOverlappedResult(fd.Sysfd, &o.o, &o.qty, false, &o.flags)
+ var flags uint32
+ err = windows.WSAGetOverlappedResult(fd.Sysfd, &o.o, &qty, false, &flags)
}
}
switch err {
err = waitErr
}
}
- return int(o.qty), err
+ return int(qty), err
}
// FD is a file descriptor. The net and os packages embed this type in
case kindFile, kindPipe:
o := &fd.rop
o.InitBuf(buf)
- n, err = fd.execIO(o, func(o *operation) error {
- return syscall.ReadFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &o.qty, fd.overlapped(o))
+ n, err = fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.ReadFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &qty, fd.overlapped(o))
+ return qty, err
})
fd.addOffset(n)
switch err {
case kindNet:
o := &fd.rop
o.InitBuf(buf)
- n, err = fd.execIO(o, func(o *operation) error {
- return syscall.WSARecv(fd.Sysfd, &o.buf, 1, &o.qty, &o.flags, &o.o, nil)
+ n, err = fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ var flags uint32
+ err = syscall.WSARecv(fd.Sysfd, &o.buf, 1, &qty, &flags, &o.o, nil)
+ return qty, err
})
if race.Enabled {
race.Acquire(unsafe.Pointer(&ioSync))
o := &fd.rop
o.InitBuf(b)
fd.setOffset(off)
- n, err := fd.execIO(o, func(o *operation) error {
- return syscall.ReadFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &o.qty, &o.o)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.ReadFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &qty, &o.o)
+ return qty, err
})
if err == syscall.ERROR_HANDLE_EOF {
err = io.EOF
defer fd.readUnlock()
o := &fd.rop
o.InitBuf(buf)
- n, err := fd.execIO(o, func(o *operation) error {
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
if o.rsa == nil {
o.rsa = new(syscall.RawSockaddrAny)
}
o.rsan = int32(unsafe.Sizeof(*o.rsa))
- return syscall.WSARecvFrom(fd.Sysfd, &o.buf, 1, &o.qty, &o.flags, o.rsa, &o.rsan, &o.o, nil)
+ var flags uint32
+ err = syscall.WSARecvFrom(fd.Sysfd, &o.buf, 1, &qty, &flags, o.rsa, &o.rsan, &o.o, nil)
+ return qty, err
})
err = fd.eofError(n, err)
if err != nil {
defer fd.readUnlock()
o := &fd.rop
o.InitBuf(buf)
- n, err := fd.execIO(o, func(o *operation) error {
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
if o.rsa == nil {
o.rsa = new(syscall.RawSockaddrAny)
}
o.rsan = int32(unsafe.Sizeof(*o.rsa))
- return syscall.WSARecvFrom(fd.Sysfd, &o.buf, 1, &o.qty, &o.flags, o.rsa, &o.rsan, &o.o, nil)
+ var flags uint32
+ err = syscall.WSARecvFrom(fd.Sysfd, &o.buf, 1, &qty, &flags, o.rsa, &o.rsan, &o.o, nil)
+ return qty, err
})
err = fd.eofError(n, err)
if err != nil {
defer fd.readUnlock()
o := &fd.rop
o.InitBuf(buf)
- n, err := fd.execIO(o, func(o *operation) error {
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
if o.rsa == nil {
o.rsa = new(syscall.RawSockaddrAny)
}
o.rsan = int32(unsafe.Sizeof(*o.rsa))
- return syscall.WSARecvFrom(fd.Sysfd, &o.buf, 1, &o.qty, &o.flags, o.rsa, &o.rsan, &o.o, nil)
+ var flags uint32
+ err = syscall.WSARecvFrom(fd.Sysfd, &o.buf, 1, &qty, &flags, o.rsa, &o.rsan, &o.o, nil)
+ return qty, err
})
err = fd.eofError(n, err)
if err != nil {
case kindPipe, kindFile:
o := &fd.wop
o.InitBuf(b)
- n, err = fd.execIO(o, func(o *operation) error {
- return syscall.WriteFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &o.qty, fd.overlapped(o))
+ n, err = fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.WriteFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &qty, fd.overlapped(o))
+ return qty, err
})
fd.addOffset(n)
case kindNet:
}
o := &fd.wop
o.InitBuf(b)
- n, err = fd.execIO(o, func(o *operation) error {
- return syscall.WSASend(fd.Sysfd, &o.buf, 1, &o.qty, 0, &o.o, nil)
+ n, err = fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.WSASend(fd.Sysfd, &o.buf, 1, &qty, 0, &o.o, nil)
+ return qty, err
})
}
ntotal += n
o := &fd.wop
o.InitBuf(b)
fd.setOffset(off + int64(ntotal))
- n, err := fd.execIO(o, func(o *operation) error {
- return syscall.WriteFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &o.qty, &o.o)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.WriteFile(fd.Sysfd, unsafe.Slice(o.buf.Buf, o.buf.Len), &qty, &o.o)
+ return qty, err
})
if n > 0 {
ntotal += n
}
o := &fd.wop
o.InitBufs(buf)
- n, err := fd.execIO(o, func(o *operation) error {
- return syscall.WSASend(fd.Sysfd, &o.bufs[0], uint32(len(o.bufs)), &o.qty, 0, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.WSASend(fd.Sysfd, &o.bufs[0], uint32(len(o.bufs)), &qty, 0, &o.o, nil)
+ return qty, err
})
o.ClearBufs()
TestHookDidWritev(n)
o := &fd.wop
o.InitBuf(buf)
o.sa = sa
- n, err := fd.execIO(o, func(o *operation) error {
- return syscall.WSASendto(fd.Sysfd, &o.buf, 1, &o.qty, 0, o.sa, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.WSASendto(fd.Sysfd, &o.buf, 1, &qty, 0, o.sa, &o.o, nil)
+ return qty, err
})
return n, err
}
o := &fd.wop
o.InitBuf(b)
o.sa = sa
- n, err := fd.execIO(o, func(o *operation) error {
- return syscall.WSASendto(fd.Sysfd, &o.buf, 1, &o.qty, 0, o.sa, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = syscall.WSASendto(fd.Sysfd, &o.buf, 1, &qty, 0, o.sa, &o.o, nil)
+ return qty, err
})
ntotal += int(n)
if err != nil {
// handle zero-byte payload
o := &fd.wop
o.InitBuf(buf)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendtoInet4(fd.Sysfd, &o.buf, 1, &o.qty, 0, sa4, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendtoInet4(fd.Sysfd, &o.buf, 1, &qty, 0, sa4, &o.o, nil)
+ return qty, err
})
return n, err
}
}
o := &fd.wop
o.InitBuf(b)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendtoInet4(fd.Sysfd, &o.buf, 1, &o.qty, 0, sa4, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendtoInet4(fd.Sysfd, &o.buf, 1, &qty, 0, sa4, &o.o, nil)
+ return qty, err
})
ntotal += int(n)
if err != nil {
// handle zero-byte payload
o := &fd.wop
o.InitBuf(buf)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendtoInet6(fd.Sysfd, &o.buf, 1, &o.qty, 0, sa6, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendtoInet6(fd.Sysfd, &o.buf, 1, &qty, 0, sa6, &o.o, nil)
+ return qty, err
})
return n, err
}
}
o := &fd.wop
o.InitBuf(b)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendtoInet6(fd.Sysfd, &o.buf, 1, &o.qty, 0, sa6, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendtoInet6(fd.Sysfd, &o.buf, 1, &qty, 0, sa6, &o.o, nil)
+ return qty, err
})
ntotal += int(n)
if err != nil {
func (fd *FD) ConnectEx(ra syscall.Sockaddr) error {
o := &fd.wop
o.sa = ra
- _, err := fd.execIO(o, func(o *operation) error {
- return ConnectExFunc(fd.Sysfd, o.sa, nil, 0, nil, &o.o)
+ _, err := fd.execIO(o, func(o *operation) (uint32, error) {
+ return 0, ConnectExFunc(fd.Sysfd, o.sa, nil, 0, nil, &o.o)
})
return err
}
func (fd *FD) acceptOne(s syscall.Handle, rawsa []syscall.RawSockaddrAny, o *operation) (string, error) {
// Submit accept request.
o.rsan = int32(unsafe.Sizeof(rawsa[0]))
- _, err := fd.execIO(o, func(o *operation) error {
- return AcceptFunc(fd.Sysfd, s, (*byte)(unsafe.Pointer(&rawsa[0])), 0, uint32(o.rsan), uint32(o.rsan), &o.qty, &o.o)
+ _, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = AcceptFunc(fd.Sysfd, s, (*byte)(unsafe.Pointer(&rawsa[0])), 0, uint32(o.rsan), uint32(o.rsan), &qty, &o.o)
+ return qty, err
})
if err != nil {
CloseFunc(s)
// socket is readable. h/t https://stackoverflow.com/a/42019668/332798
o := &fd.rop
o.InitBuf(nil)
- _, err := fd.execIO(o, func(o *operation) error {
+ _, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ var flags uint32
if !fd.IsStream {
- o.flags |= windows.MSG_PEEK
+ flags |= windows.MSG_PEEK
}
- return syscall.WSARecv(fd.Sysfd, &o.buf, 1, &o.qty, &o.flags, &o.o, nil)
+ err = syscall.WSARecv(fd.Sysfd, &o.buf, 1, &qty, &flags, &o.o, nil)
+ return qty, err
})
if err == windows.WSAEMSGSIZE {
// expected with a 0-byte peek, ignore.
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
o.msg.Flags = uint32(flags)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSARecvMsg(fd.Sysfd, &o.msg, &o.qty, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSARecvMsg(fd.Sysfd, &o.msg, &qty, &o.o, nil)
+ return qty, err
})
err = fd.eofError(n, err)
var sa syscall.Sockaddr
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
o.msg.Flags = uint32(flags)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSARecvMsg(fd.Sysfd, &o.msg, &o.qty, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSARecvMsg(fd.Sysfd, &o.msg, &qty, &o.o, nil)
+ return qty, err
})
err = fd.eofError(n, err)
if err == nil {
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
o.msg.Flags = uint32(flags)
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSARecvMsg(fd.Sysfd, &o.msg, &o.qty, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSARecvMsg(fd.Sysfd, &o.msg, &qty, &o.o, nil)
+ return qty, err
})
err = fd.eofError(n, err)
if err == nil {
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = len
}
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendMsg(fd.Sysfd, &o.msg, 0, &o.qty, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendMsg(fd.Sysfd, &o.msg, 0, nil, &o.o, nil)
+ return qty, err
})
return n, int(o.msg.Control.Len), err
}
len := sockaddrInet4ToRaw(o.rsa, sa)
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = len
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendMsg(fd.Sysfd, &o.msg, 0, &o.qty, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendMsg(fd.Sysfd, &o.msg, 0, nil, &o.o, nil)
+ return qty, err
})
return n, int(o.msg.Control.Len), err
}
len := sockaddrInet6ToRaw(o.rsa, sa)
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
o.msg.Namelen = len
- n, err := fd.execIO(o, func(o *operation) error {
- return windows.WSASendMsg(fd.Sysfd, &o.msg, 0, &o.qty, &o.o, nil)
+ n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
+ err = windows.WSASendMsg(fd.Sysfd, &o.msg, 0, nil, &o.o, nil)
+ return qty, err
})
return n, int(o.msg.Control.Len), err
}