Debian Codegraph @

udp/udp_bsd.go

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