Explorar el Código

Add SO_REUSEPORT (kernel level load balance) support

nullptr hace 6 años
padre
commit
ed1ade4266
Se han modificado 1 ficheros con 6 adiciones y 2 borrados
  1. 6 2
      transport/internet/sockopt_linux.go

+ 6 - 2
transport/internet/sockopt_linux.go

@@ -3,6 +3,7 @@ package internet
 import (
 	"net"
 	"syscall"
+	"golang.org/x/sys/unix"
 )
 
 const (
@@ -13,11 +14,14 @@ const (
 )
 
 func bindAddr(fd uintptr, ip []byte, port uint32) error {
-	err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
-	if err != nil {
+	if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1); err != nil {
 		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
 
 	switch len(ip) {