Merge mozilla-central to autoland. a=merge CLOSED TREE
authorNoemi Erli <nerli@mozilla.com>
Mon, 18 Jun 2018 12:06:16 +0300
changeset 422820 5eb03fb6bb4fa39b3b22ac18eab3509992fd9f5b
parent 422819 4a23e67e1d2a863f1465c6eb94d0f7c52a6eebbc (current diff)
parent 422817 f804cc575bba9c6dcb4e3770f7dafe4d8934e73c (diff)
child 422821 4cdab1b804e8038f9844ae71a3769cf88c50ad55
push id34152
push usercsabou@mozilla.com
push dateMon, 18 Jun 2018 15:51:00 +0000
treeherdermozilla-central@97eb512f532b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone62.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
Merge mozilla-central to autoland. a=merge CLOSED TREE
--- 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();