claude implements UDP GRO

This commit is contained in:
Jay Wren
2026-02-04 11:02:06 -05:00
parent 6b6a4bc1cc
commit 030b7e2763
8 changed files with 183 additions and 21 deletions

View File

@@ -33,13 +33,26 @@ type rawMessage struct {
Pad0 [4]byte
}
func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte, [][]byte) {
msgs := make([]rawMessage, n)
buffers := make([][]byte, n)
names := make([][]byte, n)
controls := make([][]byte, n)
// Use larger buffers if GRO is enabled to hold coalesced packets
bufSize := MTU
if u.groSupported {
bufSize = groMaxPacketSize
}
// Control buffer size for receiving UDP_GRO segment size
controlSize := 0
if u.groSupported {
controlSize = unix.CmsgSpace(2) // space for uint16 segment size
}
for i := range msgs {
buffers[i] = make([]byte, MTU)
buffers[i] = make([]byte, bufSize)
names[i] = make([]byte, unix.SizeofSockaddrInet6)
vs := []iovec{
@@ -51,9 +64,16 @@ func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
msgs[i].Hdr.Name = &names[i][0]
msgs[i].Hdr.Namelen = uint32(len(names[i]))
// Set up control message buffer for GRO
if controlSize > 0 {
controls[i] = make([]byte, controlSize)
msgs[i].Hdr.Control = &controls[i][0]
msgs[i].Hdr.Controllen = uint64(controlSize)
}
}
return msgs, buffers, names
return msgs, buffers, names, controls
}
func setIovecBase(iov *iovec, base *byte) {
@@ -71,3 +91,7 @@ func setMsghdrIovlen(hdr *msghdr, l int) {
func setMsghdrControllen(hdr *msghdr, l int) {
hdr.Controllen = uint64(l)
}
func getMsghdrControllen(hdr *msghdr) int {
return int(hdr.Controllen)
}