forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
394c2f6
commit f9871a4
Showing
5 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package aghnet | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"syscall" | ||
) | ||
|
||
// reuseAddrControl is the function to be set to net.ListenConfig.Control. It | ||
// configures the socket to have a reusable port binding. | ||
func reuseAddrControl(network, address string, c syscall.RawConn) (err error) { | ||
cerr := c.Control(func(fd uintptr) { | ||
err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) | ||
}) | ||
if cerr != nil { | ||
return cerr | ||
} | ||
|
||
return err | ||
} | ||
|
||
func listenPacketReusable(network, address string) (c net.PacketConn, err error) { | ||
var lc net.ListenConfig | ||
lc.Control = reuseAddrControl | ||
|
||
return lc.ListenPacket(context.Background(), network, address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
//go:build aix || darwin || dragonfly || freebsd || netbsd || openbsd || solaris | ||
// +build aix darwin dragonfly freebsd netbsd openbsd solaris | ||
|
||
package aghnet | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
// reuseAddrCtrl is the function to be set to net.ListenConfig.Control. It | ||
// configures the socket to have a reusable port binding. | ||
func reuseAddrCtrl(network, address string, c syscall.RawConn) (err error) { | ||
cerr := c.Control(func(fd uintptr) { | ||
err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) | ||
if err != nil { | ||
err = os.NewSyscallError("setsockopt", err) | ||
} | ||
}) | ||
if cerr != nil { | ||
return cerr | ||
} | ||
|
||
return err | ||
} | ||
|
||
func listenPacketReusable(network, address string) (c net.PacketConn, err error) { | ||
var lc net.ListenConfig | ||
lc.Control = reuseAddrCtrl | ||
|
||
return lc.ListenPacket(context.Background(), network, address) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package aghnet | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghos" | ||
) | ||
|
||
func listenPacketReusable(network, address string) (c net.PacketConn, err error) { | ||
return nil, aghos.Unsupported("listening packet reusable") | ||
} |