forked from quic-go/quic-go
minor stream optimizations
This commit is contained in:
13
stream.go
13
stream.go
@@ -143,7 +143,6 @@ func (s *stream) ReadByte() (byte, error) {
|
||||
|
||||
func (s *stream) Write(p []byte) (int, error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
s.dataForWriting = make([]byte, len(p))
|
||||
copy(s.dataForWriting, p)
|
||||
@@ -154,6 +153,7 @@ func (s *stream) Write(p []byte) (int, error) {
|
||||
s.doneWritingOrErrCond.Wait()
|
||||
}
|
||||
|
||||
s.mutex.Unlock()
|
||||
if s.err != nil {
|
||||
return 0, s.err
|
||||
}
|
||||
@@ -162,8 +162,9 @@ func (s *stream) Write(p []byte) (int, error) {
|
||||
|
||||
func (s *stream) lenOfDataForWriting() protocol.ByteCount {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
return protocol.ByteCount(len(s.dataForWriting))
|
||||
l := protocol.ByteCount(len(s.dataForWriting))
|
||||
s.mutex.Unlock()
|
||||
return l
|
||||
}
|
||||
|
||||
func (s *stream) getDataForWriting(maxBytes protocol.ByteCount) []byte {
|
||||
@@ -194,9 +195,9 @@ func (s *stream) Close() error {
|
||||
|
||||
func (s *stream) shouldSendFin() bool {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
closed := atomic.LoadInt32(&s.closed) != 0
|
||||
return closed && !s.finSent && s.err == nil && s.dataForWriting == nil
|
||||
res := atomic.LoadInt32(&s.closed) != 0 && !s.finSent && s.err == nil && s.dataForWriting == nil
|
||||
s.mutex.Unlock()
|
||||
return res
|
||||
}
|
||||
|
||||
func (s *stream) sentFin() {
|
||||
|
||||
Reference in New Issue
Block a user