Fix set timeout

This commit is contained in:
世界 2024-11-27 17:28:18 +08:00
parent c44912a861
commit 4ba1eb123c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -24,7 +24,7 @@ type TimerPacketConn struct {
func NewPacketConn(ctx context.Context, conn N.PacketConn, timeout time.Duration) (context.Context, N.PacketConn) { func NewPacketConn(ctx context.Context, conn N.PacketConn, timeout time.Duration) (context.Context, N.PacketConn) {
if timeoutConn, isTimeoutConn := common.Cast[PacketConn](conn); isTimeoutConn { if timeoutConn, isTimeoutConn := common.Cast[PacketConn](conn); isTimeoutConn {
oldTimeout := timeoutConn.Timeout() oldTimeout := timeoutConn.Timeout()
if timeout >= oldTimeout { if oldTimeout > 0 && timeout >= oldTimeout {
return ctx, conn return ctx, conn
} }
if timeoutConn.SetTimeout(timeout) { if timeoutConn.SetTimeout(timeout) {