1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

Move setting of SO_REUSEPORT out of applyInboundSocketOptions

This commit is contained in:
Vigilans 2020-07-31 00:01:36 +08:00
parent 541fb5c5b1
commit bb932d8a1e
2 changed files with 9 additions and 12 deletions

View File

@ -16,11 +16,11 @@ const (
func bindAddr(fd uintptr, ip []byte, port uint32) error {
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()
return newError("failed to set SO_REUSEADDR").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()
return newError("failed to set SO_REUSEPORT").Base(err).AtWarning()
}
var sockaddr syscall.Sockaddr
@ -107,9 +107,5 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
}
}
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
return newError("failed to set SO_REUSEPORT").Base(err).AtWarning()
}
return nil
}

View File

@ -4,6 +4,7 @@ import (
"context"
"syscall"
"golang.org/x/sys/unix"
"v2ray.com/core/common/net"
"v2ray.com/core/common/session"
)
@ -27,6 +28,10 @@ func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []co
}
}
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
newError("failed to set SO_REUSEPORT").Base(err).AtWarning()
}
for _, controller := range controllers {
if err := controller(network, address, fd); err != nil {
newError("failed to apply external controller").Base(err).WriteToLog(session.ExportIDToError(ctx))
@ -39,9 +44,7 @@ func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []co
func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.Listener, error) {
var lc net.ListenConfig
if sockopt != nil || len(dl.controllers) > 0 {
lc.Control = getControlFunc(ctx, sockopt, dl.controllers)
}
lc.Control = getControlFunc(ctx, sockopt, dl.controllers)
return lc.Listen(ctx, addr.Network(), addr.String())
}
@ -49,9 +52,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
func (dl *DefaultListener) ListenPacket(ctx context.Context, addr net.Addr, sockopt *SocketConfig) (net.PacketConn, error) {
var lc net.ListenConfig
if sockopt != nil || len(dl.controllers) > 0 {
lc.Control = getControlFunc(ctx, sockopt, dl.controllers)
}
lc.Control = getControlFunc(ctx, sockopt, dl.controllers)
return lc.ListenPacket(ctx, addr.Network(), addr.String())
}