mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 15:20:30 +00:00
Merge pull request #223 from neilalexander/reusemulticast
Try to SO_REUSEPORT on multicast socket
This commit is contained in:
commit
09228554cb
@ -1,6 +1,7 @@
|
||||
package yggdrasil
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
@ -35,7 +36,10 @@ func (m *multicast) start() error {
|
||||
return err
|
||||
}
|
||||
listenString := fmt.Sprintf("[::]:%v", addr.Port)
|
||||
conn, err := net.ListenPacket("udp6", listenString)
|
||||
lc := net.ListenConfig{
|
||||
Control: multicastReuse,
|
||||
}
|
||||
conn, err := lc.ListenPacket(context.Background(), "udp6", listenString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
9
src/yggdrasil/multicast_other.go
Normal file
9
src/yggdrasil/multicast_other.go
Normal file
@ -0,0 +1,9 @@
|
||||
// +build !linux,!darwin,!netbsd,!freebsd,!openbsd,!dragonflybsd,!windows
|
||||
|
||||
package yggdrasil
|
||||
|
||||
import "syscall"
|
||||
|
||||
func multicastReuse(network string, address string, c syscall.RawConn) error {
|
||||
return nil
|
||||
}
|
22
src/yggdrasil/multicast_unix.go
Normal file
22
src/yggdrasil/multicast_unix.go
Normal file
@ -0,0 +1,22 @@
|
||||
// +build linux darwin netbsd freebsd openbsd dragonflybsd
|
||||
|
||||
package yggdrasil
|
||||
|
||||
import "syscall"
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
func multicastReuse(network string, address string, c syscall.RawConn) error {
|
||||
var control error
|
||||
var reuseport error
|
||||
|
||||
control = c.Control(func(fd uintptr) {
|
||||
reuseport = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
||||
})
|
||||
|
||||
switch {
|
||||
case reuseport != nil:
|
||||
return reuseport
|
||||
default:
|
||||
return control
|
||||
}
|
||||
}
|
22
src/yggdrasil/multicast_windows.go
Normal file
22
src/yggdrasil/multicast_windows.go
Normal file
@ -0,0 +1,22 @@
|
||||
// +build windows
|
||||
|
||||
package yggdrasil
|
||||
|
||||
import "syscall"
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
func multicastReuse(network string, address string, c syscall.RawConn) error {
|
||||
var control error
|
||||
var reuseaddr error
|
||||
|
||||
control = c.Control(func(fd uintptr) {
|
||||
reuseaddr = windows.SetsockoptInt(windows.Handle(fd), windows.SOL_SOCKET, windows.SO_REUSEADDR, 1)
|
||||
})
|
||||
|
||||
switch {
|
||||
case reuseaddr != nil:
|
||||
return reuseaddr
|
||||
default:
|
||||
return control
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user