Bug 1435899 - Close underlying stream in NonBlockingAsyncInputStream sooner. r=froydnj
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 27 Feb 2018 02:03:00 -0500
changeset 507150 5461b62599d722d0c78b8f212653817d2d718362
parent 507146 b599964cc3ee9182a50a4ed38996cef6fe87c13a
child 507151 c4029bc621f59edca2c3e0011ca50747be81b2c7
push id1905
push userffxbld-merge
push dateMon, 21 Jan 2019 12:33:13 +0000
treeherdermozilla-release@c2fca1944d8c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1435899
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1435899 - Close underlying stream in NonBlockingAsyncInputStream sooner. r=froydnj
xpcom/io/NonBlockingAsyncInputStream.cpp
--- a/xpcom/io/NonBlockingAsyncInputStream.cpp
+++ b/xpcom/io/NonBlockingAsyncInputStream.cpp
@@ -173,17 +173,29 @@ NonBlockingAsyncInputStream::Close()
   return NS_OK;
 }
 
 // nsIInputStream interface
 
 NS_IMETHODIMP
 NonBlockingAsyncInputStream::Available(uint64_t* aLength)
 {
-  return mInputStream->Available(aLength);
+  nsresult rv = mInputStream->Available(aLength);
+  if (NS_WARN_IF(NS_FAILED(rv))) {
+    return rv;
+  }
+
+  // Nothing more to read. Let's close the stream now.
+  if (*aLength == 0) {
+    mInputStream->Close();
+    mClosed = true;
+    return NS_BASE_STREAM_CLOSED;
+  }
+
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 NonBlockingAsyncInputStream::Read(char* aBuffer, uint32_t aCount,
                                   uint32_t* aReadCount)
 {
   return mInputStream->Read(aBuffer, aCount, aReadCount);
 }