2021-10-21 15:24:11 -06:00
|
|
|
//go:build linux && (386 || amd64p32 || arm || mips || mipsle) && !android && !e2e_testing
|
2019-12-11 11:38:45 -07:00
|
|
|
// +build linux
|
|
|
|
// +build 386 amd64p32 arm mips mipsle
|
2020-06-30 12:48:58 -06:00
|
|
|
// +build !android
|
2021-03-26 08:46:30 -06:00
|
|
|
// +build !e2e_testing
|
2019-12-11 11:38:45 -07:00
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
package udp
|
2019-11-19 10:00:20 -07:00
|
|
|
|
2021-03-18 19:37:24 -06:00
|
|
|
import (
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
2019-11-19 10:00:20 -07:00
|
|
|
|
|
|
|
type iovec struct {
|
|
|
|
Base *byte
|
|
|
|
Len uint32
|
|
|
|
}
|
|
|
|
|
|
|
|
type msghdr struct {
|
|
|
|
Name *byte
|
|
|
|
Namelen uint32
|
|
|
|
Iov *iovec
|
|
|
|
Iovlen uint32
|
|
|
|
Control *byte
|
|
|
|
Controllen uint32
|
|
|
|
Flags int32
|
|
|
|
}
|
|
|
|
|
|
|
|
type rawMessage struct {
|
|
|
|
Hdr msghdr
|
|
|
|
Len uint32
|
|
|
|
}
|
|
|
|
|
2023-06-14 09:48:52 -06:00
|
|
|
func (u *StdConn) PrepareRawMessages(n int) ([]rawMessage, [][]byte, [][]byte) {
|
2019-11-19 10:00:20 -07:00
|
|
|
msgs := make([]rawMessage, n)
|
|
|
|
buffers := make([][]byte, n)
|
|
|
|
names := make([][]byte, n)
|
|
|
|
|
|
|
|
for i := range msgs {
|
2021-11-03 19:54:04 -06:00
|
|
|
buffers[i] = make([]byte, MTU)
|
2021-03-18 19:37:24 -06:00
|
|
|
names[i] = make([]byte, unix.SizeofSockaddrInet6)
|
2019-11-19 10:00:20 -07:00
|
|
|
|
|
|
|
//TODO: this is still silly, no need for an array
|
|
|
|
vs := []iovec{
|
2021-03-18 19:37:24 -06:00
|
|
|
{Base: &buffers[i][0], Len: uint32(len(buffers[i]))},
|
2019-11-19 10:00:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
msgs[i].Hdr.Iov = &vs[0]
|
|
|
|
msgs[i].Hdr.Iovlen = uint32(len(vs))
|
|
|
|
|
2021-03-18 19:37:24 -06:00
|
|
|
msgs[i].Hdr.Name = &names[i][0]
|
2019-11-19 10:00:20 -07:00
|
|
|
msgs[i].Hdr.Namelen = uint32(len(names[i]))
|
|
|
|
}
|
|
|
|
|
|
|
|
return msgs, buffers, names
|
|
|
|
}
|