2021-10-21 15:24:11 -06:00
|
|
|
//go:build !e2e_testing
|
2021-03-31 09:26:35 -06:00
|
|
|
// +build !e2e_testing
|
|
|
|
|
2021-11-03 19:54:04 -06:00
|
|
|
package udp
|
2019-11-19 10:00:20 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"syscall"
|
2023-07-10 11:43:48 -06:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2019-11-19 10:00:20 -07:00
|
|
|
)
|
|
|
|
|
2023-07-10 11:43:48 -06:00
|
|
|
func NewListener(l *logrus.Logger, ip net.IP, port int, multi bool, batch int) (Conn, error) {
|
|
|
|
if multi {
|
|
|
|
//NOTE: Technically we can support it with RIO but it wouldn't be at the socket level
|
|
|
|
// The udp stack would need to be reworked to hide away the implementation differences between
|
|
|
|
// Windows and Linux
|
|
|
|
return nil, fmt.Errorf("multiple udp listeners not supported on windows")
|
|
|
|
}
|
|
|
|
|
|
|
|
rc, err := NewRIOListener(l, ip, port)
|
|
|
|
if err == nil {
|
|
|
|
return rc, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
l.WithError(err).Error("Falling back to standard udp sockets")
|
|
|
|
return NewGenericListener(l, ip, port, multi, batch)
|
|
|
|
}
|
|
|
|
|
2019-11-19 10:00:20 -07:00
|
|
|
func NewListenConfig(multi bool) net.ListenConfig {
|
|
|
|
return net.ListenConfig{
|
|
|
|
Control: func(network, address string, c syscall.RawConn) error {
|
|
|
|
if multi {
|
|
|
|
// There is no way to support multiple listeners safely on Windows:
|
|
|
|
// https://docs.microsoft.com/en-us/windows/desktop/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
|
|
|
|
return fmt.Errorf("multiple udp listeners not supported on windows")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 12:48:58 -06:00
|
|
|
|
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
|
|
|
}
|