Skip to content

Commit

Permalink
added the ListenConfig and Setsockopt for additional unix environments
Browse files Browse the repository at this point in the history
  • Loading branch information
caffix committed Feb 2, 2024
1 parent 35ae56a commit 9d93d23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
21 changes: 17 additions & 4 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions xchg.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9d93d23

Please sign in to comment.