Bug 1435899 - Close underlying stream in NonBlockingAsyncInputStream sooner. r=froydnj
☠☠ backed out by 09ecb6d58949 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 27 Feb 2018 02:03:00 -0500
changeset 462437 f22f1ab67c5ace0d966a3f60f7b1e25dfe4ec6c9
parent 462436 8cdf945be534dacae33245106e6718055a80bd7f
child 462438 925adb267211585b0cfd2f6b4e219857ecca7921
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1435899
milestone60.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
@@ -164,17 +164,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);
 }