diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index 06f4295c50a..2eb09497370 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -449,20 +449,24 @@ public: } NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) { - PRUint32 readCount = 0; - while (mIndex < mSize && aCount > 0) { - *aBuf = mBuffer[mIndex]; - aBuf++; - mIndex++; - readCount++; - aCount--; - } + PRUint32 readCount = PR_MIN(aCount, (mSize-mIndex)); + + nsCRT::memcpy(aBuf, mBuffer+mIndex, readCount); + mIndex += readCount; + *aReadCount = readCount; + return NS_OK; } NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + PRUint32 readCount = PR_MIN(count, (mSize-mIndex)); + + *_retval = 0; + nsresult rv = writer (this, closure, mBuffer+mIndex, mIndex, readCount, _retval); + mIndex += *_retval; + + return rv; } NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { diff --git a/mozilla/layout/xbl/src/nsXBLService.cpp b/mozilla/layout/xbl/src/nsXBLService.cpp index 06f4295c50a..2eb09497370 100644 --- a/mozilla/layout/xbl/src/nsXBLService.cpp +++ b/mozilla/layout/xbl/src/nsXBLService.cpp @@ -449,20 +449,24 @@ public: } NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) { - PRUint32 readCount = 0; - while (mIndex < mSize && aCount > 0) { - *aBuf = mBuffer[mIndex]; - aBuf++; - mIndex++; - readCount++; - aCount--; - } + PRUint32 readCount = PR_MIN(aCount, (mSize-mIndex)); + + nsCRT::memcpy(aBuf, mBuffer+mIndex, readCount); + mIndex += readCount; + *aReadCount = readCount; + return NS_OK; } NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { - return NS_ERROR_NOT_IMPLEMENTED; + PRUint32 readCount = PR_MIN(count, (mSize-mIndex)); + + *_retval = 0; + nsresult rv = writer (this, closure, mBuffer+mIndex, mIndex, readCount, _retval); + mIndex += *_retval; + + return rv; } NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.cpp b/mozilla/netwerk/base/src/nsBufferedStreams.cpp index 1d1f9601930..64207c4143c 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.cpp +++ b/mozilla/netwerk/base/src/nsBufferedStreams.cpp @@ -209,10 +209,27 @@ nsBufferedInputStream::Read(char * buf, PRUint32 count, PRUint32 *result) } NS_IMETHODIMP -nsBufferedInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +nsBufferedInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *result) { - NS_NOTREACHED("ReadSegments"); - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv = NS_OK; + *result = 0; + while (count > 0) { + PRUint32 amt = PR_MIN(count, mFillPoint - mCursor); + if (amt > 0) { + PRUint32 read = 0; + rv = writer (this, closure, mBuffer + mCursor, mCursor, + amt, &read); + if (NS_FAILED(rv)) break; + *result += read; + count -= read; + mCursor += read; + } + else { + rv = Fill(); + if (NS_FAILED(rv)) break; + } + } + return (*result > 0 || rv == NS_BASE_STREAM_CLOSED) ? NS_OK : rv; } NS_IMETHODIMP diff --git a/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp b/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp index 6351c393788..f6c21f32676 100644 --- a/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp +++ b/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp @@ -1241,9 +1241,41 @@ public: return NS_OK; } + typedef struct { + InterceptStreamListener* me; + nsWriteSegmentFun mWriter; + void* mClosure; + } IntercepterWriterStruct; + + static NS_METHOD IntercepterWriter(nsIInputStream* in, + void* closure, + const char* fromRawSegment, + PRUint32 toOffset, + PRUint32 count, + PRUint32 *writeCount) { + IntercepterWriterStruct* iws = (IntercepterWriterStruct*)closure; + nsresult rv; + + rv = iws->mWriter (in, iws->mClosure, fromRawSegment, + toOffset, count, writeCount); + if (NS_FAILED(rv)) return rv; + + rv = iws->me->write(fromRawSegment, count); + + // If the cache fills up, mark entry as partial content + if (NS_FAILED(rv)) + iws->me->mCacheEntry->SetFlag(nsCachedNetData::TRUNCATED_CONTENT); + return NS_OK; + } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { - NS_NOTREACHED("ReadSegments"); - return NS_ERROR_NOT_IMPLEMENTED; + IntercepterWriterStruct iws; + iws.me = this; + iws.mWriter = writer; + iws.mClosure = closure; + + return mOriginalStream->ReadSegments(IntercepterWriter, (void*)&iws, + count, _retval); } NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { @@ -1263,7 +1295,7 @@ public: private: nsresult - write(char* aBuf, PRUint32 aNumBytes) { + write(const char* aBuf, PRUint32 aNumBytes) { PRUint32 actualBytes; return mCacheStream->Write(aBuf, aNumBytes, &actualBytes); } diff --git a/mozilla/xpcom/io/nsByteArrayInputStream.cpp b/mozilla/xpcom/io/nsByteArrayInputStream.cpp index 4f9502c0100..b2ea2049fd4 100644 --- a/mozilla/xpcom/io/nsByteArrayInputStream.cpp +++ b/mozilla/xpcom/io/nsByteArrayInputStream.cpp @@ -82,10 +82,30 @@ nsByteArrayInputStream::Read (char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead } NS_IMETHODIMP -nsByteArrayInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +nsByteArrayInputStream::ReadSegments(nsWriteSegmentFun writer, void * aClosure, PRUint32 aCount, PRUint32 *aNumRead) { - NS_NOTREACHED("ReadSegments"); - return NS_ERROR_NOT_IMPLEMENTED; + nsresult rv = NS_OK; + if (aNumRead == NULL) + return NS_ERROR_NULL_POINTER; + + if (_nbytes == 0) + return NS_ERROR_FAILURE; + + if (aCount == 0 || _pos == _nbytes) + *aNumRead = 0; + else { + NS_ASSERTION (_buffer != NULL, "Stream buffer has been released - there's an ownership problem somewhere!"); + PRUint32 readCount = PR_MIN(aCount, (_nbytes - _pos)); + if (_buffer == NULL) + *aNumRead = 0; + else + rv = writer (this, aClosure, &_buffer[_pos], + _pos, readCount, aNumRead); + + _pos += *aNumRead; + } + + return rv; } NS_IMETHODIMP