优化网关转发性能

This commit is contained in:
2026-06-23 12:17:13 +08:00
parent b46d057b80
commit ca9241595e
8 changed files with 645 additions and 73 deletions

View File

@@ -14,11 +14,12 @@ func haProxyUpstream(source net.Conn, host string) net.Conn {
return nil
}
conn, err := net.DialTCP("tcp", nil, target)
conn, err := tcpDialer.Dial("tcp", target.String())
if err != nil {
log.Err(err).Msg("failed to dial TCP")
return nil
}
setSocketOptions(conn)
sourceAddr, err := net.ResolveTCPAddr(
source.RemoteAddr().Network(),
@@ -26,6 +27,7 @@ func haProxyUpstream(source net.Conn, host string) net.Conn {
)
if err != nil {
log.Err(err).Msg("failed to resolve TCP address")
conn.Close()
return nil
}
@@ -45,6 +47,7 @@ func haProxyUpstream(source net.Conn, host string) net.Conn {
_, err = header.WriteTo(conn)
if err != nil {
log.Err(err).Msg("failed to write proxy header")
conn.Close()
return nil
}