Skip to content

Commit

Permalink
connection.go: batched OnAck calls
Browse files Browse the repository at this point in the history
  • Loading branch information
cooldogedev committed Oct 11, 2024
1 parent 139bb1d commit 2c228f6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,22 @@ func (c *connection) receive(sequenceID uint32, frames []frame.Frame) (err error
func (c *connection) handle(fr frame.Frame) (err error) {
switch fr := fr.(type) {
case *frame.Acknowledgement:
var ackBytes float64
for i, r := range fr.Ranges {
for j := r[0]; j <= r[1]; j++ {
if entry := c.retransmission.remove(j); entry != nil {
c.cc.OnAck(float64(len(entry.payload)))
ackBytes += float64(len(entry.payload))
if i == len(fr.Ranges)-1 && j == r[1] {
c.rtt.Add(time.Duration(time.Since(entry.timestamp).Nanoseconds()-fr.Delay) * time.Nanosecond)
}
}
}
}

if ackBytes > 0 {
c.cc.OnAck(ackBytes)
}

if fr.Type == frame.AcknowledgementWithGaps {
for _, sequenceID := range frame.GenerateAcknowledgementGaps(fr.Ranges) {
c.retransmission.nack(sequenceID)
Expand Down

0 comments on commit 2c228f6

Please sign in to comment.