mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-04 09:17:32 -05:00
Merge pull request #1940 from enihcam/master
Add SO_REUSEPORT (kernel level load balance) support
This commit is contained in:
commit
d0ac3e9d8e
@ -3,6 +3,7 @@ package internet
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -13,11 +14,14 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
func bindAddr(fd uintptr, ip []byte, port uint32) error {
|
||||||
err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
|
||||||
if err != nil {
|
|
||||||
return newError("failed to set resuse_addr").Base(err).AtWarning()
|
return newError("failed to set resuse_addr").Base(err).AtWarning()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
|
||||||
|
return newError("failed to set resuse_port").Base(err).AtWarning()
|
||||||
|
}
|
||||||
|
|
||||||
var sockaddr syscall.Sockaddr
|
var sockaddr syscall.Sockaddr
|
||||||
|
|
||||||
switch len(ip) {
|
switch len(ip) {
|
||||||
|
Loading…
Reference in New Issue
Block a user