Skip to content

Commit bb13814

Browse files
authored
fix: adjust UDP buffer size and update read timeout for improved performance
1 parent 2115fc5 commit bb13814

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type Common struct {
6565
// 配置变量,可通过环境变量调整
6666
var (
6767
semaphoreLimit = getEnvAsInt("NP_SEMAPHORE_LIMIT", 1024) // 信号量限制
68-
udpDataBufSize = getEnvAsInt("NP_UDP_DATA_BUF_SIZE", 8192) // UDP缓冲区大小
68+
udpDataBufSize = getEnvAsInt("NP_UDP_DATA_BUF_SIZE", 2048) // UDP缓冲区大小
6969
handshakeTimeout = getEnvAsDuration("NP_HANDSHAKE_TIMEOUT", 10*time.Second) // 握手超时
7070
tcpDialTimeout = getEnvAsDuration("NP_TCP_DIAL_TIMEOUT", 30*time.Second) // TCP拨号超时
7171
udpDialTimeout = getEnvAsDuration("NP_UDP_DIAL_TIMEOUT", 10*time.Second) // UDP拨号超时
@@ -241,7 +241,7 @@ func (c *Common) getReadTimeout(parsedURL *url.URL) {
241241
c.readTimeout = value
242242
}
243243
} else {
244-
c.readTimeout = 10 * time.Minute
244+
c.readTimeout = 1 * time.Hour
245245
}
246246
}
247247

@@ -1253,7 +1253,7 @@ func (c *Common) singleTCPLoop() error {
12531253

12541254
// 交换数据
12551255
c.logger.Debug("Starting exchange: %v <-> %v", tunnelConn.LocalAddr(), targetConn.LocalAddr())
1256-
c.logger.Debug("Exchange complete: %v", conn.DataExchange(tunnelConn, targetConn, 0))
1256+
c.logger.Debug("Exchange complete: %v", conn.DataExchange(tunnelConn, targetConn, c.readTimeout))
12571257
}(tunnelConn)
12581258
}
12591259
}
@@ -1335,7 +1335,7 @@ func (c *Common) singleUDPLoop() error {
13351335

13361336
buffer := getUDPBuffer()
13371337
defer putUDPBuffer(buffer)
1338-
reader := &conn.TimeoutReader{Conn: targetConn, Timeout: 0}
1338+
reader := &conn.TimeoutReader{Conn: targetConn, Timeout: c.readTimeout}
13391339

13401340
for {
13411341
if c.ctx.Err() != nil {

0 commit comments

Comments
 (0)