From 9863e6beaedc19b49a8fe6a31269229debe0aea4 Mon Sep 17 00:00:00 2001 From: "darin%netscape.com" Date: Mon, 1 Apr 2002 05:06:59 +0000 Subject: [PATCH] fixes bug 130301 "Cannot submit large POST requests since Mozilla 0.9.9" r=brade, sr=rpotts, a=asa --- xpcom/io/nsMultiplexInputStream.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/xpcom/io/nsMultiplexInputStream.cpp b/xpcom/io/nsMultiplexInputStream.cpp index 1a278231ff02..6efbfc34b8a9 100644 --- a/xpcom/io/nsMultiplexInputStream.cpp +++ b/xpcom/io/nsMultiplexInputStream.cpp @@ -240,8 +240,13 @@ nsMultiplexInputStream::ReadSegments(nsWriteSegmentFun aWriter, void *aClosure, while (mCurrentStream < len) { nsCOMPtr stream(do_QueryElementAt(&mStreams, mCurrentStream)); - PRUint32 read; - rv = stream->ReadSegments(ReadSegCb, &state, aCount, &read); + PRUint32 avail, read, count; + rv = stream->Available(&avail); + if (NS_FAILED(rv)) return rv; + + count = PR_MIN(avail, aCount); + + rv = stream->ReadSegments(ReadSegCb, &state, count, &read); // If we got an NS_BASE_STREAM_WOULD_BLOCK error since the reader // didn't want any more data. This might not be an error for us if // data was read from a previous stream in this run @@ -250,11 +255,17 @@ nsMultiplexInputStream::ReadSegments(nsWriteSegmentFun aWriter, void *aClosure, break; NS_ENSURE_SUCCESS(rv, rv); - NS_ASSERTION(aCount >= read, "Read more then requested"); + if (read > count) { + NS_ERROR("Read more than requested"); + read = count; // truncate and hope for the best... + } mStartedReadingCurrent = PR_TRUE; state.mOffset += read; + count -= read; aCount -= read; - if (state.mDone || !aCount) + if (state.mDone || // writer doesn't want anymore data + aCount == 0 || // already read total amount requested + count > 0) // the current stream still has data break; ++mCurrentStream;