diff --git a/mozilla/base/public/nsIByteBufferInputStream.h b/mozilla/base/public/nsIByteBufferInputStream.h index 15d0c4df79f..5badc956642 100644 --- a/mozilla/base/public/nsIByteBufferInputStream.h +++ b/mozilla/base/public/nsIByteBufferInputStream.h @@ -42,25 +42,6 @@ public: //////////////////////////////////////////////////////////////////////////////// -// XXX regenerate: -#define NS_IBYTEBUFFEROUTPUTSTREAM_IID \ -{ /* 924df6d0-f192-11d2-9322-000000000000 */ \ - 0x924df6d0, \ - 0xf192, \ - 0x11d2, \ - {0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \ -} - -class nsIByteBufferOutputStream : public nsIOutputStream { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBYTEBUFFEROUTPUTSTREAM_IID); - - NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0; - -}; - -//////////////////////////////////////////////////////////////////////////////// - extern NS_BASE nsresult NS_NewByteBufferInputStream(nsIByteBufferInputStream* *result, PRBool blocking = PR_FALSE, diff --git a/mozilla/base/public/nsIFileStream.h b/mozilla/base/public/nsIFileStream.h index f27ccf1ccdf..8f2ee8f05bb 100644 --- a/mozilla/base/public/nsIFileStream.h +++ b/mozilla/base/public/nsIFileStream.h @@ -101,8 +101,6 @@ class nsIFileOutputStream { public: static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; } - NS_IMETHOD Flush() = 0; - // Forces a write to disk. }; // class nsIFileOutputStream //---------------------------------------------------------------------------------------- diff --git a/mozilla/base/src/nsByteBufferInputStream.cpp b/mozilla/base/src/nsByteBufferInputStream.cpp index ff8f45b9fb2..161015b1b01 100644 --- a/mozilla/base/src/nsByteBufferInputStream.cpp +++ b/mozilla/base/src/nsByteBufferInputStream.cpp @@ -24,7 +24,7 @@ class nsByteBufferInputStream; //////////////////////////////////////////////////////////////////////////////// -class nsByteBufferOutputStream : public nsIByteBufferOutputStream +class nsByteBufferOutputStream : public nsIOutputStream { public: NS_DECL_ISUPPORTS @@ -34,9 +34,8 @@ public: // nsIOutputStream methods: NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); - - // nsIByteBufferOutputStream methods: NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount); + NS_IMETHOD Flush(void); // nsByteBufferOutputStream methods: nsByteBufferOutputStream(nsByteBufferInputStream* in); @@ -71,7 +70,8 @@ public: friend class nsByteBufferOutputStream; nsresult Init(void); - void SetEOF(void); + nsresult SetEOF(void); + nsresult Drain(void); PRBool AtEOF() { return mEOF && (mReadCursor == mWriteCursor) && !mFull; } @@ -101,8 +101,8 @@ public: PRInt32 amt = PR_MIN(max, diff); if (amt > 0) { nsCRT::memcpy(toBuf, &mBuffer[mReadCursor], amt); -#ifdef NS_DEBUG - nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt); +#ifdef DEBUG_warren +// nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt); #endif mReadCursor += amt; *totalRef += amt; @@ -243,14 +243,17 @@ nsByteBufferInputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_IMETHODIMP nsByteBufferInputStream::Close(void) { + nsresult rv = NS_OK; if (mBlocking) PR_CEnterMonitor(this); mClosed = PR_TRUE; if (mBlocking) { - PR_CNotify(this); // wake up the writer + PRStatus status = PR_CNotify(this); // wake up the writer + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; PR_CExitMonitor(this); } - return NS_OK; + return rv; } NS_IMETHODIMP @@ -281,7 +284,7 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) PR_CEnterMonitor(this); *aReadCount = 0; - /*while (aCount > 0)*/ { // XXX should this block trying to fill the buffer, or return ASAP? + /*while (aCount > 0)*/ { if (ReadableAmount() == 0) { if (mBlocking) { PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT); @@ -325,8 +328,11 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) if (*aReadCount) mFull = PR_FALSE; - if (mBlocking) - PR_CNotify(this); // tell the writer there's space + if (mBlocking) { + PRStatus status = PR_CNotify(this); // tell the writer there's space + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; + } } done: if (mBlocking) @@ -401,8 +407,11 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount) if (mWriteCursor == mReadCursor) mFull = PR_TRUE; - if (mBlocking) - PR_CNotify(this); // tell the reader there's more + if (mBlocking) { + PRStatus status = PR_CNotify(this); // tell the reader there's more + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; + } } done: if (mBlocking) @@ -410,16 +419,46 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount) return rv; } -void +nsresult nsByteBufferInputStream::SetEOF() { + nsresult rv = NS_OK; if (mBlocking) PR_CEnterMonitor(this); mEOF = PR_TRUE; if (mBlocking) { - PR_CNotify(this); // wake up the reader + PRStatus status = PR_CNotify(this); // wake up the reader + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; PR_CExitMonitor(this); } + return rv; +} + +nsresult +nsByteBufferInputStream::Drain() +{ + nsresult rv = NS_OK; + if (mBlocking) { + PR_CEnterMonitor(this); + while (ReadableAmount() != 0) { + PRStatus status = PR_CNotify(this); // wake up the reader + if (status != PR_SUCCESS) { + rv = NS_ERROR_FAILURE; + break; + } + else { + // wait for the reader to take all the data + status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT); + if (status != PR_SUCCESS) { + rv = NS_ERROR_FAILURE; + break; + } + } + } + PR_CExitMonitor(this); + } + return rv; } //////////////////////////////////////////////////////////////////////////////// @@ -447,8 +486,7 @@ nsByteBufferOutputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr) { if (aInstancePtr == nsnull) return NS_ERROR_NULL_POINTER; - if (aIID.Equals(nsIByteBufferOutputStream::GetIID()) || - aIID.Equals(nsIOutputStream::GetIID()) || + if (aIID.Equals(nsIOutputStream::GetIID()) || aIID.Equals(nsIBaseStream::GetIID()) || aIID.Equals(nsISupports::GetIID())) { *aInstancePtr = this; @@ -477,6 +515,12 @@ nsByteBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCoun return mInputStream->Fill(fromStream, aWriteCount); } +NS_IMETHODIMP +nsByteBufferOutputStream::Flush(void) +{ + return mInputStream->Drain(); +} + //////////////////////////////////////////////////////////////////////////////// NS_BASE nsresult diff --git a/mozilla/base/src/nsIFileStream.cpp b/mozilla/base/src/nsIFileStream.cpp index daf67071de8..4a1ea37e297 100644 --- a/mozilla/base/src/nsIFileStream.cpp +++ b/mozilla/base/src/nsIFileStream.cpp @@ -154,6 +154,10 @@ class FileImpl *aWriteCount = bytesWrit; return NS_OK; } + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) + { + return NS_ERROR_NOT_IMPLEMENTED; + } NS_IMETHOD Flush(); NS_IMETHOD GetAtEOF(PRBool* outAtEOF) diff --git a/mozilla/base/src/nsIOutputStream.h b/mozilla/base/src/nsIOutputStream.h index 182b212a390..72109101115 100644 --- a/mozilla/base/src/nsIOutputStream.h +++ b/mozilla/base/src/nsIOutputStream.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -21,6 +21,8 @@ #include "nsIBaseStream.h" +class nsIInputStream; + /* 7f13b870-e95f-11d1-beae-00805f8a66dc */ #define NS_IOUTPUTSTREAM_IID \ { 0x7f13b870, 0xe95f, 0x11d1, \ @@ -42,6 +44,29 @@ public: */ NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0; + + /** + * Writes data into the stream from an input stream. + * Implementer's note: This method is defined by this interface in order + * to allow the output stream to efficiently copy the data from the input + * stream into its internal buffer (if any). If this method was provide + * as an external facility, a separate char* buffer would need to be used + * in order to call the output stream's other Write method. + * @param fromStream the stream from which the data is 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(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0; + + /** + * Flushes the stream. + */ + NS_IMETHOD + Flush(void) = 0; + }; diff --git a/mozilla/base/src/nsIStringStream.cpp b/mozilla/base/src/nsIStringStream.cpp index ee1e5b35cd7..26355091eb9 100644 --- a/mozilla/base/src/nsIStringStream.cpp +++ b/mozilla/base/src/nsIStringStream.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -110,6 +110,10 @@ class BasicStringImpl *aWriteCount = bytesWrit; return NS_OK; } + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) + { + return NS_ERROR_NOT_IMPLEMENTED; + } public: // nsISupports interface diff --git a/mozilla/base/tests/TestPipes.cpp b/mozilla/base/tests/TestPipes.cpp index 064297c7097..f3fb8e84079 100644 --- a/mozilla/base/tests/TestPipes.cpp +++ b/mozilla/base/tests/TestPipes.cpp @@ -19,6 +19,7 @@ #include "nsIThread.h" #include "nsIByteBufferInputStream.h" #include "prprf.h" +#include "prinrval.h" #include "plstr.h" #include @@ -34,22 +35,26 @@ public: nsresult rv; char buf[101]; PRUint32 count; + PRIntervalTime start = PR_IntervalNow(); while (PR_TRUE) { rv = mIn->Read(buf, 100, &count); if (rv == NS_BASE_STREAM_EOF) { - printf("EOF count = %d\n", mCount); - return NS_OK; +// printf("EOF count = %d\n", mCount); + rv = NS_OK; + break; } if (NS_FAILED(rv)) { printf("read failed\n"); - return rv; + break; } buf[count] = '\0'; - printf(buf); +// printf(buf); mCount += count; } + PRIntervalTime end = PR_IntervalNow(); + printf("read time = %dms\n", PR_IntervalToMilliseconds(end - start)); return rv; } @@ -83,6 +88,7 @@ main() rv = NS_NewThread(&receiver, new nsReceiver(in)); NS_RELEASE(in); + PRIntervalTime start = PR_IntervalNow(); for (PRUint32 i = 0; i < ITERATIONS; i++) { PRUint32 writeCount; char* buf = PR_smprintf("%d %s", i, kTestPattern); @@ -92,9 +98,11 @@ main() } rv = out->Close(); NS_ASSERTION(NS_SUCCEEDED(rv), "close failed"); + PRIntervalTime end = PR_IntervalNow(); receiver->Join(); NS_RELEASE(receiver); + printf("write time = %dms\n", PR_IntervalToMilliseconds(end - start)); return 0; } diff --git a/mozilla/editor/txmgr/tests/TestTXMgr.cpp b/mozilla/editor/txmgr/tests/TestTXMgr.cpp index 8149fc64cc1..acf2c0197c6 100644 --- a/mozilla/editor/txmgr/tests/TestTXMgr.cpp +++ b/mozilla/editor/txmgr/tests/TestTXMgr.cpp @@ -447,6 +447,15 @@ public: fflush(stdout); return NS_OK; } + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) + { + return NS_ERROR_NOT_IMPLEMENTED; + } + NS_IMETHOD Flush() + { + fflush(stdout); + return NS_OK; + } }; NS_IMPL_ADDREF(ConsoleOutput) diff --git a/mozilla/mailnews/mime/src/plugin_inst.h b/mozilla/mailnews/mime/src/plugin_inst.h index e5977f48a17..14488d6700d 100644 --- a/mozilla/mailnews/mime/src/plugin_inst.h +++ b/mozilla/mailnews/mime/src/plugin_inst.h @@ -55,6 +55,13 @@ public: NS_IMETHOD Write(const char *aBuf, PRUint32 aLen, PRUint32 *aWriteLength); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + NS_IMETHOD Flush(void) { + return NS_OK; + } + // nsIBaseStream interface NS_IMETHOD Close(void); diff --git a/mozilla/modules/plugin/bad/badapter.cpp b/mozilla/modules/plugin/bad/badapter.cpp index 8c06f4a7fee..c94c17ac11a 100644 --- a/mozilla/modules/plugin/bad/badapter.cpp +++ b/mozilla/modules/plugin/bad/badapter.cpp @@ -216,6 +216,14 @@ public: NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + return NS_OK; + } + ////////////////////////////////////////////////////////////////////////// // // Specific methods to nsIPluginManagerStream. diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp index e1e6a9df18e..399a98635f5 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -158,6 +158,14 @@ public: NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + return NS_OK; + } + // nsIBaseStream interface NS_IMETHOD diff --git a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index e1e6a9df18e..399a98635f5 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -158,6 +158,14 @@ public: NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + return NS_OK; + } + // nsIBaseStream interface NS_IMETHOD diff --git a/mozilla/modules/plugin/samples/backward/badapter.cpp b/mozilla/modules/plugin/samples/backward/badapter.cpp index 8c06f4a7fee..c94c17ac11a 100644 --- a/mozilla/modules/plugin/samples/backward/badapter.cpp +++ b/mozilla/modules/plugin/samples/backward/badapter.cpp @@ -216,6 +216,14 @@ public: NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + return NS_OK; + } + ////////////////////////////////////////////////////////////////////////// // // Specific methods to nsIPluginManagerStream. diff --git a/mozilla/modules/plugin/src/npglue.h b/mozilla/modules/plugin/src/npglue.h index 5a2c064ab06..2d0318a318c 100644 --- a/mozilla/modules/plugin/src/npglue.h +++ b/mozilla/modules/plugin/src/npglue.h @@ -674,8 +674,15 @@ public: * @return number of bytes read or an error if < 0 */ NS_IMETHOD - Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, - PRInt32 *resultingCount); + Write(const char* aBuf, PRInt32 aCount, PRInt32 *resultingCount); + + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + return NS_OK; + } //////////////////////////////////////////////////////////////////////////// // nsPluginManagerStream specific methods: diff --git a/mozilla/modules/plugin/src/nsPluginManagerStream.h b/mozilla/modules/plugin/src/nsPluginManagerStream.h index 9fe3ca2c1e2..ffed830dfdd 100644 --- a/mozilla/modules/plugin/src/nsPluginManagerStream.h +++ b/mozilla/modules/plugin/src/nsPluginManagerStream.h @@ -41,8 +41,15 @@ public: * @return number of bytes read or an error if < 0 */ NS_IMETHOD - Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount, - PRInt32 *resultingCount); + Write(const char* aBuf, PRInt32 aCount, PRInt32 *resultingCount); + + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + return NS_OK; + } //////////////////////////////////////////////////////////////////////////// // nsPluginManagerStream specific methods: diff --git a/mozilla/network/cnvts/nsNetConverterStream.h b/mozilla/network/cnvts/nsNetConverterStream.h index 39c339ab70b..3dea98c1a8b 100644 --- a/mozilla/network/cnvts/nsNetConverterStream.h +++ b/mozilla/network/cnvts/nsNetConverterStream.h @@ -48,6 +48,13 @@ public: PRUint32 aLen, PRUint32 *aWriteLength); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush(void) { + return NS_OK; + } // nsIBaseStream interface diff --git a/mozilla/network/module/nsNetStream.h b/mozilla/network/module/nsNetStream.h index b4da2eda3f0..2091c4a6d50 100644 --- a/mozilla/network/module/nsNetStream.h +++ b/mozilla/network/module/nsNetStream.h @@ -112,6 +112,14 @@ public: PRUint32 aLen, PRUint32 *aWriteCount); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush(void) { + return NS_OK; + } + protected: virtual ~nsBufferedStream(); @@ -148,6 +156,14 @@ public: PRUint32 aLen, PRUint32 *aWriteLength); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush(void) { + return NS_OK; + } + protected: virtual ~nsAsyncStream(); @@ -186,6 +202,14 @@ public: PRUint32 aLen, PRUint32 *aWriteLength); + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush(void) { + return NS_OK; + } + protected: virtual ~nsBlockingStream(); diff --git a/mozilla/network/public/nsIStreamObserver.h b/mozilla/network/public/nsIStreamObserver.h index 1967561fd1d..b9b0cbe0e70 100644 --- a/mozilla/network/public/nsIStreamObserver.h +++ b/mozilla/network/public/nsIStreamObserver.h @@ -23,11 +23,8 @@ #include "nscore.h" /* forward declaration */ -class nsIInputStream; -class nsString; class nsIURL; - /* 97566110-ff60-11d1-beb9-00805f8a66dc */ #define NS_ISTREAMOBSERVER_IID \ { 0x97566110, 0xff60, 0x11d1, \ diff --git a/mozilla/rdf/tests/rdfcat/rdfcat.cpp b/mozilla/rdf/tests/rdfcat/rdfcat.cpp index e724d53505f..941dba185a1 100644 --- a/mozilla/rdf/tests/rdfcat/rdfcat.cpp +++ b/mozilla/rdf/tests/rdfcat/rdfcat.cpp @@ -146,6 +146,15 @@ public: *aWriteCount = aCount; return NS_OK; } + + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush(void) { + PR_Sync(PR_GetSpecialFD(PR_StandardOutput)); + return NS_OK; + } }; NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, kIOutputStreamIID); diff --git a/mozilla/rdf/tests/rdfsink/rdfsink.cpp b/mozilla/rdf/tests/rdfsink/rdfsink.cpp index 2ed6f38bb4a..de6bf574682 100644 --- a/mozilla/rdf/tests/rdfsink/rdfsink.cpp +++ b/mozilla/rdf/tests/rdfsink/rdfsink.cpp @@ -136,6 +136,16 @@ public: *aWriteCount = aCount; return NS_OK; } + + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD Flush() { + PR_Sync(PR_GetSpecialFD(PR_StandardOutput)); + return NS_OK; + } + }; NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, kIOutputStreamIID); diff --git a/mozilla/xpcom/io/nsByteBufferInputStream.cpp b/mozilla/xpcom/io/nsByteBufferInputStream.cpp index ff8f45b9fb2..161015b1b01 100644 --- a/mozilla/xpcom/io/nsByteBufferInputStream.cpp +++ b/mozilla/xpcom/io/nsByteBufferInputStream.cpp @@ -24,7 +24,7 @@ class nsByteBufferInputStream; //////////////////////////////////////////////////////////////////////////////// -class nsByteBufferOutputStream : public nsIByteBufferOutputStream +class nsByteBufferOutputStream : public nsIOutputStream { public: NS_DECL_ISUPPORTS @@ -34,9 +34,8 @@ public: // nsIOutputStream methods: NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); - - // nsIByteBufferOutputStream methods: NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount); + NS_IMETHOD Flush(void); // nsByteBufferOutputStream methods: nsByteBufferOutputStream(nsByteBufferInputStream* in); @@ -71,7 +70,8 @@ public: friend class nsByteBufferOutputStream; nsresult Init(void); - void SetEOF(void); + nsresult SetEOF(void); + nsresult Drain(void); PRBool AtEOF() { return mEOF && (mReadCursor == mWriteCursor) && !mFull; } @@ -101,8 +101,8 @@ public: PRInt32 amt = PR_MIN(max, diff); if (amt > 0) { nsCRT::memcpy(toBuf, &mBuffer[mReadCursor], amt); -#ifdef NS_DEBUG - nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt); +#ifdef DEBUG_warren +// nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt); #endif mReadCursor += amt; *totalRef += amt; @@ -243,14 +243,17 @@ nsByteBufferInputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr) NS_IMETHODIMP nsByteBufferInputStream::Close(void) { + nsresult rv = NS_OK; if (mBlocking) PR_CEnterMonitor(this); mClosed = PR_TRUE; if (mBlocking) { - PR_CNotify(this); // wake up the writer + PRStatus status = PR_CNotify(this); // wake up the writer + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; PR_CExitMonitor(this); } - return NS_OK; + return rv; } NS_IMETHODIMP @@ -281,7 +284,7 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) PR_CEnterMonitor(this); *aReadCount = 0; - /*while (aCount > 0)*/ { // XXX should this block trying to fill the buffer, or return ASAP? + /*while (aCount > 0)*/ { if (ReadableAmount() == 0) { if (mBlocking) { PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT); @@ -325,8 +328,11 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) if (*aReadCount) mFull = PR_FALSE; - if (mBlocking) - PR_CNotify(this); // tell the writer there's space + if (mBlocking) { + PRStatus status = PR_CNotify(this); // tell the writer there's space + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; + } } done: if (mBlocking) @@ -401,8 +407,11 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount) if (mWriteCursor == mReadCursor) mFull = PR_TRUE; - if (mBlocking) - PR_CNotify(this); // tell the reader there's more + if (mBlocking) { + PRStatus status = PR_CNotify(this); // tell the reader there's more + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; + } } done: if (mBlocking) @@ -410,16 +419,46 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount) return rv; } -void +nsresult nsByteBufferInputStream::SetEOF() { + nsresult rv = NS_OK; if (mBlocking) PR_CEnterMonitor(this); mEOF = PR_TRUE; if (mBlocking) { - PR_CNotify(this); // wake up the reader + PRStatus status = PR_CNotify(this); // wake up the reader + if (status != PR_SUCCESS) + rv = NS_ERROR_FAILURE; PR_CExitMonitor(this); } + return rv; +} + +nsresult +nsByteBufferInputStream::Drain() +{ + nsresult rv = NS_OK; + if (mBlocking) { + PR_CEnterMonitor(this); + while (ReadableAmount() != 0) { + PRStatus status = PR_CNotify(this); // wake up the reader + if (status != PR_SUCCESS) { + rv = NS_ERROR_FAILURE; + break; + } + else { + // wait for the reader to take all the data + status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT); + if (status != PR_SUCCESS) { + rv = NS_ERROR_FAILURE; + break; + } + } + } + PR_CExitMonitor(this); + } + return rv; } //////////////////////////////////////////////////////////////////////////////// @@ -447,8 +486,7 @@ nsByteBufferOutputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr) { if (aInstancePtr == nsnull) return NS_ERROR_NULL_POINTER; - if (aIID.Equals(nsIByteBufferOutputStream::GetIID()) || - aIID.Equals(nsIOutputStream::GetIID()) || + if (aIID.Equals(nsIOutputStream::GetIID()) || aIID.Equals(nsIBaseStream::GetIID()) || aIID.Equals(nsISupports::GetIID())) { *aInstancePtr = this; @@ -477,6 +515,12 @@ nsByteBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCoun return mInputStream->Fill(fromStream, aWriteCount); } +NS_IMETHODIMP +nsByteBufferOutputStream::Flush(void) +{ + return mInputStream->Drain(); +} + //////////////////////////////////////////////////////////////////////////////// NS_BASE nsresult diff --git a/mozilla/xpcom/io/nsIByteBufferInputStream.h b/mozilla/xpcom/io/nsIByteBufferInputStream.h index 15d0c4df79f..5badc956642 100644 --- a/mozilla/xpcom/io/nsIByteBufferInputStream.h +++ b/mozilla/xpcom/io/nsIByteBufferInputStream.h @@ -42,25 +42,6 @@ public: //////////////////////////////////////////////////////////////////////////////// -// XXX regenerate: -#define NS_IBYTEBUFFEROUTPUTSTREAM_IID \ -{ /* 924df6d0-f192-11d2-9322-000000000000 */ \ - 0x924df6d0, \ - 0xf192, \ - 0x11d2, \ - {0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \ -} - -class nsIByteBufferOutputStream : public nsIOutputStream { -public: - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBYTEBUFFEROUTPUTSTREAM_IID); - - NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0; - -}; - -//////////////////////////////////////////////////////////////////////////////// - extern NS_BASE nsresult NS_NewByteBufferInputStream(nsIByteBufferInputStream* *result, PRBool blocking = PR_FALSE, diff --git a/mozilla/xpcom/io/nsIFileStream.cpp b/mozilla/xpcom/io/nsIFileStream.cpp index daf67071de8..4a1ea37e297 100644 --- a/mozilla/xpcom/io/nsIFileStream.cpp +++ b/mozilla/xpcom/io/nsIFileStream.cpp @@ -154,6 +154,10 @@ class FileImpl *aWriteCount = bytesWrit; return NS_OK; } + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) + { + return NS_ERROR_NOT_IMPLEMENTED; + } NS_IMETHOD Flush(); NS_IMETHOD GetAtEOF(PRBool* outAtEOF) diff --git a/mozilla/xpcom/io/nsIFileStream.h b/mozilla/xpcom/io/nsIFileStream.h index f27ccf1ccdf..8f2ee8f05bb 100644 --- a/mozilla/xpcom/io/nsIFileStream.h +++ b/mozilla/xpcom/io/nsIFileStream.h @@ -101,8 +101,6 @@ class nsIFileOutputStream { public: static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; } - NS_IMETHOD Flush() = 0; - // Forces a write to disk. }; // class nsIFileOutputStream //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsIOutputStream.h b/mozilla/xpcom/io/nsIOutputStream.h index 182b212a390..72109101115 100644 --- a/mozilla/xpcom/io/nsIOutputStream.h +++ b/mozilla/xpcom/io/nsIOutputStream.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -21,6 +21,8 @@ #include "nsIBaseStream.h" +class nsIInputStream; + /* 7f13b870-e95f-11d1-beae-00805f8a66dc */ #define NS_IOUTPUTSTREAM_IID \ { 0x7f13b870, 0xe95f, 0x11d1, \ @@ -42,6 +44,29 @@ public: */ NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0; + + /** + * Writes data into the stream from an input stream. + * Implementer's note: This method is defined by this interface in order + * to allow the output stream to efficiently copy the data from the input + * stream into its internal buffer (if any). If this method was provide + * as an external facility, a separate char* buffer would need to be used + * in order to call the output stream's other Write method. + * @param fromStream the stream from which the data is 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(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0; + + /** + * Flushes the stream. + */ + NS_IMETHOD + Flush(void) = 0; + }; diff --git a/mozilla/xpcom/io/nsIStringStream.cpp b/mozilla/xpcom/io/nsIStringStream.cpp index ee1e5b35cd7..26355091eb9 100644 --- a/mozilla/xpcom/io/nsIStringStream.cpp +++ b/mozilla/xpcom/io/nsIStringStream.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public License * Version 1.0 (the "NPL"); you may not use this file except in @@ -110,6 +110,10 @@ class BasicStringImpl *aWriteCount = bytesWrit; return NS_OK; } + NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) + { + return NS_ERROR_NOT_IMPLEMENTED; + } public: // nsISupports interface diff --git a/mozilla/xpcom/tests/TestPipes.cpp b/mozilla/xpcom/tests/TestPipes.cpp index 064297c7097..f3fb8e84079 100644 --- a/mozilla/xpcom/tests/TestPipes.cpp +++ b/mozilla/xpcom/tests/TestPipes.cpp @@ -19,6 +19,7 @@ #include "nsIThread.h" #include "nsIByteBufferInputStream.h" #include "prprf.h" +#include "prinrval.h" #include "plstr.h" #include @@ -34,22 +35,26 @@ public: nsresult rv; char buf[101]; PRUint32 count; + PRIntervalTime start = PR_IntervalNow(); while (PR_TRUE) { rv = mIn->Read(buf, 100, &count); if (rv == NS_BASE_STREAM_EOF) { - printf("EOF count = %d\n", mCount); - return NS_OK; +// printf("EOF count = %d\n", mCount); + rv = NS_OK; + break; } if (NS_FAILED(rv)) { printf("read failed\n"); - return rv; + break; } buf[count] = '\0'; - printf(buf); +// printf(buf); mCount += count; } + PRIntervalTime end = PR_IntervalNow(); + printf("read time = %dms\n", PR_IntervalToMilliseconds(end - start)); return rv; } @@ -83,6 +88,7 @@ main() rv = NS_NewThread(&receiver, new nsReceiver(in)); NS_RELEASE(in); + PRIntervalTime start = PR_IntervalNow(); for (PRUint32 i = 0; i < ITERATIONS; i++) { PRUint32 writeCount; char* buf = PR_smprintf("%d %s", i, kTestPattern); @@ -92,9 +98,11 @@ main() } rv = out->Close(); NS_ASSERTION(NS_SUCCEEDED(rv), "close failed"); + PRIntervalTime end = PR_IntervalNow(); receiver->Join(); NS_RELEASE(receiver); + printf("write time = %dms\n", PR_IntervalToMilliseconds(end - start)); return 0; } diff --git a/mozilla/xpfe/browser/src/nsWidgetListener.h b/mozilla/xpfe/browser/src/nsWidgetListener.h index 696d9eb72d6..b67aeec2086 100644 --- a/mozilla/xpfe/browser/src/nsWidgetListener.h +++ b/mozilla/xpfe/browser/src/nsWidgetListener.h @@ -37,6 +37,7 @@ class nsWidgetListener : public nsIWidgetController, { public: nsWidgetListener(); + NS_IMETHOD ProcessEvent(class nsIDOMEvent *) { return NS_OK; } // nsISupports interface NS_DECL_ISUPPORTS @@ -72,4 +73,4 @@ protected: nsresult AddEventListener(nsISupports* aNode, const nsIID& aInterfaceIID); }; -#endif /* nsWidgetListener_h__ */ \ No newline at end of file +#endif /* nsWidgetListener_h__ */