udp_android.go 903 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //go:build !e2e_testing
  2. // +build !e2e_testing
  3. package udp
  4. import (
  5. "fmt"
  6. "net"
  7. "syscall"
  8. "github.com/sirupsen/logrus"
  9. "golang.org/x/sys/unix"
  10. )
  11. func NewListener(l *logrus.Logger, ip net.IP, port int, multi bool, batch int) (Conn, error) {
  12. return NewGenericListener(l, ip, port, multi, batch)
  13. }
  14. func NewListenConfig(multi bool) net.ListenConfig {
  15. return net.ListenConfig{
  16. Control: func(network, address string, c syscall.RawConn) error {
  17. if multi {
  18. var controlErr error
  19. err := c.Control(func(fd uintptr) {
  20. if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
  21. controlErr = fmt.Errorf("SO_REUSEPORT failed: %v", err)
  22. return
  23. }
  24. })
  25. if err != nil {
  26. return err
  27. }
  28. if controlErr != nil {
  29. return controlErr
  30. }
  31. }
  32. return nil
  33. },
  34. }
  35. }
  36. func (u *GenericConn) Rebind() error {
  37. return nil
  38. }