udp_bsd.go 1.0 KB

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