1
0
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:
Kslr 2019-10-19 12:19:09 +08:00 committed by GitHub
commit d0ac3e9d8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {