diff --git a/mozilla/base/src/nsByteBuffer.cpp b/mozilla/base/src/nsByteBuffer.cpp index a27f8cbf2c9..bd3c9b72467 100644 --- a/mozilla/base/src/nsByteBuffer.cpp +++ b/mozilla/base/src/nsByteBuffer.cpp @@ -31,7 +31,7 @@ public: virtual PRInt32 GetBufferSize() const; virtual char* GetBuffer() const; virtual PRBool Grow(PRInt32 aNewSize); - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream, PRInt32 aKeep); char* mBuffer; @@ -94,14 +94,14 @@ PRBool ByteBufferImpl::Grow(PRInt32 aNewSize) return PR_FALSE; } -PRInt32 ByteBufferImpl::Fill(PRInt32* aErrorCode, nsIInputStream* aStream, +PRInt32 ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream, PRInt32 aKeep) { NS_PRECONDITION(nsnull != aStream, "null stream"); NS_PRECONDITION(PRUint32(aKeep) <= PRUint32(mLength), "illegal keep count"); if ((nsnull == aStream) || (PRUint32(aKeep) > PRUint32(mLength))) { // whoops - *aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS; + *aErrorCode = NS_BASE_STREAM_ILLEGAL_ARGS; return -1; } @@ -113,10 +113,13 @@ PRInt32 ByteBufferImpl::Fill(PRInt32* aErrorCode, nsIInputStream* aStream, // Read in some new data mLength = aKeep; PRInt32 amount = mSpace - aKeep; - PRInt32 nb = aStream->Read(aErrorCode, mBuffer, aKeep, amount); - if (nb > 0) { + PRInt32 nb; + *aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb); + if (NS_SUCCEEDED(*aErrorCode)) { mLength += nb; } + else + nb = 0; return nb; } diff --git a/mozilla/base/src/nsIBaseStream.h b/mozilla/base/src/nsIBaseStream.h index 8578d81676a..06efd0fad4f 100644 --- a/mozilla/base/src/nsIBaseStream.h +++ b/mozilla/base/src/nsIBaseStream.h @@ -31,12 +31,27 @@ class nsIBaseStream : public nsISupports { public: - /** Return the number of bytes in the stream */ - virtual PRInt32 GetLength() = 0; - - /** Close the stream. */ - virtual void Close() = 0; + /** Close the stream. */ + NS_IMETHOD + Close(void) = 0; }; +/** Error codes */ +//@{ +// XXX fix up the values so they are not total hacks... MMP +/// End of file +#define NS_BASE_STREAM_EOF 0x80001001 +/// Stream closed +#define NS_BASE_STREAM_CLOSED 0x80001002 +/// Error from the operating system +#define NS_BASE_STREAM_OSERROR 0x80001003 +/// Illegal arguments +#define NS_BASE_STREAM_ILLEGAL_ARGS 0x80001004 +/// For unichar streams +#define NS_BASE_STREAM_NO_CONVERTER 0x80001005 +/// For unichar streams +#define NS_BASE_STREAM_BAD_CONVERSION 0x80001006 +//@} + #endif /* nsInputStream_h___ */ diff --git a/mozilla/base/src/nsIByteBuffer.h b/mozilla/base/src/nsIByteBuffer.h index 74561b69a47..43a04c29342 100644 --- a/mozilla/base/src/nsIByteBuffer.h +++ b/mozilla/base/src/nsIByteBuffer.h @@ -44,7 +44,7 @@ public: /** Fill the buffer with data from aStream. Don't grow the buffer, only * read until length of buffer equals buffer size. */ - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream, PRInt32 aKeep) = 0; }; diff --git a/mozilla/base/src/nsIInputStream.h b/mozilla/base/src/nsIInputStream.h index abfc50f4512..37c942927f3 100644 --- a/mozilla/base/src/nsIInputStream.h +++ b/mozilla/base/src/nsIInputStream.h @@ -27,34 +27,28 @@ /** Abstract byte input stream */ class nsIInputStream : public nsIBaseStream { public: - /** Read data from the stream. - * @param aErrorCode the error code if an error occurs - * @param aBuf the buffer into which the data is read - * @param aOffset the start offset of the data - * @param aCount the maximum number of bytes to read - * @return number of bytes read or -1 if error - */ - virtual PRInt32 Read(PRInt32* aErrorCode, - char* aBuf, - PRInt32 aOffset, - PRInt32 aCount) = 0; + + /** Return the number of bytes in the stream + * @param aLength out parameter to hold the length + * of the stream. if an error occurs, the length + * will be undefined + * @return error status + */ + NS_IMETHOD + GetLength(PRInt32 *aLength) = 0; + + /** Read data from the stream. + * @param aErrorCode the error code if an error occurs + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aReadCount out parameter to hold the number of + * bytes read, eof if 0. if an error occurs, the + * read count will be undefined + * @return error status + */ + NS_IMETHOD + Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount) = 0; }; -/** Error codes */ -//@{ -// XXX fix up the values to work with nsqresult -/// End of file -#define NS_INPUTSTREAM_EOF 1 -/// Stream closed -#define NS_INPUTSTREAM_CLOSED 2 -/// Error from the operating system -#define NS_INPUTSTREAM_OSERROR 3 -/// Illegal arguments -#define NS_INPUTSTREAM_ILLEGAL_ARGS 4 -/// For unichar streams -#define NS_INPUTSTREAM_NO_CONVERTER 5 -/// For unichar streams -#define NS_INPUTSTREAM_BAD_CONVERSION 6 -//@} - #endif /* nsInputStream_h___ */ diff --git a/mozilla/base/src/nsIOutputStream.h b/mozilla/base/src/nsIOutputStream.h index 3f89f03a4a3..ad032f52767 100644 --- a/mozilla/base/src/nsIOutputStream.h +++ b/mozilla/base/src/nsIOutputStream.h @@ -25,20 +25,21 @@ { 0x7f13b870, 0xe95f, 0x11d1, \ {0xbe, 0xae, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} } -/** Abstract byte input stream */ +/** Abstract byte output stream */ class nsIOutputStream : public nsIBaseStream { public: - /** Write data into the stream. - * @param aErrorCode the error code if an error occurs - * @param aBuf the buffer into which the data is read - * @param aOffset the start offset of the data - * @param aCount the maximum number of bytes to read - * @return number of bytes read or -1 if error - */ - virtual PRInt32 Write(PRInt32* aErrorCode, - const char* aBuf, - PRInt32 aOffset, - PRInt32 aCount) = 0; + + /** Write data into the stream. + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aWriteCount out parameter to hold the number of + * bytes written. if an error occurs, the writecount + * is undefined + * @return error status + */ + NS_IMETHOD + Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aWriteCount) = 0; }; diff --git a/mozilla/base/src/nsIUnicharBuffer.h b/mozilla/base/src/nsIUnicharBuffer.h index 17bf8e74a3a..a5f57d7886b 100644 --- a/mozilla/base/src/nsIUnicharBuffer.h +++ b/mozilla/base/src/nsIUnicharBuffer.h @@ -33,7 +33,7 @@ public: virtual PRInt32 GetBufferSize() const = 0; virtual PRUnichar* GetBuffer() const = 0; virtual PRBool Grow(PRInt32 aNewSize) = 0; - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIUnicharInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream, PRInt32 aKeep) = 0; }; diff --git a/mozilla/base/src/nsIUnicharInputStream.h b/mozilla/base/src/nsIUnicharInputStream.h index 250dd07f17b..ecd21b775d4 100644 --- a/mozilla/base/src/nsIUnicharInputStream.h +++ b/mozilla/base/src/nsIUnicharInputStream.h @@ -42,11 +42,11 @@ enum nsCharSetID { */ class nsIUnicharInputStream : public nsISupports { public: - virtual PRInt32 Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount) = 0; - virtual void Close() = 0; + NS_IMETHOD Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount) = 0; + NS_IMETHOD Close() = 0; }; /** diff --git a/mozilla/base/src/nsUnicharBuffer.cpp b/mozilla/base/src/nsUnicharBuffer.cpp index 8c001afe069..6bedaaf6255 100644 --- a/mozilla/base/src/nsUnicharBuffer.cpp +++ b/mozilla/base/src/nsUnicharBuffer.cpp @@ -31,7 +31,7 @@ public: virtual PRInt32 GetBufferSize() const; virtual PRUnichar* GetBuffer() const; virtual PRBool Grow(PRInt32 aNewSize); - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIUnicharInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream, PRInt32 aKeep); PRUnichar* mBuffer; @@ -94,7 +94,7 @@ PRBool UnicharBufferImpl::Grow(PRInt32 aNewSize) return PR_FALSE; } -PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode, +PRInt32 UnicharBufferImpl::Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream, PRInt32 aKeep) { @@ -102,7 +102,7 @@ PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode, NS_PRECONDITION(PRUint32(aKeep) < PRUint32(mLength), "illegal keep count"); if ((nsnull == aStream) || (PRUint32(aKeep) >= PRUint32(mLength))) { // whoops - *aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS; + *aErrorCode = NS_BASE_STREAM_ILLEGAL_ARGS; return -1; } @@ -115,10 +115,13 @@ PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode, // Read in some new data mLength = aKeep; PRInt32 amount = mSpace - aKeep; - PRInt32 nb = aStream->Read(aErrorCode, mBuffer, aKeep, amount); - if (nb > 0) { + PRInt32 nb; + *aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb); + if (NS_SUCCEEDED(*aErrorCode)) { mLength += nb; } + else + nb = 0; return nb; } diff --git a/mozilla/base/src/nsUnicharInputStream.cpp b/mozilla/base/src/nsUnicharInputStream.cpp index 6f1534af003..b724da7f262 100644 --- a/mozilla/base/src/nsUnicharInputStream.cpp +++ b/mozilla/base/src/nsUnicharInputStream.cpp @@ -36,11 +36,11 @@ public: NS_DECL_ISUPPORTS - virtual PRInt32 Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount); - virtual void Close(); + NS_IMETHOD Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount); + NS_IMETHOD Close(); nsString* mString; PRInt32 mPos; @@ -62,12 +62,13 @@ StringUnicharInputStream::~StringUnicharInputStream() } } -PRInt32 StringUnicharInputStream::Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount) +nsresult StringUnicharInputStream::Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount) { if (mPos >= mLen) { + *aReadCount = 0; return -1; } const PRUnichar* us = mString->GetUnicode(); @@ -77,15 +78,17 @@ PRInt32 StringUnicharInputStream::Read(PRInt32* aErrorCode, } nsCRT::memcpy(aBuf + aOffset, us + mPos, sizeof(PRUnichar) * amount); mPos += amount; - return amount; + *aReadCount = amount; + return NS_OK; } -void StringUnicharInputStream::Close() +nsresult StringUnicharInputStream::Close() { mPos = mLen; if (nsnull != mString) { delete mString; } + return NS_OK; } NS_IMPL_ISUPPORTS(StringUnicharInputStream, kIUnicharInputStreamIID); @@ -163,7 +166,7 @@ NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult, return NS_ERROR_NO_AGGREGATION; } if (eCharSetID_IsoLatin1 != aCharSet) { - return NS_INPUTSTREAM_NO_CONVERTER; + return NS_BASE_STREAM_NO_CONVERTER; } IsoLatin1Converter* it = new IsoLatin1Converter(); if (nsnull == it) { @@ -182,14 +185,14 @@ public: ~ConverterInputStream(); NS_DECL_ISUPPORTS - virtual PRInt32 Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount); - virtual void Close(); + NS_IMETHOD Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount); + NS_IMETHOD Close(); protected: - PRInt32 Fill(PRInt32* aErrorCode); + PRInt32 Fill(nsresult * aErrorCode); nsIInputStream* mInput; nsIB2UConverter* mConverter; @@ -224,7 +227,7 @@ ConverterInputStream::~ConverterInputStream() Close(); } -void ConverterInputStream::Close() +nsresult ConverterInputStream::Close() { if (nsnull != mInput) { mInput->Release(); @@ -242,19 +245,23 @@ void ConverterInputStream::Close() mUnicharData->Release(); mUnicharData = nsnull; } + + return NS_OK; } -PRInt32 ConverterInputStream::Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount) +nsresult ConverterInputStream::Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount) { PRInt32 rv = mUnicharDataLength - mUnicharDataOffset; + nsresult errorCode; if (0 == rv) { // Fill the unichar buffer - rv = Fill(aErrorCode); + rv = Fill(&errorCode); if (rv <= 0) { - return rv; + *aReadCount = 0; + return errorCode; } } if (rv > aCount) { @@ -263,14 +270,15 @@ PRInt32 ConverterInputStream::Read(PRInt32* aErrorCode, nsCRT::memcpy(aBuf + aOffset, mUnicharData->GetBuffer() + mUnicharDataOffset, rv * sizeof(PRUnichar)); mUnicharDataOffset += rv; - return rv; + *aReadCount = rv; + return NS_OK; } -PRInt32 ConverterInputStream::Fill(PRInt32* aErrorCode) +PRInt32 ConverterInputStream::Fill(nsresult * aErrorCode) { if (nsnull == mInput) { // We already closed the stream! - *aErrorCode = NS_INPUTSTREAM_CLOSED; + *aErrorCode = NS_BASE_STREAM_CLOSED; return -1; } diff --git a/mozilla/base/src/nscore.h b/mozilla/base/src/nscore.h index 337781679a3..87ad079890e 100644 --- a/mozilla/base/src/nscore.h +++ b/mozilla/base/src/nscore.h @@ -107,4 +107,10 @@ typedef PRUcs2 PRUnichar; #define NS_GFX NS_IMPORT #endif +#ifdef _IMPL_NS_PLUGIN +#define NS_PLUGIN NS_EXPORT +#else +#define NS_PLUGIN NS_IMPORT +#endif + #endif /* nscore_h___ */ diff --git a/mozilla/base/tests/CvtURL.cpp b/mozilla/base/tests/CvtURL.cpp index 365b687431a..f3f50f47626 100644 --- a/mozilla/base/tests/CvtURL.cpp +++ b/mozilla/base/tests/CvtURL.cpp @@ -75,9 +75,10 @@ int main(int argc, char** argv) PRInt32 count = 0; for (;;) { PRUnichar buf[1000]; - PRInt32 nb = uin->Read(&ec, buf, 0, 1000); - if (nb <= 0) { - if (nb < 0) { + PRInt32 nb; + ec = uin->Read(buf, 0, 1000, &nb); + if (ec < 0) { + if (ec != NS_BASE_STREAM_EOF) { printf("i/o error: %d\n", ec); } break; diff --git a/mozilla/xpcom/ds/nsByteBuffer.cpp b/mozilla/xpcom/ds/nsByteBuffer.cpp index a27f8cbf2c9..bd3c9b72467 100644 --- a/mozilla/xpcom/ds/nsByteBuffer.cpp +++ b/mozilla/xpcom/ds/nsByteBuffer.cpp @@ -31,7 +31,7 @@ public: virtual PRInt32 GetBufferSize() const; virtual char* GetBuffer() const; virtual PRBool Grow(PRInt32 aNewSize); - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream, PRInt32 aKeep); char* mBuffer; @@ -94,14 +94,14 @@ PRBool ByteBufferImpl::Grow(PRInt32 aNewSize) return PR_FALSE; } -PRInt32 ByteBufferImpl::Fill(PRInt32* aErrorCode, nsIInputStream* aStream, +PRInt32 ByteBufferImpl::Fill(nsresult* aErrorCode, nsIInputStream* aStream, PRInt32 aKeep) { NS_PRECONDITION(nsnull != aStream, "null stream"); NS_PRECONDITION(PRUint32(aKeep) <= PRUint32(mLength), "illegal keep count"); if ((nsnull == aStream) || (PRUint32(aKeep) > PRUint32(mLength))) { // whoops - *aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS; + *aErrorCode = NS_BASE_STREAM_ILLEGAL_ARGS; return -1; } @@ -113,10 +113,13 @@ PRInt32 ByteBufferImpl::Fill(PRInt32* aErrorCode, nsIInputStream* aStream, // Read in some new data mLength = aKeep; PRInt32 amount = mSpace - aKeep; - PRInt32 nb = aStream->Read(aErrorCode, mBuffer, aKeep, amount); - if (nb > 0) { + PRInt32 nb; + *aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb); + if (NS_SUCCEEDED(*aErrorCode)) { mLength += nb; } + else + nb = 0; return nb; } diff --git a/mozilla/xpcom/ds/nsIByteBuffer.h b/mozilla/xpcom/ds/nsIByteBuffer.h index 74561b69a47..43a04c29342 100644 --- a/mozilla/xpcom/ds/nsIByteBuffer.h +++ b/mozilla/xpcom/ds/nsIByteBuffer.h @@ -44,7 +44,7 @@ public: /** Fill the buffer with data from aStream. Don't grow the buffer, only * read until length of buffer equals buffer size. */ - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIInputStream* aStream, PRInt32 aKeep) = 0; }; diff --git a/mozilla/xpcom/ds/nsIUnicharBuffer.h b/mozilla/xpcom/ds/nsIUnicharBuffer.h index 17bf8e74a3a..a5f57d7886b 100644 --- a/mozilla/xpcom/ds/nsIUnicharBuffer.h +++ b/mozilla/xpcom/ds/nsIUnicharBuffer.h @@ -33,7 +33,7 @@ public: virtual PRInt32 GetBufferSize() const = 0; virtual PRUnichar* GetBuffer() const = 0; virtual PRBool Grow(PRInt32 aNewSize) = 0; - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIUnicharInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream, PRInt32 aKeep) = 0; }; diff --git a/mozilla/xpcom/ds/nsUnicharBuffer.cpp b/mozilla/xpcom/ds/nsUnicharBuffer.cpp index 8c001afe069..6bedaaf6255 100644 --- a/mozilla/xpcom/ds/nsUnicharBuffer.cpp +++ b/mozilla/xpcom/ds/nsUnicharBuffer.cpp @@ -31,7 +31,7 @@ public: virtual PRInt32 GetBufferSize() const; virtual PRUnichar* GetBuffer() const; virtual PRBool Grow(PRInt32 aNewSize); - virtual PRInt32 Fill(PRInt32* aErrorCode, nsIUnicharInputStream* aStream, + virtual PRInt32 Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream, PRInt32 aKeep); PRUnichar* mBuffer; @@ -94,7 +94,7 @@ PRBool UnicharBufferImpl::Grow(PRInt32 aNewSize) return PR_FALSE; } -PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode, +PRInt32 UnicharBufferImpl::Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream, PRInt32 aKeep) { @@ -102,7 +102,7 @@ PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode, NS_PRECONDITION(PRUint32(aKeep) < PRUint32(mLength), "illegal keep count"); if ((nsnull == aStream) || (PRUint32(aKeep) >= PRUint32(mLength))) { // whoops - *aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS; + *aErrorCode = NS_BASE_STREAM_ILLEGAL_ARGS; return -1; } @@ -115,10 +115,13 @@ PRInt32 UnicharBufferImpl::Fill(PRInt32* aErrorCode, // Read in some new data mLength = aKeep; PRInt32 amount = mSpace - aKeep; - PRInt32 nb = aStream->Read(aErrorCode, mBuffer, aKeep, amount); - if (nb > 0) { + PRInt32 nb; + *aErrorCode = aStream->Read(mBuffer, aKeep, amount, &nb); + if (NS_SUCCEEDED(*aErrorCode)) { mLength += nb; } + else + nb = 0; return nb; } diff --git a/mozilla/xpcom/io/nsIBaseStream.h b/mozilla/xpcom/io/nsIBaseStream.h index 8578d81676a..06efd0fad4f 100644 --- a/mozilla/xpcom/io/nsIBaseStream.h +++ b/mozilla/xpcom/io/nsIBaseStream.h @@ -31,12 +31,27 @@ class nsIBaseStream : public nsISupports { public: - /** Return the number of bytes in the stream */ - virtual PRInt32 GetLength() = 0; - - /** Close the stream. */ - virtual void Close() = 0; + /** Close the stream. */ + NS_IMETHOD + Close(void) = 0; }; +/** Error codes */ +//@{ +// XXX fix up the values so they are not total hacks... MMP +/// End of file +#define NS_BASE_STREAM_EOF 0x80001001 +/// Stream closed +#define NS_BASE_STREAM_CLOSED 0x80001002 +/// Error from the operating system +#define NS_BASE_STREAM_OSERROR 0x80001003 +/// Illegal arguments +#define NS_BASE_STREAM_ILLEGAL_ARGS 0x80001004 +/// For unichar streams +#define NS_BASE_STREAM_NO_CONVERTER 0x80001005 +/// For unichar streams +#define NS_BASE_STREAM_BAD_CONVERSION 0x80001006 +//@} + #endif /* nsInputStream_h___ */ diff --git a/mozilla/xpcom/io/nsIInputStream.h b/mozilla/xpcom/io/nsIInputStream.h index abfc50f4512..37c942927f3 100644 --- a/mozilla/xpcom/io/nsIInputStream.h +++ b/mozilla/xpcom/io/nsIInputStream.h @@ -27,34 +27,28 @@ /** Abstract byte input stream */ class nsIInputStream : public nsIBaseStream { public: - /** Read data from the stream. - * @param aErrorCode the error code if an error occurs - * @param aBuf the buffer into which the data is read - * @param aOffset the start offset of the data - * @param aCount the maximum number of bytes to read - * @return number of bytes read or -1 if error - */ - virtual PRInt32 Read(PRInt32* aErrorCode, - char* aBuf, - PRInt32 aOffset, - PRInt32 aCount) = 0; + + /** Return the number of bytes in the stream + * @param aLength out parameter to hold the length + * of the stream. if an error occurs, the length + * will be undefined + * @return error status + */ + NS_IMETHOD + GetLength(PRInt32 *aLength) = 0; + + /** Read data from the stream. + * @param aErrorCode the error code if an error occurs + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aReadCount out parameter to hold the number of + * bytes read, eof if 0. if an error occurs, the + * read count will be undefined + * @return error status + */ + NS_IMETHOD + Read(char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aReadCount) = 0; }; -/** Error codes */ -//@{ -// XXX fix up the values to work with nsqresult -/// End of file -#define NS_INPUTSTREAM_EOF 1 -/// Stream closed -#define NS_INPUTSTREAM_CLOSED 2 -/// Error from the operating system -#define NS_INPUTSTREAM_OSERROR 3 -/// Illegal arguments -#define NS_INPUTSTREAM_ILLEGAL_ARGS 4 -/// For unichar streams -#define NS_INPUTSTREAM_NO_CONVERTER 5 -/// For unichar streams -#define NS_INPUTSTREAM_BAD_CONVERSION 6 -//@} - #endif /* nsInputStream_h___ */ diff --git a/mozilla/xpcom/io/nsIOutputStream.h b/mozilla/xpcom/io/nsIOutputStream.h index 3f89f03a4a3..ad032f52767 100644 --- a/mozilla/xpcom/io/nsIOutputStream.h +++ b/mozilla/xpcom/io/nsIOutputStream.h @@ -25,20 +25,21 @@ { 0x7f13b870, 0xe95f, 0x11d1, \ {0xbe, 0xae, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} } -/** Abstract byte input stream */ +/** Abstract byte output stream */ class nsIOutputStream : public nsIBaseStream { public: - /** Write data into the stream. - * @param aErrorCode the error code if an error occurs - * @param aBuf the buffer into which the data is read - * @param aOffset the start offset of the data - * @param aCount the maximum number of bytes to read - * @return number of bytes read or -1 if error - */ - virtual PRInt32 Write(PRInt32* aErrorCode, - const char* aBuf, - PRInt32 aOffset, - PRInt32 aCount) = 0; + + /** Write data into the stream. + * @param aBuf the buffer into which the data is read + * @param aOffset the start offset of the data + * @param aCount the maximum number of bytes to read + * @param aWriteCount out parameter to hold the number of + * bytes written. if an error occurs, the writecount + * is undefined + * @return error status + */ + NS_IMETHOD + Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, PRInt32 *aWriteCount) = 0; }; diff --git a/mozilla/xpcom/io/nsIUnicharInputStream.h b/mozilla/xpcom/io/nsIUnicharInputStream.h index 250dd07f17b..ecd21b775d4 100644 --- a/mozilla/xpcom/io/nsIUnicharInputStream.h +++ b/mozilla/xpcom/io/nsIUnicharInputStream.h @@ -42,11 +42,11 @@ enum nsCharSetID { */ class nsIUnicharInputStream : public nsISupports { public: - virtual PRInt32 Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount) = 0; - virtual void Close() = 0; + NS_IMETHOD Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount) = 0; + NS_IMETHOD Close() = 0; }; /** diff --git a/mozilla/xpcom/io/nsUnicharInputStream.cpp b/mozilla/xpcom/io/nsUnicharInputStream.cpp index 6f1534af003..b724da7f262 100644 --- a/mozilla/xpcom/io/nsUnicharInputStream.cpp +++ b/mozilla/xpcom/io/nsUnicharInputStream.cpp @@ -36,11 +36,11 @@ public: NS_DECL_ISUPPORTS - virtual PRInt32 Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount); - virtual void Close(); + NS_IMETHOD Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount); + NS_IMETHOD Close(); nsString* mString; PRInt32 mPos; @@ -62,12 +62,13 @@ StringUnicharInputStream::~StringUnicharInputStream() } } -PRInt32 StringUnicharInputStream::Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount) +nsresult StringUnicharInputStream::Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount) { if (mPos >= mLen) { + *aReadCount = 0; return -1; } const PRUnichar* us = mString->GetUnicode(); @@ -77,15 +78,17 @@ PRInt32 StringUnicharInputStream::Read(PRInt32* aErrorCode, } nsCRT::memcpy(aBuf + aOffset, us + mPos, sizeof(PRUnichar) * amount); mPos += amount; - return amount; + *aReadCount = amount; + return NS_OK; } -void StringUnicharInputStream::Close() +nsresult StringUnicharInputStream::Close() { mPos = mLen; if (nsnull != mString) { delete mString; } + return NS_OK; } NS_IMPL_ISUPPORTS(StringUnicharInputStream, kIUnicharInputStreamIID); @@ -163,7 +166,7 @@ NS_NewB2UConverter(nsIB2UConverter** aInstancePtrResult, return NS_ERROR_NO_AGGREGATION; } if (eCharSetID_IsoLatin1 != aCharSet) { - return NS_INPUTSTREAM_NO_CONVERTER; + return NS_BASE_STREAM_NO_CONVERTER; } IsoLatin1Converter* it = new IsoLatin1Converter(); if (nsnull == it) { @@ -182,14 +185,14 @@ public: ~ConverterInputStream(); NS_DECL_ISUPPORTS - virtual PRInt32 Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount); - virtual void Close(); + NS_IMETHOD Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount); + NS_IMETHOD Close(); protected: - PRInt32 Fill(PRInt32* aErrorCode); + PRInt32 Fill(nsresult * aErrorCode); nsIInputStream* mInput; nsIB2UConverter* mConverter; @@ -224,7 +227,7 @@ ConverterInputStream::~ConverterInputStream() Close(); } -void ConverterInputStream::Close() +nsresult ConverterInputStream::Close() { if (nsnull != mInput) { mInput->Release(); @@ -242,19 +245,23 @@ void ConverterInputStream::Close() mUnicharData->Release(); mUnicharData = nsnull; } + + return NS_OK; } -PRInt32 ConverterInputStream::Read(PRInt32* aErrorCode, - PRUnichar* aBuf, - PRInt32 aOffset, - PRInt32 aCount) +nsresult ConverterInputStream::Read(PRUnichar* aBuf, + PRInt32 aOffset, + PRInt32 aCount, + PRInt32 *aReadCount) { PRInt32 rv = mUnicharDataLength - mUnicharDataOffset; + nsresult errorCode; if (0 == rv) { // Fill the unichar buffer - rv = Fill(aErrorCode); + rv = Fill(&errorCode); if (rv <= 0) { - return rv; + *aReadCount = 0; + return errorCode; } } if (rv > aCount) { @@ -263,14 +270,15 @@ PRInt32 ConverterInputStream::Read(PRInt32* aErrorCode, nsCRT::memcpy(aBuf + aOffset, mUnicharData->GetBuffer() + mUnicharDataOffset, rv * sizeof(PRUnichar)); mUnicharDataOffset += rv; - return rv; + *aReadCount = rv; + return NS_OK; } -PRInt32 ConverterInputStream::Fill(PRInt32* aErrorCode) +PRInt32 ConverterInputStream::Fill(nsresult * aErrorCode) { if (nsnull == mInput) { // We already closed the stream! - *aErrorCode = NS_INPUTSTREAM_CLOSED; + *aErrorCode = NS_BASE_STREAM_CLOSED; return -1; } diff --git a/mozilla/xpcom/tests/CvtURL.cpp b/mozilla/xpcom/tests/CvtURL.cpp index 365b687431a..f3f50f47626 100644 --- a/mozilla/xpcom/tests/CvtURL.cpp +++ b/mozilla/xpcom/tests/CvtURL.cpp @@ -75,9 +75,10 @@ int main(int argc, char** argv) PRInt32 count = 0; for (;;) { PRUnichar buf[1000]; - PRInt32 nb = uin->Read(&ec, buf, 0, 1000); - if (nb <= 0) { - if (nb < 0) { + PRInt32 nb; + ec = uin->Read(buf, 0, 1000, &nb); + if (ec < 0) { + if (ec != NS_BASE_STREAM_EOF) { printf("i/o error: %d\n", ec); } break;