mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-29 15:52:07 +00:00
IDLized stream interfaces. Required rename of overloaded Write method (now WriteFrom). Added nsIBufferInputStream for peek capability.
This commit is contained in:
parent
2f48fd7da7
commit
00a8591812
@ -155,7 +155,7 @@ nsBuffer::Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount)
|
||||
|
||||
*readCount = 0;
|
||||
while (bufLen > 0) {
|
||||
rv = GetReadBuffer(&readBufferLen, &readBuffer);
|
||||
rv = GetReadBuffer(0, &readBuffer, &readBufferLen);
|
||||
if (rv == NS_BASE_STREAM_EOF) // all we're going to get
|
||||
return *readCount > 0 ? NS_OK : NS_BASE_STREAM_EOF;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@ -181,7 +181,9 @@ nsBuffer::Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::GetReadBuffer(PRUint32 *readBufferLength, char* *result)
|
||||
nsBuffer::GetReadBuffer(PRUint32 startPosition,
|
||||
char* *result,
|
||||
PRUint32 *readBufferLength)
|
||||
{
|
||||
if (mReadSegment == nsnull) {
|
||||
if (PR_CLIST_IS_EMPTY(&mSegments)) {
|
||||
@ -229,7 +231,7 @@ nsBuffer::Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount)
|
||||
while (bufLen > 0) {
|
||||
PRUint32 writeBufLen;
|
||||
char* writeBuf;
|
||||
rv = GetWriteBuffer(&writeBufLen, &writeBuf);
|
||||
rv = GetWriteBuffer(0, &writeBuf, &writeBufLen);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if we failed to allocate a new segment, we're probably out
|
||||
// of memory, but we don't care -- just report what we were
|
||||
@ -254,7 +256,7 @@ nsBuffer::Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::Write(nsIInputStream* fromStream, PRUint32 *writeCount)
|
||||
nsBuffer::WriteFrom(nsIInputStream* fromStream, PRUint32 count, PRUint32 *writeCount)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -262,10 +264,10 @@ nsBuffer::Write(nsIInputStream* fromStream, PRUint32 *writeCount)
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
||||
*writeCount = 0;
|
||||
while (PR_TRUE) {
|
||||
while (count > 0) {
|
||||
PRUint32 writeBufLen;
|
||||
char* writeBuf;
|
||||
rv = GetWriteBuffer(&writeBufLen, &writeBuf);
|
||||
rv = GetWriteBuffer(0, &writeBuf, &writeBufLen);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if we failed to allocate a new segment, we're probably out
|
||||
// of memory, but we don't care -- just report what we were
|
||||
@ -274,13 +276,14 @@ nsBuffer::Write(nsIInputStream* fromStream, PRUint32 *writeCount)
|
||||
}
|
||||
|
||||
PRUint32 readCount;
|
||||
rv = fromStream->Read(writeBuf, writeBufLen, &readCount);
|
||||
rv = fromStream->Read(writeBuf, PR_MIN(writeBufLen, count), &readCount);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if we failed to read just report what we were
|
||||
// able to write so far
|
||||
return NS_OK;
|
||||
}
|
||||
*writeCount += readCount;
|
||||
count -= readCount;
|
||||
// set the write cursor after the data is valid
|
||||
if (mWriteCursor + readCount == mWriteSegmentEnd) {
|
||||
mWriteSegment = nsnull; // allocate a new segment next time around
|
||||
@ -294,7 +297,9 @@ nsBuffer::Write(nsIInputStream* fromStream, PRUint32 *writeCount)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBuffer::GetWriteBuffer(PRUint32 *writeBufferLength, char* *result)
|
||||
nsBuffer::GetWriteBuffer(PRUint32 startPosition,
|
||||
char* *result,
|
||||
PRUint32 *writeBufferLength)
|
||||
{
|
||||
if (mEOF)
|
||||
return NS_BASE_STREAM_EOF;
|
||||
|
@ -35,11 +35,15 @@ public:
|
||||
NS_IMETHOD Init(PRUint32 growBySize, PRUint32 maxSize,
|
||||
nsIAllocator* allocator);
|
||||
NS_IMETHOD Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount);
|
||||
NS_IMETHOD GetReadBuffer(PRUint32 *readBufferLength, char* *result);
|
||||
NS_IMETHOD GetReadBuffer(PRUint32 startPosition,
|
||||
char* *result,
|
||||
PRUint32 *readBufferLength);
|
||||
|
||||
NS_IMETHOD Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount);
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *writeCount);
|
||||
NS_IMETHOD GetWriteBuffer(PRUint32 *writeBufferLength, char* *result);
|
||||
NS_IMETHOD WriteFrom(nsIInputStream* fromStream, PRUint32 count, PRUint32 *writeCount);
|
||||
NS_IMETHOD GetWriteBuffer(PRUint32 startPosition,
|
||||
char* *result,
|
||||
PRUint32 *writeBufferLength);
|
||||
NS_IMETHOD SetEOF();
|
||||
|
||||
// nsBuffer methods:
|
||||
|
@ -54,11 +54,15 @@ public:
|
||||
nsIAllocator* allocator) = 0;
|
||||
|
||||
NS_IMETHOD Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount) = 0;
|
||||
NS_IMETHOD GetReadBuffer(PRUint32 *readBufferLength, char* *result) = 0;
|
||||
NS_IMETHOD GetReadBuffer(PRUint32 startPosition,
|
||||
char* *result,
|
||||
PRUint32 *readBufferLength) = 0;
|
||||
|
||||
NS_IMETHOD Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount) = 0;
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *writeCount) = 0;
|
||||
NS_IMETHOD GetWriteBuffer(PRUint32 *writeBufferLength, char* *result) = 0;
|
||||
NS_IMETHOD WriteFrom(nsIInputStream* fromStream, PRUint32 count, PRUint32 *writeCount) = 0;
|
||||
NS_IMETHOD GetWriteBuffer(PRUint32 startPosition,
|
||||
char* *result,
|
||||
PRUint32 *writeBufferLength) = 0;
|
||||
NS_IMETHOD SetEOF() = 0;
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ class nsIByteBufferInputStream : public nsIInputStream {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBYTEBUFFERINPUTSTREAM_IID);
|
||||
|
||||
NS_IMETHOD Fill(nsIInputStream* stream, PRUint32 *aWriteCount) = 0;
|
||||
NS_IMETHOD Fill(nsIInputStream* stream, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
NS_IMETHOD Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "nsIBuffer.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsAutoLock.h"
|
||||
|
||||
@ -25,7 +25,7 @@ class nsBufferInputStream;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsBufferInputStream : public nsIInputStream
|
||||
class nsBufferInputStream : public nsIBufferInputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
@ -37,6 +37,11 @@ public:
|
||||
NS_IMETHOD GetLength(PRUint32 *aLength);
|
||||
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount);
|
||||
|
||||
// nsIBufferInputStream methods:
|
||||
NS_IMETHOD GetBuffer(PRUint32 startPosition, char * *bufferSegment,
|
||||
PRUint32 *bufferSegmentSize);
|
||||
NS_IMETHOD Find(char * aString, PRInt32 *_retval);
|
||||
|
||||
// nsBufferInputStream methods:
|
||||
nsBufferInputStream(nsIBuffer* buf, PRBool blocking);
|
||||
virtual ~nsBufferInputStream();
|
||||
@ -45,7 +50,7 @@ public:
|
||||
nsresult rv;
|
||||
PRUint32 amt;
|
||||
char* buf;
|
||||
rv = mBuffer->GetReadBuffer(&amt, &buf); // should never fail
|
||||
rv = mBuffer->GetReadBuffer(0, &buf, &amt); // should never fail
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "GetInputBuffer failed");
|
||||
return amt;
|
||||
}
|
||||
@ -70,7 +75,8 @@ public:
|
||||
|
||||
// nsIOutputStream methods:
|
||||
NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD WriteFrom(nsIInputStream* fromStream, PRUint32 aCount,
|
||||
PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Flush(void);
|
||||
|
||||
// nsBufferOutputStream methods:
|
||||
@ -143,7 +149,7 @@ nsBufferInputStream::GetLength(PRUint32 *aLength)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
|
||||
char* buf;
|
||||
return mBuffer->GetReadBuffer(aLength, &buf);
|
||||
return mBuffer->GetReadBuffer(0, &buf, aLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
@ -174,6 +180,19 @@ nsBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferInputStream::GetBuffer(PRUint32 startPosition, char * *bufferSegment,
|
||||
PRUint32 *bufferSegmentSize)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferInputStream::Find(char * aString, PRInt32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsBufferInputStream::SetEOF()
|
||||
{
|
||||
@ -206,7 +225,7 @@ nsBufferInputStream::Fill()
|
||||
// check read buffer again while in the monitor
|
||||
PRUint32 amt;
|
||||
char* buf;
|
||||
rv = mBuffer->GetReadBuffer(&amt, &buf);
|
||||
rv = mBuffer->GetReadBuffer(0, &buf, &amt);
|
||||
if (rv == NS_BASE_STREAM_EOF) return rv;
|
||||
if (NS_SUCCEEDED(rv) && amt > 0) return NS_OK;
|
||||
|
||||
@ -320,7 +339,8 @@ nsBufferOutputStream::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteC
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
nsBufferOutputStream::WriteFrom(nsIInputStream* fromStream, PRUint32 aCount,
|
||||
PRUint32 *aWriteCount)
|
||||
{
|
||||
if (mBuffer == nsnull)
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
@ -328,9 +348,9 @@ nsBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
nsresult rv = NS_OK;
|
||||
*aWriteCount = 0;
|
||||
|
||||
while (PR_TRUE) { // write until fromStream gets EOF
|
||||
while (aCount > 0) {
|
||||
PRUint32 amt;
|
||||
rv = mBuffer->Write(fromStream, &amt);
|
||||
rv = mBuffer->WriteFrom(fromStream, aCount, &amt);
|
||||
if (rv == NS_BASE_STREAM_EOF)
|
||||
return *aWriteCount > 0 ? NS_OK : rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
@ -339,6 +359,7 @@ nsBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
aCount -= amt;
|
||||
*aWriteCount += amt;
|
||||
}
|
||||
}
|
||||
@ -358,7 +379,7 @@ nsBufferOutputStream::Flush(void)
|
||||
// check write buffer again while in the monitor
|
||||
PRUint32 amt;
|
||||
char* buf;
|
||||
rv = mBuffer->GetWriteBuffer(&amt, &buf);
|
||||
rv = mBuffer->GetWriteBuffer(0, &buf, &amt);
|
||||
if (rv == NS_BASE_STREAM_EOF) return rv;
|
||||
if (NS_SUCCEEDED(rv) && amt > 0) return NS_OK;
|
||||
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
char buf[100];
|
||||
PRUint32 readCnt;
|
||||
char* readBuf;
|
||||
rv = mReadBuffer->GetReadBuffer(&readCnt, &readBuf);
|
||||
rv = mReadBuffer->GetReadBuffer(0, &readBuf, &readCnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
while (!(mDone && readCnt == 0)) {
|
||||
rv = mReadBuffer->Read(buf, 99, &readCnt);
|
||||
@ -52,7 +52,7 @@ public:
|
||||
break;
|
||||
mon.Notify(); // wake up writer
|
||||
mon.Wait(); // wait for more
|
||||
rv = mReadBuffer->GetReadBuffer(&readCnt, &readBuf);
|
||||
rv = mReadBuffer->GetReadBuffer(0, &readBuf, &readCnt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else {
|
||||
|
Loading…
Reference in New Issue
Block a user