Debian Codegraph @

udp/udp_netbsd.go

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