Source file src/vendor/golang.org/x/net/quic/ack_delay.go

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package quic
     6  
     7  import (
     8  	"math"
     9  	"time"
    10  )
    11  
    12  // An unscaledAckDelay is an ACK Delay field value from an ACK packet,
    13  // without the ack_delay_exponent scaling applied.
    14  type unscaledAckDelay int64
    15  
    16  func unscaledAckDelayFromDuration(d time.Duration, ackDelayExponent uint8) unscaledAckDelay {
    17  	return unscaledAckDelay(d.Microseconds() >> ackDelayExponent)
    18  }
    19  
    20  func (d unscaledAckDelay) Duration(ackDelayExponent uint8) time.Duration {
    21  	if int64(d) > (math.MaxInt64>>ackDelayExponent)/int64(time.Microsecond) {
    22  		// If scaling the delay would overflow, ignore the delay.
    23  		return 0
    24  	}
    25  	return time.Duration(d<<ackDelayExponent) * time.Microsecond
    26  }
    27  

View as plain text