This commit is contained in:
gospider
2025-02-21 16:36:32 +08:00
parent a31eb9ed6a
commit 5e4c6cfb35
11 changed files with 515 additions and 321 deletions

View File

@@ -10,6 +10,7 @@ import (
"net/http"
"net/url"
"sync"
"syscall"
"time"
"github.com/gospider007/gtls"
@@ -61,6 +62,14 @@ func newDialer(option DialOption) dialer {
KeepAlive: option.KeepAlive,
LocalAddr: option.LocalAddr,
FallbackDelay: time.Nanosecond,
Control: func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) // 启用地址重用
syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEPORT, 1) // 启用端口重用
syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, syscall.TCP_NODELAY, 1)
syscall.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{Onoff: 1, Linger: 0})
})
},
KeepAliveConfig: net.KeepAliveConfig{
Enable: true,
Idle: time.Second * 5,