From 9d93d23e3f0c70717ce0e8a90786cdfecbdacdd2 Mon Sep 17 00:00:00 2001 From: caffix Date: Thu, 1 Feb 2024 22:17:51 -0500 Subject: [PATCH] added the ListenConfig and Setsockopt for additional unix environments --- conn.go | 21 +++++++++++++++++---- xchg.go | 7 ------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/conn.go b/conn.go index 4b5171c..4a39f88 100644 --- a/conn.go +++ b/conn.go @@ -73,9 +73,22 @@ func (c *connections) Add() error { var err error var conn net.PacketConn - if runtime.GOOS == "linux" { - conn, err = c.linuxListenPacket() - } else { + switch runtime.GOOS { + case "android": + fallthrough + case "linux": + fallthrough + case "darwin": + fallthrough + case "freebsd": + fallthrough + case "netbsd": + fallthrough + case "openbsd": + fallthrough + case "solaris": + conn, err = c.unixListenPacket() + default: conn, err = net.ListenPacket("udp", ":0") } @@ -87,7 +100,7 @@ func (c *connections) Add() error { return err } -func (c *connections) linuxListenPacket() (net.PacketConn, error) { +func (c *connections) unixListenPacket() (net.PacketConn, error) { lc := net.ListenConfig{ Control: func(network, address string, c syscall.RawConn) error { var operr error diff --git a/xchg.go b/xchg.go index 0e6f494..0504f2d 100644 --- a/xchg.go +++ b/xchg.go @@ -62,13 +62,6 @@ func xchgKey(id uint16, name string) string { return fmt.Sprintf("%d:%s", id, strings.ToLower(RemoveLastDot(name))) } -func (r *xchgMgr) len() int { - r.Lock() - defer r.Unlock() - - return len(r.xchgs) -} - func (r *xchgMgr) setTimeout(d time.Duration) { r.Lock() defer r.Unlock()