github.com/danielpfeifer02/quic-go-prio-packs@v0.41.0-28/internal/ackhandler/packet.go (about)

     1  package ackhandler
     2  
     3  import (
     4  	"sync"
     5  	"time"
     6  
     7  	"github.com/danielpfeifer02/quic-go-prio-packs/internal/protocol"
     8  )
     9  
    10  // A Packet is a packet
    11  type packet struct {
    12  	SendTime        time.Time
    13  	PacketNumber    protocol.PacketNumber
    14  	StreamFrames    []StreamFrame
    15  	Frames          []Frame
    16  	LargestAcked    protocol.PacketNumber // InvalidPacketNumber if the packet doesn't contain an ACK
    17  	Length          protocol.ByteCount
    18  	EncryptionLevel protocol.EncryptionLevel
    19  
    20  	IsPathMTUProbePacket bool // We don't report the loss of Path MTU probe packets to the congestion controller.
    21  
    22  	includedInBytesInFlight bool
    23  	declaredLost            bool
    24  	skippedPacket           bool
    25  }
    26  
    27  func (p *packet) outstanding() bool {
    28  	return !p.declaredLost && !p.skippedPacket && !p.IsPathMTUProbePacket
    29  }
    30  
    31  var packetPool = sync.Pool{New: func() any { return &packet{} }}
    32  
    33  func getPacket() *packet {
    34  	p := packetPool.Get().(*packet)
    35  	p.PacketNumber = 0
    36  	p.StreamFrames = nil
    37  	p.Frames = nil
    38  	p.LargestAcked = 0
    39  	p.Length = 0
    40  	p.EncryptionLevel = protocol.EncryptionLevel(0)
    41  	p.SendTime = time.Time{}
    42  	p.IsPathMTUProbePacket = false
    43  	p.includedInBytesInFlight = false
    44  	p.declaredLost = false
    45  	p.skippedPacket = false
    46  	return p
    47  }
    48  
    49  // We currently only return Packets back into the pool when they're acknowledged (not when they're lost).
    50  // This simplifies the code, and gives the vast majority of the performance benefit we can gain from using the pool.
    51  func putPacket(p *packet) {
    52  	p.Frames = nil
    53  	p.StreamFrames = nil
    54  	packetPool.Put(p)
    55  }