forked from quic-go/quic-go
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:
22
stream.go
22
stream.go
@@ -20,11 +20,10 @@ type streamI interface {
|
||||
AddStreamFrame(*wire.StreamFrame) error
|
||||
RegisterRemoteError(error, protocol.ByteCount) error
|
||||
HasDataForWriting() bool
|
||||
GetDataForWriting(maxBytes protocol.ByteCount) []byte
|
||||
GetDataForWriting(maxBytes protocol.ByteCount) (data []byte, shouldSendFin bool)
|
||||
GetWriteOffset() protocol.ByteCount
|
||||
Finished() bool
|
||||
Cancel(error)
|
||||
ShouldSendFin() bool
|
||||
SentFin()
|
||||
// methods needed for flow control
|
||||
GetWindowUpdate() protocol.ByteCount
|
||||
@@ -266,17 +265,19 @@ func (s *stream) GetWriteOffset() protocol.ByteCount {
|
||||
// HasDataForWriting says if there's stream available to be dequeued for writing
|
||||
func (s *stream) HasDataForWriting() bool {
|
||||
s.mutex.Lock()
|
||||
hasData := s.err == nil && len(s.dataForWriting) > 0
|
||||
hasData := s.err == nil && // nothing should be sent if an error occurred
|
||||
(len(s.dataForWriting) > 0 || // there is data queued for sending
|
||||
s.finishedWriting.Get() && !s.finSent.Get()) // if there is no data, but writing finished and the FIN hasn't been sent yet
|
||||
s.mutex.Unlock()
|
||||
return hasData
|
||||
}
|
||||
|
||||
func (s *stream) GetDataForWriting(maxBytes protocol.ByteCount) []byte {
|
||||
func (s *stream) GetDataForWriting(maxBytes protocol.ByteCount) ([]byte, bool /* should send FIN */) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
if s.err != nil || s.dataForWriting == nil {
|
||||
return nil
|
||||
return nil, s.finishedWriting.Get() && !s.finSent.Get()
|
||||
}
|
||||
|
||||
// TODO(#657): Flow control for the crypto stream
|
||||
@@ -284,7 +285,7 @@ func (s *stream) GetDataForWriting(maxBytes protocol.ByteCount) []byte {
|
||||
maxBytes = utils.MinByteCount(maxBytes, s.flowController.SendWindowSize())
|
||||
}
|
||||
if maxBytes == 0 {
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
|
||||
var ret []byte
|
||||
@@ -298,7 +299,7 @@ func (s *stream) GetDataForWriting(maxBytes protocol.ByteCount) []byte {
|
||||
}
|
||||
s.writeOffset += protocol.ByteCount(len(ret))
|
||||
s.flowController.AddBytesSent(protocol.ByteCount(len(ret)))
|
||||
return ret
|
||||
return ret, s.finishedWriting.Get() && s.dataForWriting == nil && !s.finSent.Get()
|
||||
}
|
||||
|
||||
// Close implements io.Closer
|
||||
@@ -316,13 +317,6 @@ func (s *stream) shouldSendReset() bool {
|
||||
return (s.resetLocally.Get() || s.resetRemotely.Get()) && !s.finishedWriteAndSentFin()
|
||||
}
|
||||
|
||||
func (s *stream) ShouldSendFin() bool {
|
||||
s.mutex.Lock()
|
||||
res := s.finishedWriting.Get() && !s.finSent.Get() && s.err == nil && s.dataForWriting == nil
|
||||
s.mutex.Unlock()
|
||||
return res
|
||||
}
|
||||
|
||||
func (s *stream) SentFin() {
|
||||
s.finSent.Set(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user