反向代理实现AutoFlush/修复配置自动加载问题

This commit is contained in:
GoEdgeLab
2020-09-27 18:41:56 +08:00
parent ee2281b581
commit 6f3d688ece
14 changed files with 101 additions and 23 deletions

24
internal/utils/net.go Normal file
View File

@@ -0,0 +1,24 @@
package utils
import (
"context"
"github.com/iwind/TeaGo/logs"
"net"
"syscall"
)
// 监听可重用的端口
func ListenReuseAddr(network string, addr string) (net.Listener, error) {
config := &net.ListenConfig{
Control: func(network, address string, c syscall.RawConn) error {
return c.Control(func(fd uintptr) {
err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, SO_REUSEPORT, 1)
if err != nil {
logs.Println("[LISTEN]" + err.Error())
}
})
},
KeepAlive: 0,
}
return config.Listen(context.Background(), network, addr)
}