remove the ShouldSendFin method from the stream

GetDataForWriting now has two return parameters: the data and if a FIN
should be sent.
This commit is contained in:
Marten Seemann 2017-12-07 19:13:21 +07:00
parent 085624be20
commit 71af5758e2
5 changed files with 67 additions and 83 deletions

View file

@ -67,7 +67,7 @@ func (f *streamFramer) PopCryptoStreamFrame(maxLen protocol.ByteCount) *wire.Str
Offset: f.cryptoStream.GetWriteOffset(),
}
frameHeaderBytes, _ := frame.MinLength(f.version) // can never error
frame.Data = f.cryptoStream.GetDataForWriting(maxLen - frameHeaderBytes)
frame.Data, frame.FinBit = f.cryptoStream.GetDataForWriting(maxLen - frameHeaderBytes)
return frame
}
@ -115,24 +115,16 @@ func (f *streamFramer) maybePopNormalFrames(maxBytes protocol.ByteCount) (res []
}
maxLen := maxBytes - currentLen - frameHeaderBytes
var data []byte
if s.HasDataForWriting() {
data = s.GetDataForWriting(maxLen)
frame.Data, frame.FinBit = s.GetDataForWriting(maxLen)
}
// This is unlikely, but check it nonetheless, the scheduler might have jumped in. Seems to happen in ~20% of cases in the tests.
shouldSendFin := s.ShouldSendFin()
if data == nil && !shouldSendFin {
if len(frame.Data) == 0 && !frame.FinBit {
return true, nil
}
if shouldSendFin {
frame.FinBit = true
if frame.FinBit {
s.SentFin()
}
frame.Data = data
// Finally, check if we are now FC blocked and should queue a BLOCKED frame
if !frame.FinBit && s.IsFlowControlBlocked() {
f.blockedFrameQueue = append(f.blockedFrameQueue, &wire.StreamBlockedFrame{StreamID: s.StreamID()})