Fix canceler.PacketConn

This commit is contained in:
dyhkwong 2024-04-09 22:06:25 +08:00 committed by GitHub
parent 10f242e3c9
commit c88be7da10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -21,13 +21,13 @@ type TimerPacketConn struct {
instance *Instance instance *Instance
} }
func NewPacketConn(ctx context.Context, conn N.PacketConn, timeout time.Duration) (context.Context, 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 timeout < oldTimeout {
timeoutConn.SetTimeout(timeout) timeoutConn.SetTimeout(timeout)
} }
return ctx, timeoutConn return ctx, conn
} }
err := conn.SetReadDeadline(time.Time{}) err := conn.SetReadDeadline(time.Time{})
if err == nil { if err == nil {