Browse Source

Add SO_REUSEPORT (kernel level load balance) support

pull/1940/head
nullptr 5 years ago
parent
commit
ed1ade4266
  1. 8
      transport/internet/sockopt_linux.go

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

Loading…
Cancel
Save