github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/tcp/stream-timing-delayed_acknowledgment.go (about) 1 /* For license and copyright information please see the LEGAL file in the code repository */ 2 3 package tcp 4 5 import ( 6 "github.com/GeniusesGroup/libgo/protocol" 7 "github.com/GeniusesGroup/libgo/time/monotonic" 8 ) 9 10 type delayedAcknowledgment struct { 11 enable bool 12 interval protocol.Duration 13 nextCheck monotonic.Time 14 } 15 16 func (da *delayedAcknowledgment) Init(now monotonic.Time) (next protocol.Duration) { 17 da.enable = true 18 now.Add(DelayedAcknowledgment_Timeout) 19 da.nextCheck = now 20 return 21 } 22 func (da *delayedAcknowledgment) Reinit() { 23 } 24 func (da *delayedAcknowledgment) Deinit() {} 25 26 // Don't block the caller 27 func (da *delayedAcknowledgment) CheckInterval(s *Stream, now monotonic.Time) (next protocol.Duration) { 28 if !da.enable { 29 return -1 30 } 31 32 // TODO::: check stream state 33 34 next = da.next(now) 35 if next > 0 { 36 return 37 } 38 39 // TODO::: 40 41 return 42 } 43 44 // d can be negative that show ka.CheckInterval called with some delay 45 func (da *delayedAcknowledgment) next(now monotonic.Time) (d protocol.Duration) { 46 d = da.nextCheck.Until(now) 47 return 48 }