Kaynağa Gözat

Record actual copied length (#107)

This allows properly recording partial reads in receive window on connection break

Partially addresses #94
Jeff Mitchell 2 yıl önce
ebeveyn
işleme
7eb05715ff
1 değiştirilmiş dosya ile 3 ekleme ve 2 silme
  1. 3 2
      stream.go

+ 3 - 2
stream.go

@@ -488,14 +488,15 @@ func (s *Stream) readData(hdr header, flags uint16, conn io.Reader) error {
 		// This way we can read in the whole packet without further allocations.
 		s.recvBuf = bytes.NewBuffer(make([]byte, 0, length))
 	}
-	if _, err := io.Copy(s.recvBuf, conn); err != nil {
+	copiedLength, err := io.Copy(s.recvBuf, conn)
+	if err != nil {
 		s.session.logger.Printf("[ERR] yamux: Failed to read stream data: %v", err)
 		s.recvLock.Unlock()
 		return err
 	}
 
 	// Decrement the receive window
-	s.recvWindow -= length
+	s.recvWindow -= uint32(copiedLength)
 	s.recvLock.Unlock()
 
 	// Unblock any readers