mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
internal/poll: remove msg field from Windows' poll.operation
There is no need to keep the msg field in the poll.operation struct. This skims down the size of os.File by 112 bytes. Change-Id: I5c7b1f3989f9bb5f1748df2cba8128d9c479b35d Reviewed-on: https://go-review.googlesource.com/c/go/+/685418 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Mark Freeman <mark@golang.org>
This commit is contained in:
parent
d7b4114346
commit
0984264471
1 changed files with 43 additions and 51 deletions
|
|
@ -78,7 +78,6 @@ type operation struct {
|
||||||
|
|
||||||
// fields used only by net package
|
// fields used only by net package
|
||||||
buf syscall.WSABuf
|
buf syscall.WSABuf
|
||||||
msg windows.WSAMsg
|
|
||||||
rsa *syscall.RawSockaddrAny
|
rsa *syscall.RawSockaddrAny
|
||||||
bufs []syscall.WSABuf
|
bufs []syscall.WSABuf
|
||||||
}
|
}
|
||||||
|
|
@ -112,10 +111,7 @@ func (fd *FD) overlapped(o *operation) *syscall.Overlapped {
|
||||||
|
|
||||||
func (o *operation) InitBuf(buf []byte) {
|
func (o *operation) InitBuf(buf []byte) {
|
||||||
o.buf.Len = uint32(len(buf))
|
o.buf.Len = uint32(len(buf))
|
||||||
o.buf.Buf = nil
|
o.buf.Buf = unsafe.SliceData(buf)
|
||||||
if len(buf) != 0 {
|
|
||||||
o.buf.Buf = &buf[0]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *operation) InitBufs(buf *[][]byte) {
|
func (o *operation) InitBufs(buf *[][]byte) {
|
||||||
|
|
@ -148,19 +144,18 @@ func (o *operation) ClearBufs() {
|
||||||
o.bufs = o.bufs[:0]
|
o.bufs = o.bufs[:0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *operation) InitMsg(p []byte, oob []byte) {
|
func newWSAMsg(p []byte, oob []byte, flags int) windows.WSAMsg {
|
||||||
o.InitBuf(p)
|
return windows.WSAMsg{
|
||||||
o.msg.Buffers = &o.buf
|
Buffers: &syscall.WSABuf{
|
||||||
o.msg.BufferCount = 1
|
Len: uint32(len(p)),
|
||||||
|
Buf: unsafe.SliceData(p),
|
||||||
o.msg.Name = nil
|
},
|
||||||
o.msg.Namelen = 0
|
BufferCount: 1,
|
||||||
|
Control: syscall.WSABuf{
|
||||||
o.msg.Flags = 0
|
Len: uint32(len(oob)),
|
||||||
o.msg.Control.Len = uint32(len(oob))
|
Buf: unsafe.SliceData(oob),
|
||||||
o.msg.Control.Buf = nil
|
},
|
||||||
if len(oob) != 0 {
|
Flags: uint32(flags),
|
||||||
o.msg.Control.Buf = &oob[0]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1279,15 +1274,14 @@ func (fd *FD) ReadMsg(p []byte, oob []byte, flags int) (int, int, int, syscall.S
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &fd.rop
|
o := &fd.rop
|
||||||
o.InitMsg(p, oob)
|
|
||||||
if o.rsa == nil {
|
if o.rsa == nil {
|
||||||
o.rsa = new(syscall.RawSockaddrAny)
|
o.rsa = new(syscall.RawSockaddrAny)
|
||||||
}
|
}
|
||||||
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
msg := newWSAMsg(p, oob, flags)
|
||||||
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
|
msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
||||||
o.msg.Flags = uint32(flags)
|
msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
|
||||||
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
||||||
err = windows.WSARecvMsg(fd.Sysfd, &o.msg, &qty, &o.o, nil)
|
err = windows.WSARecvMsg(fd.Sysfd, &msg, &qty, &o.o, nil)
|
||||||
return qty, err
|
return qty, err
|
||||||
})
|
})
|
||||||
err = fd.eofError(n, err)
|
err = fd.eofError(n, err)
|
||||||
|
|
@ -1295,7 +1289,7 @@ func (fd *FD) ReadMsg(p []byte, oob []byte, flags int) (int, int, int, syscall.S
|
||||||
if err == nil {
|
if err == nil {
|
||||||
sa, err = o.rsa.Sockaddr()
|
sa, err = o.rsa.Sockaddr()
|
||||||
}
|
}
|
||||||
return n, int(o.msg.Control.Len), int(o.msg.Flags), sa, err
|
return n, int(msg.Control.Len), int(msg.Flags), sa, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadMsgInet4 is ReadMsg, but specialized to return a syscall.SockaddrInet4.
|
// ReadMsgInet4 is ReadMsg, but specialized to return a syscall.SockaddrInet4.
|
||||||
|
|
@ -1310,22 +1304,21 @@ func (fd *FD) ReadMsgInet4(p []byte, oob []byte, flags int, sa4 *syscall.Sockadd
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &fd.rop
|
o := &fd.rop
|
||||||
o.InitMsg(p, oob)
|
|
||||||
if o.rsa == nil {
|
if o.rsa == nil {
|
||||||
o.rsa = new(syscall.RawSockaddrAny)
|
o.rsa = new(syscall.RawSockaddrAny)
|
||||||
}
|
}
|
||||||
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
msg := newWSAMsg(p, oob, flags)
|
||||||
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
|
msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
||||||
o.msg.Flags = uint32(flags)
|
msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
|
||||||
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
||||||
err = windows.WSARecvMsg(fd.Sysfd, &o.msg, &qty, &o.o, nil)
|
err = windows.WSARecvMsg(fd.Sysfd, &msg, &qty, &o.o, nil)
|
||||||
return qty, err
|
return qty, err
|
||||||
})
|
})
|
||||||
err = fd.eofError(n, err)
|
err = fd.eofError(n, err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rawToSockaddrInet4(o.rsa, sa4)
|
rawToSockaddrInet4(o.rsa, sa4)
|
||||||
}
|
}
|
||||||
return n, int(o.msg.Control.Len), int(o.msg.Flags), err
|
return n, int(msg.Control.Len), int(msg.Flags), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadMsgInet6 is ReadMsg, but specialized to return a syscall.SockaddrInet6.
|
// ReadMsgInet6 is ReadMsg, but specialized to return a syscall.SockaddrInet6.
|
||||||
|
|
@ -1340,22 +1333,21 @@ func (fd *FD) ReadMsgInet6(p []byte, oob []byte, flags int, sa6 *syscall.Sockadd
|
||||||
}
|
}
|
||||||
|
|
||||||
o := &fd.rop
|
o := &fd.rop
|
||||||
o.InitMsg(p, oob)
|
|
||||||
if o.rsa == nil {
|
if o.rsa == nil {
|
||||||
o.rsa = new(syscall.RawSockaddrAny)
|
o.rsa = new(syscall.RawSockaddrAny)
|
||||||
}
|
}
|
||||||
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
msg := newWSAMsg(p, oob, flags)
|
||||||
o.msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
|
msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
||||||
o.msg.Flags = uint32(flags)
|
msg.Namelen = int32(unsafe.Sizeof(*o.rsa))
|
||||||
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
||||||
err = windows.WSARecvMsg(fd.Sysfd, &o.msg, &qty, &o.o, nil)
|
err = windows.WSARecvMsg(fd.Sysfd, &msg, &qty, &o.o, nil)
|
||||||
return qty, err
|
return qty, err
|
||||||
})
|
})
|
||||||
err = fd.eofError(n, err)
|
err = fd.eofError(n, err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rawToSockaddrInet6(o.rsa, sa6)
|
rawToSockaddrInet6(o.rsa, sa6)
|
||||||
}
|
}
|
||||||
return n, int(o.msg.Control.Len), int(o.msg.Flags), err
|
return n, int(msg.Control.Len), int(msg.Flags), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMsg wraps the WSASendMsg network call.
|
// WriteMsg wraps the WSASendMsg network call.
|
||||||
|
|
@ -1370,7 +1362,7 @@ func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, err
|
||||||
defer fd.writeUnlock()
|
defer fd.writeUnlock()
|
||||||
|
|
||||||
o := &fd.wop
|
o := &fd.wop
|
||||||
o.InitMsg(p, oob)
|
msg := newWSAMsg(p, oob, 0)
|
||||||
if sa != nil {
|
if sa != nil {
|
||||||
if o.rsa == nil {
|
if o.rsa == nil {
|
||||||
o.rsa = new(syscall.RawSockaddrAny)
|
o.rsa = new(syscall.RawSockaddrAny)
|
||||||
|
|
@ -1379,14 +1371,14 @@ func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
||||||
o.msg.Namelen = len
|
msg.Namelen = len
|
||||||
}
|
}
|
||||||
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
||||||
err = windows.WSASendMsg(fd.Sysfd, &o.msg, 0, nil, &o.o, nil)
|
err = windows.WSASendMsg(fd.Sysfd, &msg, 0, nil, &o.o, nil)
|
||||||
return qty, err
|
return qty, err
|
||||||
})
|
})
|
||||||
return n, int(o.msg.Control.Len), err
|
return n, int(msg.Control.Len), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMsgInet4 is WriteMsg specialized for syscall.SockaddrInet4.
|
// WriteMsgInet4 is WriteMsg specialized for syscall.SockaddrInet4.
|
||||||
|
|
@ -1401,18 +1393,18 @@ func (fd *FD) WriteMsgInet4(p []byte, oob []byte, sa *syscall.SockaddrInet4) (in
|
||||||
defer fd.writeUnlock()
|
defer fd.writeUnlock()
|
||||||
|
|
||||||
o := &fd.wop
|
o := &fd.wop
|
||||||
o.InitMsg(p, oob)
|
|
||||||
if o.rsa == nil {
|
if o.rsa == nil {
|
||||||
o.rsa = new(syscall.RawSockaddrAny)
|
o.rsa = new(syscall.RawSockaddrAny)
|
||||||
}
|
}
|
||||||
len := sockaddrInet4ToRaw(o.rsa, sa)
|
len := sockaddrInet4ToRaw(o.rsa, sa)
|
||||||
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
msg := newWSAMsg(p, oob, 0)
|
||||||
o.msg.Namelen = len
|
msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
||||||
|
msg.Namelen = len
|
||||||
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
||||||
err = windows.WSASendMsg(fd.Sysfd, &o.msg, 0, nil, &o.o, nil)
|
err = windows.WSASendMsg(fd.Sysfd, &msg, 0, nil, &o.o, nil)
|
||||||
return qty, err
|
return qty, err
|
||||||
})
|
})
|
||||||
return n, int(o.msg.Control.Len), err
|
return n, int(msg.Control.Len), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMsgInet6 is WriteMsg specialized for syscall.SockaddrInet6.
|
// WriteMsgInet6 is WriteMsg specialized for syscall.SockaddrInet6.
|
||||||
|
|
@ -1427,18 +1419,18 @@ func (fd *FD) WriteMsgInet6(p []byte, oob []byte, sa *syscall.SockaddrInet6) (in
|
||||||
defer fd.writeUnlock()
|
defer fd.writeUnlock()
|
||||||
|
|
||||||
o := &fd.wop
|
o := &fd.wop
|
||||||
o.InitMsg(p, oob)
|
|
||||||
if o.rsa == nil {
|
if o.rsa == nil {
|
||||||
o.rsa = new(syscall.RawSockaddrAny)
|
o.rsa = new(syscall.RawSockaddrAny)
|
||||||
}
|
}
|
||||||
|
msg := newWSAMsg(p, oob, 0)
|
||||||
len := sockaddrInet6ToRaw(o.rsa, sa)
|
len := sockaddrInet6ToRaw(o.rsa, sa)
|
||||||
o.msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
msg.Name = (syscall.Pointer)(unsafe.Pointer(o.rsa))
|
||||||
o.msg.Namelen = len
|
msg.Namelen = len
|
||||||
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
n, err := fd.execIO(o, func(o *operation) (qty uint32, err error) {
|
||||||
err = windows.WSASendMsg(fd.Sysfd, &o.msg, 0, nil, &o.o, nil)
|
err = windows.WSASendMsg(fd.Sysfd, &msg, 0, nil, &o.o, nil)
|
||||||
return qty, err
|
return qty, err
|
||||||
})
|
})
|
||||||
return n, int(o.msg.Control.Len), err
|
return n, int(msg.Control.Len), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func DupCloseOnExec(fd int) (int, string, error) {
|
func DupCloseOnExec(fd int) (int, string, error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue