Merge inbound to mozilla-central. a=merge
authorNoemi Erli <nerli@mozilla.com>
Mon, 18 Jun 2018 12:02:20 +0300
changeset 479541 f804cc575bba9c6dcb4e3770f7dafe4d8934e73c
parent 479539 628bd444ead118e3c634f5ec135313e76023f384 (current diff)
parent 479540 61882e8a3cf3ffe6a23f90f54d6cd6091f0b6544 (diff)
child 479542 b73265d537e68d57c35846e581624b98e6ec6331
child 479544 5eb03fb6bb4fa39b3b22ac18eab3509992fd9f5b
child 479552 4e6031a71ca31be8bd3a8e0241735233e297df58
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone62.0a1
first release with
nightly linux32
f804cc575bba / 62.0a1 / 20180618100844 / files
nightly linux64
f804cc575bba / 62.0a1 / 20180618100844 / files
nightly mac
f804cc575bba / 62.0a1 / 20180618100844 / files
nightly win32
f804cc575bba / 62.0a1 / 20180618100844 / files
nightly win64
f804cc575bba / 62.0a1 / 20180618100844 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Merge inbound to mozilla-central. a=merge
--- a/netwerk/base/nsNetUtil.cpp
+++ b/netwerk/base/nsNetUtil.cpp
@@ -1515,17 +1515,17 @@ NS_NewBufferedInputStream(nsIInputStream
             in.forget(aResult);
         }
     }
     return rv;
 }
 
 namespace {
 
-#define BUFFER_SIZE 4096
+#define BUFFER_SIZE 8192
 
 class BufferWriter final : public Runnable
                          , public nsIInputStreamCallback
 {
 public:
     NS_DECL_ISUPPORTS_INHERITED
 
     BufferWriter(nsIInputStream* aInputStream,
@@ -1673,74 +1673,73 @@ private:
     NS_IMETHOD
     Run() override
     {
         MOZ_ASSERT(mAsyncInputStream);
         MOZ_ASSERT(!mInputStream);
 
         MonitorAutoLock lock(mMonitor);
 
-        if (mCompleted) {
-            return NS_OK;
-        }
-
-        if (mCount == 0) {
-            OperationCompleted(lock, NS_OK);
-            return NS_OK;
-        }
-
-        if (mCount == -1 && !MaybeExpandBufferSize()) {
-            OperationCompleted(lock, NS_ERROR_OUT_OF_MEMORY);
-            return NS_OK;
-        }
-
-        uint64_t offset = mWrittenData;
-        uint64_t length = mCount == -1 ? BUFFER_SIZE : mCount;
-
-        // Let's try to read it directly.
-        uint32_t writtenData;
-        nsresult rv = mAsyncInputStream->ReadSegments(NS_CopySegmentToBuffer,
-                                                     static_cast<char*>(mBuffer) + offset,
-                                                     length, &writtenData);
-
-        // Operation completed.
-        if (NS_SUCCEEDED(rv) && writtenData == 0) {
-            OperationCompleted(lock, NS_OK);
+        while (true) {
+            if (mCompleted) {
+                return NS_OK;
+            }
+
+            if (mCount == 0) {
+                OperationCompleted(lock, NS_OK);
+                return NS_OK;
+            }
+
+            if (mCount == -1 && !MaybeExpandBufferSize()) {
+                OperationCompleted(lock, NS_ERROR_OUT_OF_MEMORY);
+                return NS_OK;
+            }
+
+            uint64_t offset = mWrittenData;
+            uint64_t length = mCount == -1 ? BUFFER_SIZE : mCount;
+
+            // Let's try to read it directly.
+            uint32_t writtenData;
+            nsresult rv = mAsyncInputStream->ReadSegments(NS_CopySegmentToBuffer,
+                                                         static_cast<char*>(mBuffer) + offset,
+                                                         length, &writtenData);
+
+            // Operation completed.
+            if (NS_SUCCEEDED(rv) && writtenData == 0) {
+                OperationCompleted(lock, NS_OK);
+                return NS_OK;
+            }
+
+            // If we succeeded, let's try to read again.
+            if (NS_SUCCEEDED(rv)) {
+                mWrittenData += writtenData;
+                if (mCount != -1) {
+                    MOZ_ASSERT(mCount >= writtenData);
+                    mCount -= writtenData;
+                }
+
+                continue;
+            }
+
+            // Async wait...
+            if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+                rv = mAsyncInputStream->AsyncWait(this, 0, length, mTaskQueue);
+                if (NS_WARN_IF(NS_FAILED(rv))) {
+                    OperationCompleted(lock, rv);
+                }
+                return NS_OK;
+            }
+
+            // Error.
+            OperationCompleted(lock, rv);
             return NS_OK;
         }
 
-        // If we succeeded, let's try to read again.
-        if (NS_SUCCEEDED(rv)) {
-            mWrittenData += writtenData;
-            if (mCount != -1) {
-                MOZ_ASSERT(mCount >= writtenData);
-                mCount -= writtenData;
-            }
-
-            nsCOMPtr<nsIRunnable> runnable = this;
-            rv = mTaskQueue->Dispatch(runnable.forget());
-            if (NS_WARN_IF(NS_FAILED(rv))) {
-                OperationCompleted(lock, rv);
-            }
-
-            return NS_OK;
-        }
-
-        // Async wait...
-        if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
-            rv = mAsyncInputStream->AsyncWait(this, 0, length, mTaskQueue);
-            if (NS_WARN_IF(NS_FAILED(rv))) {
-                OperationCompleted(lock, rv);
-            }
-            return NS_OK;
-        }
-
-        // Error.
-        OperationCompleted(lock, rv);
-        return NS_OK;
+        MOZ_ASSERT_UNREACHABLE("We should not be here");
+        return NS_ERROR_FAILURE;
     }
 
     NS_IMETHOD
     OnInputStreamReady(nsIAsyncInputStream* aStream) override
     {
         MOZ_ASSERT(aStream == mAsyncInputStream);
         // The stream is ready, let's read it again.
         return Run();