2021-10-21 15:24:11 -06:00
|
|
|
//go:build !e2e_testing
|
2021-03-26 08:46:30 -06:00
|
|
|
// +build !e2e_testing
|
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
package udp
|
2020-06-30 12:48:58 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
2024-07-31 09:18:56 -06:00
|
|
|
"net/netip"
|
2020-06-30 12:48:58 -06:00
|
|
|
"syscall"
|
|
|
|
|
2023-07-10 11:43:48 -06:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-06-30 12:48:58 -06:00
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
2024-07-31 09:18:56 -06:00
|
|
|
func NewListener(l *logrus.Logger, ip netip.Addr, port int, multi bool, batch int) (Conn, error) {
|
2023-07-10 11:43:48 -06:00
|
|
|
return NewGenericListener(l, ip, port, multi, batch)
|
|
|
|
}
|
|
|
|
|
2020-06-30 12:48:58 -06:00
|
|
|
func NewListenConfig(multi bool) net.ListenConfig {
|
|
|
|
return net.ListenConfig{
|
|
|
|
Control: func(network, address string, c syscall.RawConn) error {
|
|
|
|
if multi {
|
|
|
|
var controlErr error
|
|
|
|
err := c.Control(func(fd uintptr) {
|
|
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
|
|
|
|
controlErr = fmt.Errorf("SO_REUSEPORT failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if controlErr != nil {
|
|
|
|
return controlErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 09:48:52 -06:00
|
|
|
func (u *GenericConn) Rebind() error {
|
2020-09-18 08:20:09 -06:00
|
|
|
return nil
|
2020-06-30 12:48:58 -06:00
|
|
|
}
|