don't set RTO and small packet timeout when we can't actually send

fixes #126
This commit is contained in:
Lucas Clemente
2016-05-19 14:24:21 +02:00
parent bd6d893cc4
commit f96282b4d4

View File

@@ -138,12 +138,16 @@ func (s *Session) run() {
now := time.Now()
firstTimeout := utils.InfDuration
// Small packet send delay
if !s.smallPacketDelayedOccurranceTime.IsZero() {
firstTimeout = utils.MinDuration(firstTimeout, s.smallPacketDelayedOccurranceTime.Add(protocol.SmallPacketSendDelay).Sub(now))
// Some timeouts are only set when we can actually send
// Note: if a packet arrives, we go through this again afterwards.
if s.sentPacketHandler.AllowsSending() {
// Small packet send delay
if !s.smallPacketDelayedOccurranceTime.IsZero() {
firstTimeout = utils.MinDuration(firstTimeout, s.smallPacketDelayedOccurranceTime.Add(protocol.SmallPacketSendDelay).Sub(now))
}
// RTOs
firstTimeout = utils.MinDuration(firstTimeout, s.sentPacketHandler.TimeToFirstRTO())
}
// RTOs
firstTimeout = utils.MinDuration(firstTimeout, s.sentPacketHandler.TimeToFirstRTO())
// Idle connection timeout
firstTimeout = utils.MinDuration(firstTimeout, s.lastNetworkActivityTime.Add(s.connectionParametersManager.GetIdleConnectionStateLifetime()).Sub(now))
@@ -389,6 +393,10 @@ func (s *Session) closeStreamsWithError(err error) {
// TODO: try sending more than one packet
func (s *Session) maybeSendPacket() error {
if time.Now().Sub(s.smallPacketDelayedOccurranceTime) > protocol.SmallPacketSendDelay {
return s.sendPacket()
}
if !s.sentPacketHandler.AllowsSending() {
return nil
}
@@ -432,14 +440,12 @@ func (s *Session) maybeSendPacket() error {
s.smallPacketDelayedOccurranceTime = time.Now()
}
if time.Now().Sub(s.smallPacketDelayedOccurranceTime) > protocol.SmallPacketSendDelay {
return s.sendPacket()
}
return nil
}
func (s *Session) sendPacket() error {
s.smallPacketDelayedOccurranceTime = time.Time{} // zero
if !s.sentPacketHandler.AllowsSending() {
return nil
}
@@ -483,8 +489,6 @@ func (s *Session) sendPacket() error {
return nil
}
s.smallPacketDelayedOccurranceTime = time.Time{} // zero
err = s.sentPacketHandler.SentPacket(&ackhandler.Packet{
PacketNumber: packet.number,
Frames: packet.frames,