From f29b00bbe4988167b8a0dd8d30db9b14c7f2ab5f Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Tue, 22 Aug 2000 07:03:33 +0000 Subject: [PATCH] Bug 46777. Redesigned stream interfaces to allows stream observers to be decoupled from pipe implementation. Needed for embedding to fix 'spin' problem. r=rpotts,valeski,ruslan git-svn-id: svn://10.0.0.236/trunk@76875 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/xbl/src/nsXBLService.cpp | 16 ++ .../xul/document/src/nsXULDocument.cpp | 23 +- mozilla/editor/txmgr/tests/TestTXMgr.cpp | 37 +++ mozilla/htmlparser/src/nsParser.cpp | 2 +- mozilla/layout/xbl/src/nsXBLService.cpp | 16 ++ .../mailnews/absync/src/nsAbSyncPostEngine.h | 2 +- mozilla/mailnews/base/util/nsMsgFolder.cpp | 2 +- mozilla/mailnews/compose/src/nsURLFetcher.h | 2 +- mozilla/mailnews/imap/src/nsImapProtocol.h | 8 +- .../mime/emitters/src/nsMimeBaseEmitter.cpp | 13 +- .../mime/emitters/src/nsMimeBaseEmitter.h | 9 +- .../mailnews/mime/src/nsStreamConverter.cpp | 15 +- mozilla/mailnews/mime/src/nsStreamConverter.h | 8 +- mozilla/mailnews/news/src/nsNNTPProtocol.h | 8 +- mozilla/modules/libjar/nsJARInputStream.cpp | 28 +++ mozilla/modules/libjar/nsJARInputStream.h | 3 - .../plugin/base/src/nsPluginHostImpl.cpp | 2 +- .../plugin/base/src/nsPluginInstancePeer.cpp | 63 ++++-- .../plugin/nglsrc/nsPluginHostImpl.cpp | 2 +- .../plugin/nglsrc/nsPluginInstancePeer.cpp | 63 ++++-- mozilla/netwerk/base/public/nsIIOService.idl | 9 + .../netwerk/base/public/nsIStreamListener.idl | 6 +- mozilla/netwerk/base/public/nsNetUtil.h | 2 +- .../base/src/nsAsyncStreamListener.cpp | 2 +- .../netwerk/base/src/nsBufferedStreams.cpp | 103 +++++++-- mozilla/netwerk/base/src/nsBufferedStreams.h | 12 +- .../base/src/nsDirectoryIndexStream.cpp | 32 ++- .../netwerk/base/src/nsDirectoryIndexStream.h | 3 - mozilla/netwerk/base/src/nsFileStreams.cpp | 76 ++++++- mozilla/netwerk/base/src/nsFileStreams.h | 8 +- mozilla/netwerk/base/src/nsFileTransport.cpp | 56 ++--- mozilla/netwerk/base/src/nsFileTransport.h | 14 +- mozilla/netwerk/base/src/nsIOService.cpp | 35 +++ .../netwerk/base/src/nsSocketTransport.cpp | 97 ++++---- mozilla/netwerk/base/src/nsSocketTransport.h | 22 +- .../netwerk/base/src/nsSyncStreamListener.cpp | 15 +- .../netwerk/base/src/nsSyncStreamListener.h | 9 +- .../filecache/nsDiskCacheRecordChannel.cpp | 43 +++- .../cache/memcache/nsMemCacheChannel.cpp | 62 ++++- .../netwerk/cache/mgr/nsCacheEntryChannel.cpp | 36 +++ mozilla/netwerk/cache/mgr/nsCachedNetData.cpp | 20 ++ .../protocol/data/src/nsDataChannel.cpp | 11 +- .../netwerk/protocol/ftp/src/nsFTPChannel.cpp | 2 +- .../protocol/ftp/src/nsFtpConnectionThread.h | 4 +- .../netwerk/protocol/http/src/nsHTTPChannel.h | 4 +- .../protocol/http/src/nsHTTPEncodeStream.cpp | 29 +++ .../protocol/http/src/nsHTTPEncodeStream.h | 1 - .../protocol/http/src/nsHTTPRequest.cpp | 4 +- .../http/src/nsHTTPResponseListener.cpp | 164 +++++--------- .../http/src/nsHTTPResponseListener.h | 4 +- .../converters/nsUnknownDecoder.cpp | 10 +- .../src/nsStreamConverterService.cpp | 4 +- mozilla/netwerk/test/TestCallbacks.cpp | 1 - mozilla/netwerk/test/TestFileInput.cpp | 10 +- mozilla/netwerk/test/TestProtocols.cpp | 2 +- mozilla/netwerk/test/TestSocketIO.cpp | 31 +-- mozilla/netwerk/test/TestSocketInput.cpp | 2 +- mozilla/netwerk/test/TestSocketTransport.cpp | 41 +--- mozilla/parser/htmlparser/src/nsParser.cpp | 2 +- mozilla/rdf/base/src/nsRDFXMLDataSource.cpp | 20 ++ mozilla/rdf/content/src/nsXULDocument.cpp | 23 +- mozilla/rdf/content/src/nsXULKeyListener.cpp | 20 ++ mozilla/rdf/tests/rdfcat/rdfcat.cpp | 36 +++ mozilla/xpcom/build/dlldeps.cpp | 2 +- mozilla/xpcom/ds/nsCRT.h | 4 +- mozilla/xpcom/io/Makefile.in | 3 - mozilla/xpcom/io/makefile.win | 7 +- mozilla/xpcom/io/nsBinaryStream.cpp | 76 +++++++ mozilla/xpcom/io/nsBinaryStream.h | 6 - mozilla/xpcom/io/nsByteArrayInputStream.cpp | 30 ++- mozilla/xpcom/io/nsByteArrayInputStream.h | 3 - mozilla/xpcom/io/nsIBinaryInputStream.idl | 2 +- mozilla/xpcom/io/nsIFileStream.cpp | 85 ++++++- mozilla/xpcom/io/nsIInputStream.idl | 97 ++++++-- mozilla/xpcom/io/nsIOutputStream.idl | 93 +++++++- mozilla/xpcom/io/nsIPipe.idl | 33 ++- mozilla/xpcom/io/nsIScriptableInputStream.idl | 10 +- mozilla/xpcom/io/nsIStringStream.cpp | 81 ++++++- mozilla/xpcom/io/nsPipe2.cpp | 211 ++++++++++-------- mozilla/xpcom/io/nsScriptableInputStream.cpp | 2 +- mozilla/xpcom/io/nsScriptableInputStream.h | 3 - mozilla/xpcom/io/nsStorageStream.cpp | 73 +++++- mozilla/xpcom/io/nsStorageStream.h | 1 - mozilla/xpcom/tests/TestPipes.cpp | 133 +++++------ .../bookmarks/src/nsBookmarksService.cpp | 2 +- .../related/src/nsRelatedLinksHandler.cpp | 2 +- mozilla/xpinstall/src/nsXPInstallManager.cpp | 1 - 87 files changed, 1715 insertions(+), 654 deletions(-) diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index bae43a5fcb7..46f17a23eb7 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -416,6 +416,22 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + return NS_ERROR_NOT_IMPLEMENTED; + } + // Implementation void SetBuffer(const char* aBuffer, PRUint32 aSize) { mBuffer = aBuffer; diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 1b0806874c8..eb75cc1e35a 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -280,6 +280,26 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + // Implementation void SetBuffer(const char* aBuffer, PRUint32 aSize) { mBuffer = aBuffer; @@ -343,7 +363,7 @@ public: NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; } NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; } NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; } - NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); return NS_ERROR_NOT_IMPLEMENTED; } + NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); NS_NOTREACHED("NOTREACHED"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD GetTransferOffset(PRUint32 *aTransferOffset) { NS_NOTREACHED("GetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD SetTransferOffset(PRUint32 aTransferOffset) { NS_NOTREACHED("SetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD GetTransferCount(PRInt32 *aTransferCount) { NS_NOTREACHED("GetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -830,6 +850,7 @@ nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal) NS_IMETHODIMP nsXULDocument::AddPrincipal(nsIPrincipal *aPrincipal) { + NS_NOTREACHED("AddPrincipal"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/editor/txmgr/tests/TestTXMgr.cpp b/mozilla/editor/txmgr/tests/TestTXMgr.cpp index c0d6270d635..1fbcc27ac57 100644 --- a/mozilla/editor/txmgr/tests/TestTXMgr.cpp +++ b/mozilla/editor/txmgr/tests/TestTXMgr.cpp @@ -456,6 +456,43 @@ public: fflush(stdout); return NS_OK; } + + + NS_IMETHOD + WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetNonBlocking(PRBool aNonBlocking) { + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetObserver(nsIOutputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetObserver(nsIOutputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } }; NS_IMPL_ADDREF(ConsoleOutput) diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index af0eb9b63ad..225cfcfffa6 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -41,7 +41,7 @@ #include "nsIStringStream.h" #include "nsIChannel.h" #include "nsIProgressEventSink.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "CRtfDTD.h" #include "CNavDTD.h" #include "COtherDTD.h" diff --git a/mozilla/layout/xbl/src/nsXBLService.cpp b/mozilla/layout/xbl/src/nsXBLService.cpp index bae43a5fcb7..46f17a23eb7 100644 --- a/mozilla/layout/xbl/src/nsXBLService.cpp +++ b/mozilla/layout/xbl/src/nsXBLService.cpp @@ -416,6 +416,22 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + return NS_ERROR_NOT_IMPLEMENTED; + } + // Implementation void SetBuffer(const char* aBuffer, PRUint32 aSize) { mBuffer = aBuffer; diff --git a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h index cd854eed6ee..43df4ca17b5 100644 --- a/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h +++ b/mozilla/mailnews/absync/src/nsAbSyncPostEngine.h @@ -23,7 +23,7 @@ #define nsAbSyncPostEngine_h_ #include "nsCOMPtr.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsIStreamListener.h" #include "nsFileStream.h" #include "nsIAbSyncPostEngine.h" diff --git a/mozilla/mailnews/base/util/nsMsgFolder.cpp b/mozilla/mailnews/base/util/nsMsgFolder.cpp index ebde52a62d9..4ec0b69cbda 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgFolder.cpp @@ -576,7 +576,7 @@ nsMsgFolder::parseURI(PRBool needServer) // the name is the trailing directory in the path nsXPIDLCString fileName; rv = url->GetFileName(getter_Copies(fileName)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv) && (const char*)fileName != nsnull) { // XXX conversion to unicode here? is fileName in UTF8? // yes, let's say it is in utf8 diff --git a/mozilla/mailnews/compose/src/nsURLFetcher.h b/mozilla/mailnews/compose/src/nsURLFetcher.h index 50ec9154050..57ccb648e01 100644 --- a/mozilla/mailnews/compose/src/nsURLFetcher.h +++ b/mozilla/mailnews/compose/src/nsURLFetcher.h @@ -23,7 +23,7 @@ #define nsURLFetcher_h_ #include "nsCOMPtr.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsIStreamListener.h" #include "nsFileStream.h" diff --git a/mozilla/mailnews/imap/src/nsImapProtocol.h b/mozilla/mailnews/imap/src/nsImapProtocol.h index d0e41c71e12..76050db614a 100644 --- a/mozilla/mailnews/imap/src/nsImapProtocol.h +++ b/mozilla/mailnews/imap/src/nsImapProtocol.h @@ -29,8 +29,8 @@ #include "nsIEventQueue.h" #include "nsIStreamListener.h" #include "nsIOutputStream.h" -#include "nsIBufferOutputStream.h" -#include "nsIBufferInputStream.h" +#include "nsIOutputStream.h" +#include "nsIInputStream.h" #include "nsImapCore.h" #include "nsString.h" #include "nsIProgressEventSink.h" @@ -316,8 +316,8 @@ private: nsCOMPtr m_outputStream; // this will be obtained from the transport interface nsCOMPtr m_inputStream; - nsCOMPtr m_channelInputStream; - nsCOMPtr m_channelOutputStream; + nsCOMPtr m_channelInputStream; + nsCOMPtr m_channelOutputStream; nsCOMPtr m_channelListener; // if we are displaying an article this is the rfc-822 display sink... nsCOMPtr m_channelContext; nsCOMPtr m_mockChannel; // this is the channel we should forward to people diff --git a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp index cd285051ffd..86860d18c8c 100644 --- a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp +++ b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.cpp @@ -53,7 +53,10 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID); -NS_IMPL_ISUPPORTS2(nsMimeBaseEmitter, nsIMimeEmitter, nsIPipeObserver) +NS_IMPL_ISUPPORTS3(nsMimeBaseEmitter, + nsIMimeEmitter, + nsIInputStreamObserver, + nsIOutputStreamObserver) nsMimeBaseEmitter::nsMimeBaseEmitter() { @@ -240,18 +243,18 @@ nsMimeBaseEmitter::LocalizeHeaderName(const char *aHeaderName, const char *aDefa // nsIPipeObserver Interface /////////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsMimeBaseEmitter::OnWrite(nsIPipe* aPipe, PRUint32 aCount) +NS_IMETHODIMP nsMimeBaseEmitter::OnWrite(nsIOutputStream* out, PRUint32 aCount) { return NS_OK; } -NS_IMETHODIMP nsMimeBaseEmitter::OnEmpty(nsIPipe* aPipe) +NS_IMETHODIMP nsMimeBaseEmitter::OnEmpty(nsIInputStream* in) { return NS_OK; } -NS_IMETHODIMP nsMimeBaseEmitter::OnFull(nsIPipe* /* aPipe */) +NS_IMETHODIMP nsMimeBaseEmitter::OnFull(nsIOutputStream* out) { // the pipe is full so we should flush our data to the converter's listener // in order to make more room. @@ -273,7 +276,7 @@ NS_IMETHODIMP nsMimeBaseEmitter::OnFull(nsIPipe* /* aPipe */) return rv; } -NS_IMETHODIMP nsMimeBaseEmitter::OnClose(nsIPipe* aPipe) +NS_IMETHODIMP nsMimeBaseEmitter::OnClose(nsIInputStream* in) { return NS_OK; } diff --git a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h index 8237d6338c9..29ba3f8d342 100644 --- a/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h +++ b/mozilla/mailnews/mime/emitters/src/nsMimeBaseEmitter.h @@ -27,6 +27,7 @@ #include "nsIMimeEmitter.h" #include "nsMimeRebuffer.h" #include "nsIStreamListener.h" +#include "nsIInputStream.h" #include "nsIOutputStream.h" #include "nsIURI.h" #include "nsIPref.h" @@ -66,7 +67,10 @@ typedef struct { char *value; } headerInfoType; -class nsMimeBaseEmitter : public nsIMimeEmitter, public nsIPipeObserver { +class nsMimeBaseEmitter : public nsIMimeEmitter, + public nsIInputStreamObserver, + public nsIOutputStreamObserver +{ public: nsMimeBaseEmitter (); virtual ~nsMimeBaseEmitter (void); @@ -75,7 +79,8 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIMIMEEMITTER - NS_DECL_NSIPIPEOBSERVER + NS_DECL_NSIINPUTSTREAMOBSERVER + NS_DECL_NSIOUTPUTSTREAMOBSERVER // Utility output functions... NS_IMETHOD UtilityWriteCRLF(const char *buf); diff --git a/mozilla/mailnews/mime/src/nsStreamConverter.cpp b/mozilla/mailnews/mime/src/nsStreamConverter.cpp index c941769086a..1ade284b9e8 100644 --- a/mozilla/mailnews/mime/src/nsStreamConverter.cpp +++ b/mozilla/mailnews/mime/src/nsStreamConverter.cpp @@ -626,16 +626,19 @@ NS_IMETHODIMP nsStreamConverter::Init(nsIURI *aURI, nsIStreamListener * aOutList } // now we want to create a pipe which we'll use for converting the data... - nsCOMPtr pipeObserver = do_QueryInterface(mEmitter); rv = NS_NewPipe(getter_AddRefs(mInputStream), getter_AddRefs(mOutputStream), - pipeObserver, - NS_STREAM_CONVERTER_SEGMENT_SIZE, - NS_STREAM_CONVERTER_BUFFER_SIZE); + NS_STREAM_CONVERTER_SEGMENT_SIZE, + NS_STREAM_CONVERTER_BUFFER_SIZE, + PR_TRUE, PR_TRUE); if (NS_SUCCEEDED(rv)) { - mInputStream->SetNonBlocking(PR_TRUE); - mOutputStream->SetNonBlocking(PR_TRUE); + nsCOMPtr inObs = do_QueryInterface(mEmitter, &rv); + if (NS_SUCCEEDED(rv)) + mInputStream->SetObserver(inObs); + nsCOMPtr outObs = do_QueryInterface(mEmitter, &rv); + if (NS_SUCCEEDED(rv)) + mOutputStream->SetObserver(outObs); } // initialize our emitter diff --git a/mozilla/mailnews/mime/src/nsStreamConverter.h b/mozilla/mailnews/mime/src/nsStreamConverter.h index 186ef98b113..49ccb9f56a7 100644 --- a/mozilla/mailnews/mime/src/nsStreamConverter.h +++ b/mozilla/mailnews/mime/src/nsStreamConverter.h @@ -27,8 +27,8 @@ #include "nsIOutputStream.h" #include "nsIMimeEmitter.h" #include "nsIURI.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsIChannel.h" #include "nsString.h" #include "nsCOMPtr.h" @@ -65,8 +65,8 @@ private: nsresult Close(); // the input and output streams form a pipe...they need to be passed around together.. - nsCOMPtr mOutputStream; // output stream - nsCOMPtr mInputStream; + nsCOMPtr mOutputStream; // output stream + nsCOMPtr mInputStream; nsCOMPtr mOutListener; // output stream listener nsCOMPtr mOutgoingChannel; diff --git a/mozilla/mailnews/news/src/nsNNTPProtocol.h b/mozilla/mailnews/news/src/nsNNTPProtocol.h index fd13c0699ea..7e3a754678b 100644 --- a/mozilla/mailnews/news/src/nsNNTPProtocol.h +++ b/mozilla/mailnews/news/src/nsNNTPProtocol.h @@ -28,8 +28,8 @@ #include "nsCOMPtr.h" #include "nsIInputStream.h" #include "nsIOutputStream.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsINntpUrl.h" #include "nsINntpIncomingServer.h" #include "nsINNTPProtocol.h" @@ -199,8 +199,8 @@ private: nsCOMPtr m_newsFolder; nsCOMPtr m_msgWindow; - nsCOMPtr mDisplayInputStream; - nsCOMPtr mDisplayOutputStream; + nsCOMPtr mDisplayInputStream; + nsCOMPtr mDisplayOutputStream; nsMsgLineStreamBuffer * m_lineStreamBuffer; // used to efficiently extract lines from the incoming data stream // the nsINntpURL that is currently running diff --git a/mozilla/modules/libjar/nsJARInputStream.cpp b/mozilla/modules/libjar/nsJARInputStream.cpp index 824f213e221..a194ae3c93a 100644 --- a/mozilla/modules/libjar/nsJARInputStream.cpp +++ b/mozilla/modules/libjar/nsJARInputStream.cpp @@ -61,6 +61,34 @@ nsJARInputStream::Read(char* buf, PRUint32 count, PRUint32 *bytesRead) return err == ZIP_OK ? NS_OK : NS_ERROR_FAILURE; } +NS_IMETHODIMP +nsJARInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJARInputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJARInputStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsJARInputStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsJARInputStream::Close() { diff --git a/mozilla/modules/libjar/nsJARInputStream.h b/mozilla/modules/libjar/nsJARInputStream.h index 036c57f3090..0bf128ac0b5 100644 --- a/mozilla/modules/libjar/nsJARInputStream.h +++ b/mozilla/modules/libjar/nsJARInputStream.h @@ -47,9 +47,6 @@ class nsJARInputStream : public nsIInputStream NS_DEFINE_STATIC_CID_ACCESSOR( NS_JARINPUTSTREAM_CID ); NS_DECL_ISUPPORTS - - NS_DECL_NSIBASESTREAM - NS_DECL_NSIINPUTSTREAM static NS_METHOD diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 9125c57d0f1..4e350fb78d0 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -36,7 +36,7 @@ #include "nsIPref.h" #include "nsIFile.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsIIOService.h" #include "nsIURL.h" #include "nsIChannel.h" diff --git a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp index 3971fef2af9..01cc6d3e0a8 100644 --- a/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginInstancePeer.cpp @@ -164,21 +164,8 @@ public: virtual ~nsPluginStreamToFile(); NS_DECL_ISUPPORTS - - // nsIOutputStream interface + NS_DECL_NSIOUTPUTSTREAM - NS_IMETHOD - Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); - - NS_IMETHOD Flush() { - return NS_OK; - } - - // nsIBaseStream interface - - NS_IMETHOD - Close(void); - protected: char* mTarget; nsFileURL mFileURL; @@ -267,6 +254,12 @@ nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID, return NS_NOINTERFACE; } +NS_IMETHODIMP +nsPluginStreamToFile::Flush() +{ + return NS_OK; +} + NS_IMETHODIMP nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) { @@ -281,6 +274,48 @@ nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteC return NS_OK; } + +NS_IMETHODIMP +nsPluginStreamToFile::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} NS_IMETHODIMP nsPluginStreamToFile::Close(void) diff --git a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp index 9125c57d0f1..4e350fb78d0 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginHostImpl.cpp @@ -36,7 +36,7 @@ #include "nsIPref.h" #include "nsIFile.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsIIOService.h" #include "nsIURL.h" #include "nsIChannel.h" diff --git a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp index 3971fef2af9..01cc6d3e0a8 100644 --- a/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp +++ b/mozilla/modules/plugin/nglsrc/nsPluginInstancePeer.cpp @@ -164,21 +164,8 @@ public: virtual ~nsPluginStreamToFile(); NS_DECL_ISUPPORTS - - // nsIOutputStream interface + NS_DECL_NSIOUTPUTSTREAM - NS_IMETHOD - Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); - - NS_IMETHOD Flush() { - return NS_OK; - } - - // nsIBaseStream interface - - NS_IMETHOD - Close(void); - protected: char* mTarget; nsFileURL mFileURL; @@ -267,6 +254,12 @@ nsresult nsPluginStreamToFile::QueryInterface(const nsIID& aIID, return NS_NOINTERFACE; } +NS_IMETHODIMP +nsPluginStreamToFile::Flush() +{ + return NS_OK; +} + NS_IMETHODIMP nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) { @@ -281,6 +274,48 @@ nsPluginStreamToFile::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteC return NS_OK; } + +NS_IMETHODIMP +nsPluginStreamToFile::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsPluginStreamToFile::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} NS_IMETHODIMP nsPluginStreamToFile::Close(void) diff --git a/mozilla/netwerk/base/public/nsIIOService.idl b/mozilla/netwerk/base/public/nsIIOService.idl index 2a8b6589baf..58498496885 100644 --- a/mozilla/netwerk/base/public/nsIIOService.idl +++ b/mozilla/netwerk/base/public/nsIIOService.idl @@ -104,6 +104,15 @@ interface nsIIOService : nsISupports */ attribute boolean offline; + /** + * Consumes all input from the channel, feading data to the specified stream + * listener. The function does not return until either all the data is + * consumed, or an error occurs. + */ + void consumeInput(in nsIChannel channel, + in nsISupports ctxt, + in nsIStreamListener consumer); + //////////////////////////////////////////////////////////////////////////// // URL parsing utilities diff --git a/mozilla/netwerk/base/public/nsIStreamListener.idl b/mozilla/netwerk/base/public/nsIStreamListener.idl index 6739486b72a..55d6c5840c5 100644 --- a/mozilla/netwerk/base/public/nsIStreamListener.idl +++ b/mozilla/netwerk/base/public/nsIStreamListener.idl @@ -22,9 +22,9 @@ #include "nsIStreamObserver.idl" -interface nsIBufferInputStream; interface nsIInputStream; -interface nsIBufferOutputStream; +interface nsIInputStream; +interface nsIOutputStream; interface nsIEventQueue; [scriptable, uuid(1a637020-1482-11d3-9333-00104ba0fd40)] @@ -70,7 +70,7 @@ interface nsISyncStreamListener : nsIStreamListener * Initializes an nsISyncStreamListener. */ void init(out nsIInputStream inStream, - out nsIBufferOutputStream outStream); + out nsIOutputStream outStream); }; %{C++ diff --git a/mozilla/netwerk/base/public/nsNetUtil.h b/mozilla/netwerk/base/public/nsNetUtil.h index 9ad479d7690..299363df472 100644 --- a/mozilla/netwerk/base/public/nsNetUtil.h +++ b/mozilla/netwerk/base/public/nsNetUtil.h @@ -391,7 +391,7 @@ NS_NewAsyncStreamListener(nsIStreamListener **result, inline nsresult NS_NewSyncStreamListener(nsIInputStream **inStream, - nsIBufferOutputStream **outStream, + nsIOutputStream **outStream, nsIStreamListener **listener) { nsresult rv; diff --git a/mozilla/netwerk/base/src/nsAsyncStreamListener.cpp b/mozilla/netwerk/base/src/nsAsyncStreamListener.cpp index 24c82a4442e..22aa4daea42 100644 --- a/mozilla/netwerk/base/src/nsAsyncStreamListener.cpp +++ b/mozilla/netwerk/base/src/nsAsyncStreamListener.cpp @@ -21,7 +21,7 @@ */ #include "nsAsyncStreamListener.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsString.h" #include "nsCRT.h" #include "nsIEventQueueService.h" diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.cpp b/mozilla/netwerk/base/src/nsBufferedStreams.cpp index aa2860bc47f..1d1f9601930 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.cpp +++ b/mozilla/netwerk/base/src/nsBufferedStreams.cpp @@ -41,12 +41,10 @@ nsBufferedStream::~nsBufferedStream() Close(); } -NS_IMPL_THREADSAFE_ISUPPORTS2(nsBufferedStream, - nsIBaseStream, - nsISeekableStream); +NS_IMPL_THREADSAFE_ISUPPORTS1(nsBufferedStream, nsISeekableStream); nsresult -nsBufferedStream::Init(nsIBaseStream* stream, PRUint32 bufferSize) +nsBufferedStream::Init(nsISupports* stream, PRUint32 bufferSize) { NS_ASSERTION(stream, "need to supply a stream"); NS_ASSERTION(mStream == nsnull, "already inited"); @@ -61,14 +59,11 @@ nsBufferedStream::Init(nsIBaseStream* stream, PRUint32 bufferSize) return NS_OK; } -NS_IMETHODIMP +nsresult nsBufferedStream::Close() { nsresult rv = NS_OK; - if (mStream) { - rv = mStream->Close(); - NS_RELEASE(mStream); - mStream = nsnull; + if (mBuffer) { delete[] mBuffer; mBuffer = nsnull; mBufferSize = 0; @@ -174,7 +169,14 @@ nsBufferedInputStream::Init(nsIInputStream* stream, PRUint32 bufferSize) NS_IMETHODIMP nsBufferedInputStream::Close() { - return nsBufferedStream::Close(); + nsresult rv1 = NS_OK, rv2; + if (mStream) { + rv1 = Source()->Close(); + NS_RELEASE(mStream); + } + rv2 = nsBufferedStream::Close(); + if (NS_FAILED(rv1)) return rv1; + return rv2; } NS_IMETHODIMP @@ -206,6 +208,34 @@ nsBufferedInputStream::Read(char * buf, PRUint32 count, PRUint32 *result) return (read > 0 || rv == NS_BASE_STREAM_CLOSED) ? NS_OK : rv; } +NS_IMETHODIMP +nsBufferedInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedInputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedInputStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedInputStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsBufferedInputStream::Fill() { @@ -261,14 +291,19 @@ nsBufferedOutputStream::Init(nsIOutputStream* stream, PRUint32 bufferSize) NS_IMETHODIMP nsBufferedOutputStream::Close() { - nsresult rv1, rv2; + nsresult rv1, rv2 = NS_OK, rv3; rv1 = Flush(); // If we fail to Flush all the data, then we close anyway and drop the // remaining data in the buffer. We do this because it's what Unix does // for fclose and close. However, we report the error from Flush anyway. - rv2 = nsBufferedStream::Close(); + if (mStream) { + rv2 = Sink()->Close(); + NS_RELEASE(mStream); + } + rv3 = nsBufferedStream::Close(); if (NS_FAILED(rv1)) return rv1; - return rv2; + if (NS_FAILED(rv2)) return rv2; + return rv3; } NS_IMETHODIMP @@ -314,5 +349,47 @@ nsBufferedOutputStream::Flush(void) mCursor = rem; return NS_ERROR_FAILURE; // didn't flush all } + +NS_IMETHODIMP +nsBufferedOutputStream::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedOutputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedOutputStream::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedOutputStream::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBufferedOutputStream::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.h b/mozilla/netwerk/base/src/nsBufferedStreams.h index 3cc8ff4e402..de8057b8938 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.h +++ b/mozilla/netwerk/base/src/nsBufferedStreams.h @@ -30,19 +30,19 @@ //////////////////////////////////////////////////////////////////////////////// -class nsBufferedStream : public nsIBaseStream, - public nsISeekableStream +class nsBufferedStream : public nsISeekableStream { public: NS_DECL_ISUPPORTS - NS_DECL_NSIBASESTREAM NS_DECL_NSISEEKABLESTREAM nsBufferedStream(); virtual ~nsBufferedStream(); + nsresult Close(); + protected: - nsresult Init(nsIBaseStream* stream, PRUint32 bufferSize); + nsresult Init(nsISupports* stream, PRUint32 bufferSize); NS_IMETHOD Fill() = 0; NS_IMETHOD Flush() = 0; @@ -58,7 +58,7 @@ protected: // or the end of the buffer for output streams, and is relative to // mBufferStartOffset: PRUint32 mFillPoint; - nsIBaseStream* mStream; // cast to appropriate subclass + nsISupports* mStream; // cast to appropriate subclass }; //////////////////////////////////////////////////////////////////////////////// @@ -68,7 +68,6 @@ class nsBufferedInputStream : public nsBufferedStream, { public: NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIBASESTREAM NS_DECL_NSIINPUTSTREAM NS_DECL_NSIBUFFEREDINPUTSTREAM @@ -94,7 +93,6 @@ class nsBufferedOutputStream : public nsBufferedStream, { public: NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIBASESTREAM NS_DECL_NSIOUTPUTSTREAM NS_DECL_NSIBUFFEREDOUTPUTSTREAM diff --git a/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp b/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp index a328ae8e9b9..3ecd25b4009 100644 --- a/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp +++ b/mozilla/netwerk/base/src/nsDirectoryIndexStream.cpp @@ -111,9 +111,7 @@ nsDirectoryIndexStream::Create(nsIFile* aDir, nsIInputStream** aResult) return NS_OK; } -NS_IMPL_ISUPPORTS2(nsDirectoryIndexStream, - nsIInputStream, - nsIBaseStream) +NS_IMPL_ISUPPORTS1(nsDirectoryIndexStream, nsIInputStream) NS_IMETHODIMP nsDirectoryIndexStream::Close() @@ -270,3 +268,31 @@ nsDirectoryIndexStream::Read(char* aBuf, PRUint32 aCount, PRUint32* aReadCount) *aReadCount = nread; return NS_OK; } + +NS_IMETHODIMP +nsDirectoryIndexStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsDirectoryIndexStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsDirectoryIndexStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsDirectoryIndexStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/netwerk/base/src/nsDirectoryIndexStream.h b/mozilla/netwerk/base/src/nsDirectoryIndexStream.h index e9eee1e82cd..53f2a00ad2c 100644 --- a/mozilla/netwerk/base/src/nsDirectoryIndexStream.h +++ b/mozilla/netwerk/base/src/nsDirectoryIndexStream.h @@ -48,9 +48,6 @@ public: // nsISupportsInterface NS_DECL_ISUPPORTS - // nsIBaseStream interface - NS_DECL_NSIBASESTREAM - // nsIInputStream interface NS_DECL_NSIINPUTSTREAM }; diff --git a/mozilla/netwerk/base/src/nsFileStreams.cpp b/mozilla/netwerk/base/src/nsFileStreams.cpp index 6cd4f8016b3..b1ba8e953c5 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.cpp +++ b/mozilla/netwerk/base/src/nsFileStreams.cpp @@ -275,11 +275,9 @@ nsFileStream::~nsFileStream() Close(); } -NS_IMPL_THREADSAFE_ISUPPORTS2(nsFileStream, - nsIBaseStream, - nsISeekableStream); +NS_IMPL_THREADSAFE_ISUPPORTS1(nsFileStream, nsISeekableStream); -NS_IMETHODIMP +nsresult nsFileStream::Close() { if (mFD) { @@ -388,6 +386,34 @@ nsFileInputStream::Read(char * buf, PRUint32 count, PRUint32 *result) return NS_OK; } +NS_IMETHODIMP +nsFileInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileInputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileInputStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileInputStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + //////////////////////////////////////////////////////////////////////////////// // nsFileOutputStream @@ -458,5 +484,47 @@ nsFileOutputStream::Flush(void) } return NS_OK; } + +NS_IMETHODIMP +nsFileOutputStream::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileOutputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileOutputStream::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileOutputStream::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsFileOutputStream::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsFileStreams.h b/mozilla/netwerk/base/src/nsFileStreams.h index e4b1c01f5d2..2fe6a9dd058 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.h +++ b/mozilla/netwerk/base/src/nsFileStreams.h @@ -58,17 +58,17 @@ protected: //////////////////////////////////////////////////////////////////////////////// -class nsFileStream : public nsIBaseStream, - public nsISeekableStream +class nsFileStream : public nsISeekableStream { public: NS_DECL_ISUPPORTS - NS_DECL_NSIBASESTREAM NS_DECL_NSISEEKABLESTREAM nsFileStream(); virtual ~nsFileStream(); + nsresult Close(); + protected: PRFileDesc* mFD; }; @@ -80,7 +80,6 @@ class nsFileInputStream : public nsFileStream, { public: NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIBASESTREAM NS_DECL_NSIINPUTSTREAM NS_DECL_NSIFILEINPUTSTREAM @@ -98,7 +97,6 @@ class nsFileOutputStream : public nsFileStream, { public: NS_DECL_ISUPPORTS_INHERITED - NS_DECL_NSIBASESTREAM NS_DECL_NSIOUTPUTSTREAM NS_DECL_NSIFILEOUTPUTSTREAM diff --git a/mozilla/netwerk/base/src/nsFileTransport.cpp b/mozilla/netwerk/base/src/nsFileTransport.cpp index 0e3fc7a396a..d66861f6d8e 100644 --- a/mozilla/netwerk/base/src/nsFileTransport.cpp +++ b/mozilla/netwerk/base/src/nsFileTransport.cpp @@ -132,8 +132,8 @@ nsFileTransport::~nsFileTransport() DoClose(); } NS_ASSERTION(mSource == nsnull, "transport not closed"); - NS_ASSERTION(mBufferInputStream == nsnull, "transport not closed"); - NS_ASSERTION(mBufferOutputStream == nsnull, "transport not closed"); + NS_ASSERTION(mInputStream == nsnull, "transport not closed"); + NS_ASSERTION(mOutputStream == nsnull, "transport not closed"); NS_ASSERTION(mSink == nsnull, "transport not closed"); NS_ASSERTION(mBuffer == nsnull, "transport not closed"); if (mMonitor) @@ -145,11 +145,12 @@ nsFileTransport::~nsFileTransport() } -NS_IMPL_THREADSAFE_ISUPPORTS4(nsFileTransport, +NS_IMPL_THREADSAFE_ISUPPORTS5(nsFileTransport, nsIChannel, nsIRequest, nsIRunnable, - nsIPipeObserver); + nsIInputStreamObserver, + nsIOutputStreamObserver); NS_METHOD nsFileTransport::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) @@ -284,15 +285,15 @@ nsFileTransport::AsyncRead(nsIStreamListener *listener, nsISupports *ctxt) listener, nsnull); if (NS_FAILED(rv)) return rv; - rv = NS_NewPipe(getter_AddRefs(mBufferInputStream), - getter_AddRefs(mBufferOutputStream), - this, // nsIPipeObserver - mBufferSegmentSize, mBufferMaxSize); + rv = NS_NewPipe(getter_AddRefs(mInputStream), + getter_AddRefs(mOutputStream), + mBufferSegmentSize, mBufferMaxSize, + PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) return rv; - rv = mBufferInputStream->SetNonBlocking(PR_TRUE); + rv = mInputStream->SetObserver(this); if (NS_FAILED(rv)) return rv; - rv = mBufferOutputStream->SetNonBlocking(PR_TRUE); + rv = mOutputStream->SetObserver(this); if (NS_FAILED(rv)) return rv; NS_ASSERTION(mContext == nsnull, "context not released"); @@ -363,7 +364,8 @@ nsFileTransport::Run(void) } static NS_METHOD -nsWriteToFile(void* closure, +nsWriteToFile(nsIInputStream* in, + void* closure, const char* fromRawSegment, PRUint32 toOffset, PRUint32 count, @@ -435,7 +437,7 @@ nsFileTransport::Process(void) case READING: { PRUint32 writeAmt; // and feed the buffer to the application via the buffer stream: - mStatus = mBufferOutputStream->WriteFrom(mSource, mTransferAmount, &writeAmt); + mStatus = mOutputStream->WriteFrom(mSource, mTransferAmount, &writeAmt); PR_LOG(gFileTransportLog, PR_LOG_DEBUG, ("nsFileTransport: READING [this=%x %s] amt=%d status=%x", this, mStreamName.GetBuffer(), writeAmt, mStatus)); @@ -460,7 +462,7 @@ nsFileTransport::Process(void) mOffset += writeAmt; if (mListener) { mStatus = mListener->OnDataAvailable(this, mContext, - mBufferInputStream, + mInputStream, offset, writeAmt); if (NS_FAILED(mStatus)) { PR_LOG(gFileTransportLog, PR_LOG_DEBUG, @@ -505,9 +507,9 @@ nsFileTransport::Process(void) // of the data in the stream/file. mStatus = NS_BASE_STREAM_CLOSED; } - mBufferOutputStream->Flush(); - mBufferOutputStream = null_nsCOMPtr(); - mBufferInputStream = null_nsCOMPtr(); + mOutputStream->Flush(); + mOutputStream = null_nsCOMPtr(); + mInputStream = null_nsCOMPtr(); mSource = null_nsCOMPtr(); @@ -575,7 +577,7 @@ nsFileTransport::Process(void) mOffset = 0; } - mBufferInputStream = do_QueryInterface(mSource, &mStatus); + mInputStream = do_QueryInterface(mSource, &mStatus); if (NS_FAILED(mStatus)) { // if the given input stream isn't a buffered input // stream, then we need to have our own buffer to do the @@ -599,9 +601,9 @@ nsFileTransport::Process(void) if (mTransferAmount >= 0) transferAmt = PR_MIN(mBufferSegmentSize, (PRUint32)mTransferAmount); PRUint32 writeAmt; - if (mBufferInputStream) { - mStatus = mBufferInputStream->ReadSegments(nsWriteToFile, mSink, - transferAmt, &writeAmt); + if (mInputStream) { + mStatus = mInputStream->ReadSegments(nsWriteToFile, mSink, + transferAmt, &writeAmt); } else { PRUint32 readAmt; @@ -660,8 +662,8 @@ nsFileTransport::Process(void) mSink->Flush(); mSink = null_nsCOMPtr(); } - if (mBufferInputStream) { - mBufferInputStream = null_nsCOMPtr(); + if (mInputStream) { + mInputStream = null_nsCOMPtr(); } else if (mBuffer) { delete mBuffer; @@ -721,29 +723,29 @@ nsFileTransport::DoClose(void) } //////////////////////////////////////////////////////////////////////////////// -// nsIPipeObserver methods: +// nsIInputStreamObserver/nsIOutputStreamObserver methods: //////////////////////////////////////////////////////////////////////////////// NS_IMETHODIMP -nsFileTransport::OnFull(nsIPipe* pipe) +nsFileTransport::OnFull(nsIOutputStream* out) { return Suspend(); } NS_IMETHODIMP -nsFileTransport::OnWrite(nsIPipe* pipe, PRUint32 aCount) +nsFileTransport::OnWrite(nsIOutputStream* out, PRUint32 aCount) { return NS_OK; } NS_IMETHODIMP -nsFileTransport::OnEmpty(nsIPipe* pipe) +nsFileTransport::OnEmpty(nsIInputStream* in) { return Resume(); } NS_IMETHODIMP -nsFileTransport::OnClose(nsIPipe* pipe) +nsFileTransport::OnClose(nsIInputStream* in) { return NS_OK; } diff --git a/mozilla/netwerk/base/src/nsFileTransport.h b/mozilla/netwerk/base/src/nsFileTransport.h index 7ebe2d59879..d159ee4ca4f 100644 --- a/mozilla/netwerk/base/src/nsFileTransport.h +++ b/mozilla/netwerk/base/src/nsFileTransport.h @@ -33,8 +33,8 @@ #include "nsCOMPtr.h" #include "nsIStreamListener.h" #include "nsIProgressEventSink.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsIStreamIO.h" #include "nsIInterfaceRequestor.h" #include "nsIFile.h" @@ -45,13 +45,15 @@ class nsIInterfaceRequestor; class nsFileTransport : public nsIChannel, public nsIRunnable, - public nsIPipeObserver + public nsIInputStreamObserver, + public nsIOutputStreamObserver { public: NS_DECL_ISUPPORTS NS_DECL_NSIREQUEST NS_DECL_NSICHANNEL - NS_DECL_NSIPIPEOBSERVER + NS_DECL_NSIINPUTSTREAMOBSERVER + NS_DECL_NSIOUTPUTSTREAMOBSERVER NS_DECL_NSIRUNNABLE nsFileTransport(); @@ -121,8 +123,8 @@ protected: // reading state varialbles: nsCOMPtr mListener; nsCOMPtr mSource; - nsCOMPtr mBufferInputStream; - nsCOMPtr mBufferOutputStream; + nsCOMPtr mInputStream; + nsCOMPtr mOutputStream; // writing state variables: nsCOMPtr mObserver; diff --git a/mozilla/netwerk/base/src/nsIOService.cpp b/mozilla/netwerk/base/src/nsIOService.cpp index 4e2fca7b59d..0e9c1700597 100644 --- a/mozilla/netwerk/base/src/nsIOService.cpp +++ b/mozilla/netwerk/base/src/nsIOService.cpp @@ -344,6 +344,41 @@ nsIOService::SetOffline(PRBool offline) return NS_OK; } + +NS_IMETHODIMP +nsIOService::ConsumeInput(nsIChannel* channel, nsISupports* context, + nsIStreamListener* consumer) +{ + nsresult rv; + nsCOMPtr in; + rv = channel->OpenInputStream(getter_AddRefs(in)); + if (NS_FAILED(rv)) return rv; + + rv = consumer->OnStartRequest(channel, context); + if (NS_FAILED(rv)) return rv; + + PRUint32 sourceOffset = 0; + while (1) { + char buf[1024]; + PRUint32 readCount; + rv = in->Read(buf, sizeof(buf), &readCount); + if (NS_FAILED(rv)) + break; + + if (readCount == 0) // eof + break; + + rv = consumer->OnDataAvailable(channel, context, 0, sourceOffset, readCount); + sourceOffset += readCount; + if (NS_FAILED(rv)) + break; + } + rv = consumer->OnStopRequest(channel, context, rv, nsnull); + if (NS_FAILED(rv)) return rv; + + return rv; +} + //////////////////////////////////////////////////////////////////////////////// // URL parsing utilities diff --git a/mozilla/netwerk/base/src/nsSocketTransport.cpp b/mozilla/netwerk/base/src/nsSocketTransport.cpp index c4a881a9759..28efcd50823 100644 --- a/mozilla/netwerk/base/src/nsSocketTransport.cpp +++ b/mozilla/netwerk/base/src/nsSocketTransport.cpp @@ -1000,7 +1000,8 @@ typedef struct { static NS_METHOD -nsReadFromSocket(void* closure, +nsReadFromSocket(nsIOutputStream* out, + void* closure, char* toRawSegment, PRUint32 offset, PRUint32 count, @@ -1053,7 +1054,8 @@ nsReadFromSocket(void* closure, } static NS_METHOD -nsWriteToSocket(void* closure, +nsWriteToSocket(nsIInputStream* in, + void* closure, const char* fromRawSegment, PRUint32 toOffset, PRUint32 count, @@ -1228,7 +1230,7 @@ nsresult nsSocketTransport::doWrite(PRInt16 aSelectFlags) { totalBytesWritten = 0; if (mWritePipeIn) { - // Writing from a nsIBufferInputStream... + // Writing from a nsIInputStream... rv = doWriteFromBuffer(&totalBytesWritten); } else { @@ -1361,7 +1363,7 @@ nsresult nsSocketTransport::doWriteFromStream(PRUint32 *aCount) *aCount = 0; if (NS_SUCCEEDED(rv)) { // Try to send the data to the network. - rv = nsWriteToSocket((void*)mSocketFD, mWriteBuffer, mWriteBufferIndex, + rv = nsWriteToSocket(nsnull, (void*)mSocketFD, mWriteBuffer, mWriteBufferIndex, mWriteBufferLength, aCount); // Update the buffer index and length with the actual amount of data // that was sent... @@ -1417,11 +1419,12 @@ nsresult nsSocketTransport::CloseConnection (PRBool bNow) // -------------------------------------------------------------------------- // -NS_IMPL_THREADSAFE_ISUPPORTS5(nsSocketTransport, +NS_IMPL_THREADSAFE_ISUPPORTS6(nsSocketTransport, nsIChannel, nsIRequest, nsIDNSListener, - nsIPipeObserver, + nsIInputStreamObserver, + nsIOutputStreamObserver, nsISocketTransport); // @@ -1625,7 +1628,7 @@ nsSocketTransport::Resume(void) // // -------------------------------------------------------------------------- -// nsIPipeObserver implementation... +// nsIInputStreamObserver/nsIOutputStreamObserver implementation... // -------------------------------------------------------------------------- // // The pipe observer is used by the following methods: @@ -1634,20 +1637,18 @@ nsSocketTransport::Resume(void) // OpenOutputStream(...). // NS_IMETHODIMP -nsSocketTransport::OnFull(nsIPipe* aPipe) +nsSocketTransport::OnFull(nsIOutputStream* out) { PR_LOG(gSocketLog, PR_LOG_DEBUG, - ("nsSocketTransport::OnFull() [%s:%d %x] nsIPipe=%x.\n", - mHostName, mPort, this, aPipe)); + ("nsSocketTransport::OnFull() [%s:%d %x] nsIOutputStream=%x.\n", + mHostName, mPort, this, out)); // // The socket transport has filled up the pipe. Remove the // transport from the select list until the consumer can // make room... // - nsCOMPtr in; - nsresult rv = aPipe->GetInputStream(getter_AddRefs(in)); - if (NS_SUCCEEDED(rv) && in == mReadPipeIn) + if (out == mReadPipeOut) { // Enter the socket transport lock... nsAutoMonitor mon(mMonitor); @@ -1662,27 +1663,25 @@ nsSocketTransport::OnFull(nsIPipe* aPipe) // Else, since we might get an OnFull without an intervening OnWrite // try the OnWrite case to see if we need to resume the blocking write operation: - return OnWrite(aPipe, 0); + return OnWrite(out, 0); } NS_IMETHODIMP -nsSocketTransport::OnWrite(nsIPipe* aPipe, PRUint32 aCount) +nsSocketTransport::OnWrite(nsIOutputStream* out, PRUint32 aCount) { nsresult rv = NS_OK; PR_LOG(gSocketLog, PR_LOG_DEBUG, - ("nsSocketTransport::OnWrite() [%s:%d %x]. nsIPipe=%x Count=%d\n", - mHostName, mPort, this, aPipe, aCount)); + ("nsSocketTransport::OnWrite() [%s:%d %x]. nsIOutputStream=%x Count=%d\n", + mHostName, mPort, this, out, aCount)); // // The consumer has written some data into the pipe... If the transport // was waiting to write some data to the network, then add it to the // select list... // - nsCOMPtr in; - rv = aPipe->GetInputStream(getter_AddRefs(in)); - if (NS_SUCCEEDED(rv) && in == mWritePipeIn) { + if (out == mWritePipeOut) { // Enter the socket transport lock... nsAutoMonitor mon(mMonitor); @@ -1702,21 +1701,19 @@ nsSocketTransport::OnWrite(nsIPipe* aPipe, PRUint32 aCount) NS_IMETHODIMP -nsSocketTransport::OnEmpty(nsIPipe* aPipe) +nsSocketTransport::OnEmpty(nsIInputStream* in) { nsresult rv = NS_OK; PR_LOG(gSocketLog, PR_LOG_DEBUG, - ("nsSocketTransport::OnEmpty() [%s:%d %x] nsIPipe=%x.\n", - mHostName, mPort, this, aPipe)); + ("nsSocketTransport::OnEmpty() [%s:%d %x] nsIInputStream=%x.\n", + mHostName, mPort, this, in)); // // The consumer has emptied the pipe... If the transport was waiting // for room in the pipe, then put it back on the select list... // - nsCOMPtr in; - rv = aPipe->GetInputStream(getter_AddRefs(in)); - if (NS_SUCCEEDED(rv) && in == mReadPipeIn) { + if (in == mReadPipeIn) { // Enter the socket transport lock... nsAutoMonitor mon(mMonitor); @@ -1732,7 +1729,7 @@ nsSocketTransport::OnEmpty(nsIPipe* aPipe) } NS_IMETHODIMP -nsSocketTransport::OnClose(nsIPipe* aPipe) +nsSocketTransport::OnClose(nsIInputStream* inStr) { return NS_OK; } @@ -1896,15 +1893,14 @@ nsSocketTransport::AsyncRead(nsIStreamListener* aListener, { // XXXbe calling out of module with a lock held... rv = NS_NewPipe(getter_AddRefs(mReadPipeIn), - getter_AddRefs(mReadPipeOut), - this, // nsIPipeObserver - mBufferSegmentSize, mBufferMaxSize); + getter_AddRefs(mReadPipeOut), + mBufferSegmentSize, mBufferMaxSize, + PR_TRUE, PR_TRUE); + if (NS_SUCCEEDED(rv)) + rv = mReadPipeIn->SetObserver(this); if (NS_SUCCEEDED(rv)) - rv = mReadPipeIn->SetNonBlocking(PR_TRUE); - - if (NS_SUCCEEDED(rv)) - rv = mReadPipeOut->SetNonBlocking(PR_TRUE); + rv = mReadPipeOut->SetObserver(this); } // Create a marshalling stream listener to receive notifications... @@ -1958,7 +1954,7 @@ nsSocketTransport::AsyncWrite(nsIInputStream* aFromStream, mWritePipeIn = do_QueryInterface(aFromStream, &rv); if (NS_FAILED(rv)) { - // If the input stream does not support nsIBufferInputStream, then + // If the input stream does not support nsIInputStream, then // an intermediate buffer is necessary to move the data from the // stream to the network... mWriteFromStream = aFromStream; @@ -2034,12 +2030,17 @@ nsSocketTransport::OpenInputStream(nsIInputStream* *result) // XXXbe calling out of module with a lock held... rv = NS_NewPipe(getter_AddRefs(mReadPipeIn), getter_AddRefs(mReadPipeOut), - this, // nsIPipeObserver mBufferSegmentSize, mBufferMaxSize); if (NS_SUCCEEDED(rv)) { - rv = mReadPipeOut->SetNonBlocking(PR_TRUE); - *result = mReadPipeIn; - NS_IF_ADDREF(*result); + if (NS_SUCCEEDED(rv)) + rv = mReadPipeIn->SetObserver(this); + if (NS_SUCCEEDED(rv)) + rv = mReadPipeOut->SetObserver(this); + if (NS_SUCCEEDED(rv)) { + rv = mReadPipeOut->SetNonBlocking(PR_TRUE); + *result = mReadPipeIn; + NS_IF_ADDREF(*result); + } } } @@ -2088,16 +2089,18 @@ nsSocketTransport::OpenOutputStream(nsIOutputStream* *result) // is then written to the underlying socket when nsSocketTransport::doWrite() // is called. - nsCOMPtr out; - nsCOMPtr in; + nsCOMPtr out; + nsCOMPtr in; // XXXbe calling out of module with a lock held... rv = NS_NewPipe(getter_AddRefs(in), getter_AddRefs(out), - this, // nsIPipeObserver - mBufferSegmentSize, mBufferMaxSize); - if (NS_SUCCEEDED(rv)) { - rv = in->SetNonBlocking(PR_TRUE); - } - + mBufferSegmentSize, mBufferMaxSize, + PR_TRUE, PR_FALSE); + if (NS_SUCCEEDED(rv)) + rv = in->SetObserver(this); + + if (NS_SUCCEEDED(rv)) + rv = out->SetObserver(this); + if (NS_SUCCEEDED(rv)) { mWritePipeIn = in; *result = out; diff --git a/mozilla/netwerk/base/src/nsSocketTransport.h b/mozilla/netwerk/base/src/nsSocketTransport.h index 4fcc27bfd7d..9eeff7e559f 100644 --- a/mozilla/netwerk/base/src/nsSocketTransport.h +++ b/mozilla/netwerk/base/src/nsSocketTransport.h @@ -31,8 +31,8 @@ #include "nsISocketTransport.h" #include "nsIChannel.h" #include "nsIInputStream.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsIEventQueueService.h" #include "nsIStreamListener.h" #include "nsIDNSListener.h" @@ -117,16 +117,18 @@ class nsSocketTransportService; class nsIInterfaceRequestor; class nsSocketTransport : public nsISocketTransport, - public nsIChannel, - public nsIDNSListener, - public nsIPipeObserver + public nsIChannel, + public nsIDNSListener, + public nsIInputStreamObserver, + public nsIOutputStreamObserver { public: NS_DECL_ISUPPORTS NS_DECL_NSISOCKETTRANSPORT NS_DECL_NSIREQUEST NS_DECL_NSICHANNEL - NS_DECL_NSIPIPEOBSERVER + NS_DECL_NSIINPUTSTREAMOBSERVER + NS_DECL_NSIOUTPUTSTREAMOBSERVER NS_DECL_NSIDNSLISTENER // nsSocketTransport methods: @@ -225,8 +227,8 @@ protected: PRBool mProxyTransparent; nsCOMPtr mReadContext; nsCOMPtr mReadListener; - nsCOMPtr mReadPipeIn; - nsCOMPtr mReadPipeOut; + nsCOMPtr mReadPipeIn; + nsCOMPtr mReadPipeOut; PRUint32 mReadWriteState; PRInt16 mSelectFlags; nsSocketTransportService* mService; @@ -253,8 +255,8 @@ protected: PRUint32 mWriteBufferLength; nsCOMPtr mWriteObserver; - nsCOMPtr mWritePipeIn; - nsCOMPtr mWritePipeOut; + nsCOMPtr mWritePipeIn; + nsCOMPtr mWritePipeOut; PRUint32 mBufferSegmentSize; PRUint32 mBufferMaxSize; diff --git a/mozilla/netwerk/base/src/nsSyncStreamListener.cpp b/mozilla/netwerk/base/src/nsSyncStreamListener.cpp index bb3ccf27548..ee589e19b9f 100644 --- a/mozilla/netwerk/base/src/nsSyncStreamListener.cpp +++ b/mozilla/netwerk/base/src/nsSyncStreamListener.cpp @@ -27,25 +27,26 @@ //////////////////////////////////////////////////////////////////////////////// nsresult -nsSyncStreamListener::Init(nsIInputStream* *inStr, nsIBufferOutputStream* *outStr) +nsSyncStreamListener::Init(nsIInputStream* *inStr, nsIOutputStream* *outStr) { nsresult rv; - nsIBufferInputStream* in; + nsCOMPtr in; - rv = NS_NewPipe(&in, &mOutputStream, nsnull, + rv = NS_NewPipe(getter_AddRefs(in), + getter_AddRefs(mOutputStream), NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE, NS_SYNC_STREAM_LISTENER_BUFFER_SIZE); if (NS_FAILED(rv)) return rv; - *inStr = in; - *outStr = mOutputStream; - NS_ADDREF(mOutputStream); + *inStr = in.get(); + *outStr = mOutputStream.get(); + NS_ADDREF(*inStr); + NS_ADDREF(*outStr); return NS_OK; } nsSyncStreamListener::~nsSyncStreamListener() { - NS_IF_RELEASE(mOutputStream); } NS_IMPL_THREADSAFE_ISUPPORTS3(nsSyncStreamListener, diff --git a/mozilla/netwerk/base/src/nsSyncStreamListener.h b/mozilla/netwerk/base/src/nsSyncStreamListener.h index fe4a8596a22..fd11c181811 100644 --- a/mozilla/netwerk/base/src/nsSyncStreamListener.h +++ b/mozilla/netwerk/base/src/nsSyncStreamListener.h @@ -20,8 +20,9 @@ #define nsSyncStreamListener_h__ #include "nsIStreamListener.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" +#include "nsCOMPtr.h" class nsSyncStreamListener : public nsISyncStreamListener { @@ -41,10 +42,10 @@ public: static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult); - nsIBufferOutputStream* GetOutputStream() { return mOutputStream; } + nsIOutputStream* GetOutputStream() { return mOutputStream; } protected: - nsIBufferOutputStream* mOutputStream; + nsCOMPtr mOutputStream; }; #define NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE (4 * 1024) diff --git a/mozilla/netwerk/cache/filecache/nsDiskCacheRecordChannel.cpp b/mozilla/netwerk/cache/filecache/nsDiskCacheRecordChannel.cpp index 9f7392a2b1f..1bad8607f5a 100644 --- a/mozilla/netwerk/cache/filecache/nsDiskCacheRecordChannel.cpp +++ b/mozilla/netwerk/cache/filecache/nsDiskCacheRecordChannel.cpp @@ -54,7 +54,6 @@ class WriteStreamWrapper : public nsIOutputStream Create(nsDiskCacheRecordChannel* aChannel, nsIOutputStream *aBaseStream, nsIOutputStream* *aWrapper); NS_DECL_ISUPPORTS - NS_DECL_NSIBASESTREAM NS_DECL_NSIOUTPUTSTREAM private: @@ -96,6 +95,48 @@ WriteStreamWrapper::Write(const char *aBuffer, PRUint32 aCount, PRUint32 *aNumWr mChannel->NotifyStorageInUse(*aNumWritten); return rv; } + +NS_IMETHODIMP +WriteStreamWrapper::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +WriteStreamWrapper::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +WriteStreamWrapper::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +WriteStreamWrapper::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +WriteStreamWrapper::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +WriteStreamWrapper::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} NS_IMETHODIMP WriteStreamWrapper::Flush() diff --git a/mozilla/netwerk/cache/memcache/nsMemCacheChannel.cpp b/mozilla/netwerk/cache/memcache/nsMemCacheChannel.cpp index 709616c46fd..982191249f1 100644 --- a/mozilla/netwerk/cache/memcache/nsMemCacheChannel.cpp +++ b/mozilla/netwerk/cache/memcache/nsMemCacheChannel.cpp @@ -176,6 +176,26 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + NS_IMETHOD Close() { nsresult rv = mSyncStream->Close(); @@ -278,7 +298,7 @@ private: PRBool mSuspended; // Suspend() has been called }; -NS_IMPL_ISUPPORTS4(AsyncReadStreamAdaptor, nsIInputStream, nsIBaseStream, +NS_IMPL_ISUPPORTS3(AsyncReadStreamAdaptor, nsIInputStream, nsIStreamListener, nsIStreamObserver) // The only purpose of this output stream wrapper is to adjust the cache's @@ -306,6 +326,12 @@ public: NS_DECL_ISUPPORTS + NS_IMETHOD + Close() { return mBaseStream->Close(); } + + NS_IMETHOD + Flush() { return mBaseStream->Flush(); } + NS_IMETHOD Write(const char *aBuffer, PRUint32 aCount, PRUint32 *aNumWritten) { *aNumWritten = 0; @@ -315,10 +341,40 @@ public: } NS_IMETHOD - Flush() { return mBaseStream->Flush(); } + WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; + } NS_IMETHOD - Close() { return mBaseStream->Close(); } + WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetNonBlocking(PRBool aNonBlocking) { + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetObserver(nsIOutputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetObserver(nsIOutputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } private: nsCOMPtr mBaseStream; diff --git a/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp b/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp index 7a0dce53d92..d2952b56a12 100644 --- a/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp +++ b/mozilla/netwerk/cache/mgr/nsCacheEntryChannel.cpp @@ -90,6 +90,42 @@ public: return rv; } + NS_IMETHOD + WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetNonBlocking(PRBool aNonBlocking) { + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetObserver(nsIOutputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetObserver(nsIOutputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + protected: nsCOMPtr mOutputStream; nsCOMPtr mCacheEntry; diff --git a/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp b/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp index 41e18f1386f..7909cf48f6a 100644 --- a/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp +++ b/mozilla/netwerk/cache/mgr/nsCachedNetData.cpp @@ -1215,6 +1215,26 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + private: nsresult write(char* aBuf, PRUint32 aNumBytes) { diff --git a/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp b/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp index 139fddc9666..1412eba1775 100644 --- a/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp +++ b/mozilla/netwerk/protocol/data/src/nsDataChannel.cpp @@ -30,8 +30,8 @@ #include "plbase64.h" #include "nsIInterfaceRequestor.h" #include "nsIPipe.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsXPIDLString.h" static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); @@ -73,7 +73,8 @@ typedef struct _writeData { } writeData; static NS_METHOD -nsReadData(void* closure, // the data from +nsReadData(nsIOutputStream* out, + void* closure, // the data from char* toRawSegment, // where to put the data PRUint32 offset, // where to start PRUint32 count, // how much data is there @@ -157,8 +158,8 @@ nsDataChannel::ParseData() { cleanup = PR_TRUE; } - nsCOMPtr bufInStream; - nsCOMPtr bufOutStream; + nsCOMPtr bufInStream; + nsCOMPtr bufOutStream; rv = NS_NewPipe(getter_AddRefs(bufInStream), getter_AddRefs(bufOutStream)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp index b44ae5cf8d8..3f26fac5bf2 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFTPChannel.cpp @@ -257,7 +257,7 @@ nsFTPChannel::OpenInputStream(nsIInputStream **result) // and the FTP thread get's the output stream end. // The FTP thread will write to the output stream end // when data become available to it. - nsCOMPtr bufOutStream; // we don't use this piece + nsCOMPtr bufOutStream; // we don't use this piece nsCOMPtr listener; rv = NS_NewSyncStreamListener(result, getter_AddRefs(bufOutStream), getter_AddRefs(listener)); diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h index ec1c52b51c5..8b87c57a7fa 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h @@ -37,8 +37,8 @@ #include "nsIProtocolHandler.h" #include "nsCOMPtr.h" #include "nsXPIDLString.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsAutoLock.h" #include "nsIEventQueueService.h" #include "nsIPrompt.h" diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPChannel.h b/mozilla/netwerk/protocol/http/src/nsHTTPChannel.h index 553b50082de..977ab7c5e25 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPChannel.h +++ b/mozilla/netwerk/protocol/http/src/nsHTTPChannel.h @@ -34,7 +34,7 @@ #include "nsILoadGroup.h" #include "nsCOMPtr.h" #include "nsString.h" -#include "nsIBufferOutputStream.h" +#include "nsIOutputStream.h" #include "nsHTTPResponseListener.h" #include "nsIStreamListener.h" #include "nsIStreamObserver.h" @@ -153,7 +153,7 @@ protected: nsCOMPtr mCallbacks; nsCOMPtr mResponseDataListener; - nsCOMPtr mBufOutputStream; + nsCOMPtr mBufOutputStream; PRUint32 mLoadAttributes; diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp index fa3c7be46af..acd7df08243 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.cpp @@ -84,6 +84,7 @@ nsHTTPEncodeStream::Available(PRUint32 *result) { // XXX Ugh! This requires buffering up the translation so that you can // count it, because to walk it consumes the input. + NS_NOTREACHED("Available"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -160,6 +161,34 @@ nsHTTPEncodeStream::Read(char* outBuf, PRUint32 outBufCnt, PRUint32 *result) return NS_OK; } +NS_IMETHODIMP +nsHTTPEncodeStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTTPEncodeStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTTPEncodeStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsHTTPEncodeStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + //////////////////////////////////////////////////////////////////////////////// // nsISeekableStream methods: diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h index f877b1643b7..60351b207f2 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h +++ b/mozilla/netwerk/protocol/http/src/nsHTTPEncodeStream.h @@ -33,7 +33,6 @@ class nsHTTPEncodeStream : public nsIInputStream, { public: NS_DECL_ISUPPORTS - NS_DECL_NSIBASESTREAM NS_DECL_NSIINPUTSTREAM NS_DECL_NSISEEKABLESTREAM diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPRequest.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPRequest.cpp index 94008524873..a1ebea27bd7 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPRequest.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPRequest.cpp @@ -28,8 +28,8 @@ #include "nsHTTPEnums.h" #include "nsIPipe.h" #include "nsIStringStream.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsString.h" #include "nsCOMPtr.h" #include "nsIChannel.h" diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.cpp b/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.cpp index 3ddc03454ea..8101271a924 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.cpp +++ b/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.cpp @@ -26,7 +26,7 @@ #include "nsHTTPResponseListener.h" #include "nsIChannel.h" #include "nsISocketTransport.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsHTTPChannel.h" #include "nsHTTPResponse.h" #include "nsCRT.h" @@ -290,7 +290,7 @@ nsHTTPServerListener::OnDataAvailable(nsIChannel* channel, return NS_OK; NS_ASSERTION(i_pStream, "No stream supplied by the transport!") ; - nsCOMPtr bufferInStream = + nsCOMPtr bufferInStream = do_QueryInterface(i_pStream) ; PR_LOG(gHTTPLog, PR_LOG_ALWAYS, @@ -848,32 +848,38 @@ nsresult nsHTTPServerListener::FireSingleOnData(nsIStreamListener *aListener, } static NS_METHOD -nsWriteToString(void* closure, - const char* fromRawSegment, - PRUint32 offset, - PRUint32 count, - PRUint32 *writeCount) +nsWriteLineToString(nsIInputStream* in, + void* closure, + const char* fromRawSegment, + PRUint32 offset, + PRUint32 count, + PRUint32 *writeCount) { - nsString *str =(nsString*) closure; + nsCString* str = (nsCString*)closure; + *writeCount = 0; - str->AppendWithConversion(fromRawSegment, count) ; - *writeCount = count; - - return NS_OK; + const char* buf = fromRawSegment; + while (count-- > 0) { + const char c = *buf++; + (*writeCount)++; + if (c == LF) { + break; + } + } + str->Append(fromRawSegment, *writeCount); + return NS_BASE_STREAM_WOULD_BLOCK; } -nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in, +nsresult nsHTTPServerListener::ParseStatusLine(nsIInputStream* in, PRUint32 aLength, PRUint32 *aBytesRead) { nsresult rv = NS_OK; - - PRBool bFoundString = PR_FALSE; - PRUint32 offsetOfEnd, totalBytesToRead, actualBytesRead; + PRUint32 actualBytesRead; PR_LOG(gHTTPLog, PR_LOG_ALWAYS, -("nsHTTPServerListener::ParseStatusLine [this=%x].\taLength=%d\n", + ("nsHTTPServerListener::ParseStatusLine [this=%x].\taLength=%d\n", this, aLength)) ; *aBytesRead = 0; @@ -883,26 +889,9 @@ nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in, return NS_ERROR_FAILURE; } - // Look for the LF which ends the Status-Line. - // n.b. Search looks at all pending data not just the first aLength bytes - rv = in->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd) ; - if (NS_FAILED(rv)) return rv; - if (bFoundString && offsetOfEnd >= aLength) bFoundString = PR_FALSE; - - if (!bFoundString) { - // - // This is a partial header... Read the entire buffer and wait for - // more data... - // - totalBytesToRead = aLength; - } else { - // Do not forget to include the LF character in the read... - totalBytesToRead = offsetOfEnd+1; - } - - rv = in->ReadSegments(nsWriteToString, -(void*) &mHeaderBuffer, - totalBytesToRead, + rv = in->ReadSegments(nsWriteLineToString, + (void*) &mHeaderBuffer, + aLength, &actualBytesRead) ; if (NS_FAILED(rv)) return rv; @@ -910,8 +899,7 @@ nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in, PRUint32 bL = mHeaderBuffer.Length() ; - if (bL > 0 - && PL_strncmp(mHeaderBuffer, "HTTP/", bL > 5 ? 5 : bL)) + if (bL > 0 && mHeaderBuffer.Find("HTTP/", PR_FALSE, 0, 5) != 0) { // this is simple http response mSimpleResponse = PR_TRUE; @@ -926,10 +914,10 @@ nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in, } // Wait for more data to arrive before processing the header... - if (!bFoundString) return NS_OK; + if (bL > 0 && mHeaderBuffer.CharAt(bL - 1) != LF) return NS_OK; PR_LOG(gHTTPLog, PR_LOG_ALWAYS, -("\tParseStatusLine [this=%x].\tGot Status-Line:%s\n" + ("\tParseStatusLine [this=%x].\tGot Status-Line:%s\n" , this, mHeaderBuffer.GetBuffer()) ) ; // @@ -950,7 +938,7 @@ nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in, // Pretend that the headers have been consumed. // PR_LOG(gHTTPLog, PR_LOG_ALWAYS, -("\tParseStatusLine [this=%x]. HTTP/0.9 Server Response!" + ("\tParseStatusLine [this=%x]. HTTP/0.9 Server Response!" " Hold onto you seats!\n", this)) ; mResponse->SetStatus(200) ; @@ -965,14 +953,12 @@ nsresult nsHTTPServerListener::ParseStatusLine(nsIBufferInputStream* in, return rv; } -nsresult nsHTTPServerListener::ParseHTTPHeader(nsIBufferInputStream* in, +nsresult nsHTTPServerListener::ParseHTTPHeader(nsIInputStream* in, PRUint32 aLength, PRUint32 *aBytesRead) { nsresult rv = NS_OK; - - PRBool bFoundString; - PRUint32 offsetOfEnd, totalBytesToRead, actualBytesRead; + PRUint32 totalBytesToRead = aLength, actualBytesRead; *aBytesRead = 0; @@ -986,73 +972,45 @@ nsresult nsHTTPServerListener::ParseHTTPHeader(nsIBufferInputStream* in, // a CRLF. Header values may be extended over multiple lines by preceeding // each extra line with linear white space... // + PRInt32 newlineOffset = 0; do { + // Append the buffer into the header string... + rv = in->ReadSegments(nsWriteLineToString, + (void*) &mHeaderBuffer, + totalBytesToRead, + &actualBytesRead); + if (NS_FAILED(rv)) return rv; + if (actualBytesRead == 0) + break; + + *aBytesRead += actualBytesRead; + totalBytesToRead -= actualBytesRead; + // // If last character in the header string is a LF, then the header // may be complete... // - if (!mHeaderBuffer.IsEmpty() && mHeaderBuffer.Last() == '\n') { - // This line is either LF or CRLF so the header is complete... - if (mHeaderBuffer.Length() <= 2) { - break; - } - - rv = in->Search(" ", PR_FALSE, &bFoundString, &offsetOfEnd) ; - if (NS_FAILED(rv)) return rv; - if (bFoundString && offsetOfEnd >= aLength) bFoundString = PR_FALSE; - - // Need to wait for more data to see if the header is complete - if (!bFoundString && offsetOfEnd == 0) - return NS_OK; - - if (!bFoundString || offsetOfEnd != 0) { - // then check for tab too - rv = in->Search("\t", PR_FALSE, &bFoundString, &offsetOfEnd) ; - if (NS_FAILED(rv)) return rv; - if (bFoundString && offsetOfEnd >= aLength) bFoundString = PR_FALSE; - - NS_ASSERTION(!(!bFoundString && offsetOfEnd == 0) , - "should have been checked above") ; - if (!bFoundString || offsetOfEnd != 0) { - break; // neither space nor tab, so jump out of the loop - } - } - // else, go around the loop again and accumulate the rest of the header... + newlineOffset = mHeaderBuffer.FindChar(LF, PR_FALSE, newlineOffset); + if (newlineOffset == -1) + return NS_OK; + + // This line is either LF or CRLF so the header is complete... + if (mHeaderBuffer.Length() <= 2) { + break; } - // Look for the next LF in the buffer... - rv = in->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd) ; - if (NS_FAILED(rv)) return rv; - if (bFoundString && offsetOfEnd >= aLength) bFoundString = PR_FALSE; + if ((PRUint32)newlineOffset == mHeaderBuffer.Length()) + return NS_OK; - - if (!bFoundString) { - // - // The buffer contains a partial header. Read the entire buffer - // and wait for more data... - // - totalBytesToRead = aLength; - } else { - // Do not forget to include the LF character in the read... - totalBytesToRead = offsetOfEnd+1; - } - - // Append the buffer into the header string... - rv = in->ReadSegments(nsWriteToString, -(void*) &mHeaderBuffer, - totalBytesToRead, - &actualBytesRead) ; - if (NS_FAILED(rv)) return rv; - - *aBytesRead += actualBytesRead; - - // Partial header - wait for more data to arrive... - if (!bFoundString) return NS_OK; - - } while (PR_TRUE) ; + const char* buf = mHeaderBuffer.GetBuffer(); + const char charAfterNewline = buf[newlineOffset + 1]; + if ((charAfterNewline != ' ') || (charAfterNewline != '\t')) + break; + newlineOffset++; + } while (PR_TRUE); PR_LOG(gHTTPLog, PR_LOG_ALWAYS, -("\tParseHTTPHeader [this=%x].\tGot header string:%s\n", + ("\tParseHTTPHeader [this=%x].\tGot header string:%s\n", this, mHeaderBuffer.GetBuffer()) ) ; // diff --git a/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.h b/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.h index 75f9117b202..81468ab1f03 100644 --- a/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.h +++ b/mozilla/netwerk/protocol/http/src/nsHTTPResponseListener.h @@ -106,10 +106,10 @@ protected: // nsHTTPResponseListener methods... nsresult FireOnHeadersAvailable(); - nsresult ParseStatusLine(nsIBufferInputStream* in, PRUint32 aLength, + nsresult ParseStatusLine(nsIInputStream* in, PRUint32 aLength, PRUint32 *aBytesRead); - nsresult ParseHTTPHeader(nsIBufferInputStream* in, PRUint32 aLength, + nsresult ParseHTTPHeader(nsIInputStream* in, PRUint32 aLength, PRUint32* aBytesRead); protected: diff --git a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp index 5532ae72c69..9fa5c825152 100644 --- a/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp +++ b/mozilla/netwerk/streamconv/converters/nsUnknownDecoder.cpp @@ -26,8 +26,8 @@ #include "nsIStreamConverterService.h" #include "nsIPipe.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsMimeTypes.h" #include "netCore.h" @@ -314,11 +314,11 @@ nsresult nsUnknownDecoder::FireListenerNotifications(nsIChannel *aChannel, // stream into the sniffer buffer... if (NS_SUCCEEDED(rv)) { PRUint32 len = 0; - nsCOMPtr in; - nsCOMPtr out; + nsCOMPtr in; + nsCOMPtr out; // Create a pipe and fill it with the data from the sniffer buffer. - rv = NS_NewPipe(getter_AddRefs(in), getter_AddRefs(out), nsnull, + rv = NS_NewPipe(getter_AddRefs(in), getter_AddRefs(out), MAX_BUFFER_SIZE, MAX_BUFFER_SIZE); if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp b/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp index 7454cd60569..df604e3a137 100644 --- a/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp +++ b/mozilla/netwerk/streamconv/src/nsStreamConverterService.cpp @@ -41,8 +41,8 @@ #include "nsDeque.h" #include "nsIRegistry.h" #include "nsIEnumerator.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsIStreamConverter.h" #include "nsCOMPtr.h" diff --git a/mozilla/netwerk/test/TestCallbacks.cpp b/mozilla/netwerk/test/TestCallbacks.cpp index e95a93b6cb8..264d6100f7a 100644 --- a/mozilla/netwerk/test/TestCallbacks.cpp +++ b/mozilla/netwerk/test/TestCallbacks.cpp @@ -32,7 +32,6 @@ #include "nsIServiceManager.h" #include "nsIStreamListener.h" #include "nsIInputStream.h" -#include "nsIBufferInputStream.h" #include "nsCRT.h" #include "nsIChannel.h" #include "nsIURL.h" diff --git a/mozilla/netwerk/test/TestFileInput.cpp b/mozilla/netwerk/test/TestFileInput.cpp index 31a18368c90..85a22fcbc47 100644 --- a/mozilla/netwerk/test/TestFileInput.cpp +++ b/mozilla/netwerk/test/TestFileInput.cpp @@ -34,8 +34,8 @@ #include "nsILocalFile.h" #include "nsNetUtil.h" #include "nsIPipe.h" -#include "nsIBufferOutputStream.h" -#include "nsIBufferInputStream.h" +#include "nsIOutputStream.h" +#include "nsIInputStream.h" #include "nsIRunnable.h" #include "nsIThread.h" #include "nsISupportsArray.h" @@ -201,9 +201,9 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) nsresult rv; nsCOMPtr fileStr; - nsIBufferInputStream* bufStr = nsnull; + nsIInputStream* bufStr = nsnull; PRUint32 sourceOffset = 0; - nsCOMPtr out; + nsCOMPtr out; nsCOMPtr file; rv = reader->OnStartRequest(nsnull, nsnull); @@ -215,7 +215,7 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path) rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStr), file); if (NS_FAILED(rv)) goto done; - rv = NS_NewPipe(&bufStr, getter_AddRefs(out), nsnull, + rv = NS_NewPipe(&bufStr, getter_AddRefs(out), NS_FILE_TRANSPORT_BUFFER_SIZE, NS_FILE_TRANSPORT_BUFFER_SIZE); if (NS_FAILED(rv)) goto done; diff --git a/mozilla/netwerk/test/TestProtocols.cpp b/mozilla/netwerk/test/TestProtocols.cpp index 23ac8bb8bb9..875dd87546b 100644 --- a/mozilla/netwerk/test/TestProtocols.cpp +++ b/mozilla/netwerk/test/TestProtocols.cpp @@ -40,7 +40,7 @@ #include "nsIServiceManager.h" #include "nsIStreamListener.h" #include "nsIInputStream.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsCRT.h" #include "nsIChannel.h" #include "nsIURL.h" diff --git a/mozilla/netwerk/test/TestSocketIO.cpp b/mozilla/netwerk/test/TestSocketIO.cpp index f57c99129a7..1ea2ffb6cc7 100644 --- a/mozilla/netwerk/test/TestSocketIO.cpp +++ b/mozilla/netwerk/test/TestSocketIO.cpp @@ -28,8 +28,6 @@ #include #endif -#define NSPIPE2 - #include "nspr.h" #include "nscore.h" #include "nsISocketTransportService.h" @@ -38,13 +36,9 @@ #include "nsIChannel.h" #include "nsIStreamObserver.h" #include "nsIStreamListener.h" -#ifndef NSPIPE2 -#include "nsIBuffer.h" -#else #include "nsIPipe.h" -#include "nsIBufferOutputStream.h" -#endif -#include "nsIBufferInputStream.h" +#include "nsIOutputStream.h" +#include "nsIInputStream.h" #include "nsCRT.h" #include "nsCOMPtr.h" @@ -218,30 +212,15 @@ main(int argc, char* argv[]) if (NS_FAILED(rv)) return rv; // Create a stream for the data being written to the server... - nsIBufferInputStream* stream; + nsIInputStream* stream; PRUint32 bytesWritten; -#ifndef NSPIPE2 - nsCOMPtr buf; - rv = NS_NewBuffer(&buf, 1024, 4096, nsnull); - rv = NS_NewBufferInputStream(&stream, buf); -#else - nsCOMPtr out; - rv = NS_NewPipe(&stream, getter_AddRefs(out), nsnull, - 1024, 4096); -#endif + nsCOMPtr out; + rv = NS_NewPipe(&stream, getter_AddRefs(out), 1024, 4096); if (NS_FAILED(rv)) return rv; char *buffer = PR_smprintf("GET %s HTML/1.0%s%s", fileName, CRLF, CRLF); -#if 0 - stream->Fill(buffer, strlen(buffer), &bytesWritten); -#else -#ifndef NSPIPE2 - buf->Write(buffer, strlen(buffer), &bytesWritten); -#else out->Write(buffer, strlen(buffer), &bytesWritten); -#endif -#endif printf("\n+++ Request is: %s\n", buffer); // Create the socket transport... diff --git a/mozilla/netwerk/test/TestSocketInput.cpp b/mozilla/netwerk/test/TestSocketInput.cpp index 3543a3edd5b..e79e28f9946 100644 --- a/mozilla/netwerk/test/TestSocketInput.cpp +++ b/mozilla/netwerk/test/TestSocketInput.cpp @@ -35,7 +35,7 @@ #include "nsIServiceManager.h" #include "nsIChannel.h" #include "nsIStreamListener.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); diff --git a/mozilla/netwerk/test/TestSocketTransport.cpp b/mozilla/netwerk/test/TestSocketTransport.cpp index 0c559b6e9be..ad7b98b9277 100644 --- a/mozilla/netwerk/test/TestSocketTransport.cpp +++ b/mozilla/netwerk/test/TestSocketTransport.cpp @@ -34,21 +34,15 @@ #include "pprio.h" // PR_Init_Log #endif -#define NSPIPE2 - #include "nsISocketTransportService.h" #include "nsIEventQueueService.h" #include "nsIServiceManager.h" #include "nsIChannel.h" #include "nsIStreamObserver.h" #include "nsIStreamListener.h" -#ifndef NSPIPE2 -#include "nsIBuffer.h" -#else #include "nsIPipe.h" -#endif -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsIRunnable.h" #include "nsIThread.h" #include "nsITimer.h" @@ -166,12 +160,8 @@ public: } protected: -#ifndef NSPIPE2 - nsIBuffer* mBuffer; -#else - nsIBufferOutputStream* mOut; -#endif - nsIBufferInputStream* mStream; + nsIOutputStream* mOut; + nsIInputStream* mStream; nsIInputStream* mInStream; nsIOutputStream* mOutStream; @@ -300,11 +290,7 @@ TestConnection::TestConnection(const char* aHostName, PRInt32 aPort, mBytesRead = 0; mTransport = nsnull; -#ifndef NSPIPE2 - mBuffer = nsnull; -#else mOut = nsnull; -#endif mStream = nsnull; mInStream = nsnull; @@ -326,12 +312,7 @@ TestConnection::TestConnection(const char* aHostName, PRInt32 aPort, if (mIsAsync) { // Create a stream for the data being written to the server... if (NS_SUCCEEDED(rv)) { -#ifndef NSPIPE2 - rv = NS_NewBuffer(&mBuffer, 1024, 4096, nsnull); - rv = NS_NewBufferInputStream(&mStream, mBuffer); -#else - rv = NS_NewPipe(&mStream, &mOut, nsnull, 1024, 4096); -#endif + rv = NS_NewPipe(&mStream, &mOut, 1024, 4096); } } // Synchronous transport... @@ -348,11 +329,7 @@ TestConnection::~TestConnection() NS_IF_RELEASE(mTransport); // Async resources... NS_IF_RELEASE(mStream); -#ifndef NSPIPE2 - NS_IF_RELEASE(mBuffer); -#else NS_IF_RELEASE(mOut); -#endif // Sync resources... NS_IF_RELEASE(mInStream); @@ -448,15 +425,7 @@ nsresult TestConnection::WriteBuffer(void) // Async case... // if (mStream) { -#if 0 - rv = mStream->Fill(buffer, size, &bytesWritten); -#else -#ifndef NSPIPE2 - rv = mBuffer->Write(buffer, size, &bytesWritten); -#else rv = mOut->Write(buffer, size, &bytesWritten); -#endif -#endif // Write the buffer to the server... if (NS_SUCCEEDED(rv)) { diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index af0eb9b63ad..225cfcfffa6 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -41,7 +41,7 @@ #include "nsIStringStream.h" #include "nsIChannel.h" #include "nsIProgressEventSink.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "CRtfDTD.h" #include "CNavDTD.h" #include "COtherDTD.h" diff --git a/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp b/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp index d2c4f832f75..ab1f7417051 100644 --- a/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp +++ b/mozilla/rdf/base/src/nsRDFXMLDataSource.cpp @@ -166,6 +166,26 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + // Implementation void SetBuffer(const char* aBuffer, PRUint32 aSize) { mBuffer = aBuffer; diff --git a/mozilla/rdf/content/src/nsXULDocument.cpp b/mozilla/rdf/content/src/nsXULDocument.cpp index 1b0806874c8..eb75cc1e35a 100644 --- a/mozilla/rdf/content/src/nsXULDocument.cpp +++ b/mozilla/rdf/content/src/nsXULDocument.cpp @@ -280,6 +280,26 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + // Implementation void SetBuffer(const char* aBuffer, PRUint32 aSize) { mBuffer = aBuffer; @@ -343,7 +363,7 @@ public: NS_IMETHOD GetContentType(char * *aContentType) { *aContentType = nsnull; return NS_OK; } NS_IMETHOD SetContentType(const char *aContentType) { return NS_OK; } NS_IMETHOD GetContentLength(PRInt32 *aContentLength) { *aContentLength = 0; return NS_OK; } - NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); return NS_ERROR_NOT_IMPLEMENTED; } + NS_IMETHOD SetContentLength(PRInt32 aContentLength) { NS_NOTREACHED("SetContentLength"); NS_NOTREACHED("NOTREACHED"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD GetTransferOffset(PRUint32 *aTransferOffset) { NS_NOTREACHED("GetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD SetTransferOffset(PRUint32 aTransferOffset) { NS_NOTREACHED("SetTransferOffset"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHOD GetTransferCount(PRInt32 *aTransferCount) { NS_NOTREACHED("GetTransferCount"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -830,6 +850,7 @@ nsXULDocument::GetPrincipal(nsIPrincipal **aPrincipal) NS_IMETHODIMP nsXULDocument::AddPrincipal(nsIPrincipal *aPrincipal) { + NS_NOTREACHED("AddPrincipal"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/rdf/content/src/nsXULKeyListener.cpp b/mozilla/rdf/content/src/nsXULKeyListener.cpp index b6b680c317d..27e32752174 100644 --- a/mozilla/rdf/content/src/nsXULKeyListener.cpp +++ b/mozilla/rdf/content/src/nsXULKeyListener.cpp @@ -362,6 +362,26 @@ public: return NS_OK; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + // Implementation void SetBuffer(const char* aBuffer, PRUint32 aSize) { mBuffer = aBuffer; diff --git a/mozilla/rdf/tests/rdfcat/rdfcat.cpp b/mozilla/rdf/tests/rdfcat/rdfcat.cpp index 0cb28ca4039..20c00547685 100644 --- a/mozilla/rdf/tests/rdfcat/rdfcat.cpp +++ b/mozilla/rdf/tests/rdfcat/rdfcat.cpp @@ -92,6 +92,42 @@ public: return NS_OK; } + NS_IMETHOD + WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) { + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetNonBlocking(PRBool *aNonBlocking) { + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetNonBlocking(PRBool aNonBlocking) { + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + GetObserver(nsIOutputStreamObserver * *aObserver) { + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + + NS_IMETHOD + SetObserver(nsIOutputStreamObserver * aObserver) { + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; + } + NS_IMETHOD Flush(void) { PR_Sync(PR_GetSpecialFD(PR_StandardOutput)); return NS_OK; diff --git a/mozilla/xpcom/build/dlldeps.cpp b/mozilla/xpcom/build/dlldeps.cpp index b16e830344b..2c548bba259 100644 --- a/mozilla/xpcom/build/dlldeps.cpp +++ b/mozilla/xpcom/build/dlldeps.cpp @@ -92,7 +92,7 @@ void XXXNeverCalled() nsSupportsArray(); NS_GetNumberOfAtoms(); nsFileURL(NULL); - NS_NewPipe(NULL, NULL, NULL, 0, 0); + NS_NewPipe(NULL, NULL, 0, 0, PR_FALSE, PR_FALSE, NULL); nsFileSpec s; nsFixedSizeAllocator a; a.Init(0, 0, 0, 0, 0); diff --git a/mozilla/xpcom/ds/nsCRT.h b/mozilla/xpcom/ds/nsCRT.h index 6aaab4196a2..5b01364d156 100644 --- a/mozilla/xpcom/ds/nsCRT.h +++ b/mozilla/xpcom/ds/nsCRT.h @@ -29,8 +29,8 @@ #include "prtypes.h" #include "nsCppSharedAllocator.h" -#define CR '\015' -#define LF '\012' +#define CR '\015' // \r +#define LF '\012' // \n #define VTAB '\013' #define FF '\014' #define TAB '\011' diff --git a/mozilla/xpcom/io/Makefile.in b/mozilla/xpcom/io/Makefile.in index 32d034b86d7..cb7a5943850 100644 --- a/mozilla/xpcom/io/Makefile.in +++ b/mozilla/xpcom/io/Makefile.in @@ -83,11 +83,8 @@ EXPORTS += nsLocalFileUnix.h endif XPIDLSRCS = \ - nsIBaseStream.idl \ nsIBinaryInputStream.idl \ nsIBinaryOutputStream.idl \ - nsIBufferInputStream.idl \ - nsIBufferOutputStream.idl \ nsIFile.idl \ nsIFileSpec.idl \ nsIInputStream.idl \ diff --git a/mozilla/xpcom/io/makefile.win b/mozilla/xpcom/io/makefile.win index 4167eac1922..9c25d01c755 100644 --- a/mozilla/xpcom/io/makefile.win +++ b/mozilla/xpcom/io/makefile.win @@ -47,13 +47,10 @@ XPIDL_MODULE = xpcom_io XPIDLSRCS = \ .\nsIPipe.idl \ - .\nsIBaseStream.idl \ - .\nsIBinaryInputStream.idl \ - .\nsIBinaryOutputStream.idl \ .\nsIInputStream.idl \ .\nsIOutputStream.idl \ - .\nsIBufferInputStream.idl \ - .\nsIBufferOutputStream.idl \ + .\nsIBinaryInputStream.idl \ + .\nsIBinaryOutputStream.idl \ .\nsIScriptableInputStream.idl \ .\nsIStorageStream.idl \ .\nsIFileSpec.idl \ diff --git a/mozilla/xpcom/io/nsBinaryStream.cpp b/mozilla/xpcom/io/nsBinaryStream.cpp index c79147b3e3b..b9d78000a8a 100644 --- a/mozilla/xpcom/io/nsBinaryStream.cpp +++ b/mozilla/xpcom/io/nsBinaryStream.cpp @@ -68,6 +68,48 @@ nsBinaryOutputStream::Write(const char *aBuf, PRUint32 aCount, PRUint32 *aActual return mOutputStream->Write(aBuf, aCount, aActualBytes); } +NS_IMETHODIMP +nsBinaryOutputStream::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryOutputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryOutputStream::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryOutputStream::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryOutputStream::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + nsresult nsBinaryOutputStream::WriteFully(const char *aBuf, PRUint32 aCount) { @@ -156,12 +198,14 @@ nsBinaryOutputStream::WriteStringZ(const char *aString) NS_IMETHODIMP nsBinaryOutputStream::WriteWStringZ(const PRUnichar* aString) { + NS_NOTREACHED("WriteWStringZ"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsBinaryOutputStream::WriteUtf8Z(const PRUnichar* aString) { + NS_NOTREACHED("WriteUtf8Z"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -180,6 +224,7 @@ nsBinaryOutputStream::WriteBytes(const char *aString, PRUint32 aLength) NS_IMETHODIMP nsBinaryOutputStream::WriteString(nsString* aString) { + NS_NOTREACHED("WriteString"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -196,6 +241,34 @@ nsBinaryInputStream::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead) return mInputStream->Read(aBuffer, aCount, aNumRead); } +NS_IMETHODIMP +nsBinaryInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryInputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryInputStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsBinaryInputStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsBinaryInputStream::Close() { return mInputStream->Close(); } @@ -317,12 +390,14 @@ nsBinaryInputStream::ReadStringZ(char* *aString) NS_IMETHODIMP nsBinaryInputStream::ReadWStringZ(PRUnichar* *aString) { + NS_NOTREACHED("ReadWStringZ"); return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP nsBinaryInputStream::ReadUtf8Z(PRUnichar* *aString) { + NS_NOTREACHED("ReadUtf8Z"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -349,6 +424,7 @@ nsBinaryInputStream::ReadBytes(char* *aString, PRUint32 aLength) NS_IMETHODIMP nsBinaryInputStream::ReadString(nsString* *aString) { + NS_NOTREACHED("ReadString"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/xpcom/io/nsBinaryStream.h b/mozilla/xpcom/io/nsBinaryStream.h index ad42868048a..0fb7f45e6e7 100644 --- a/mozilla/xpcom/io/nsBinaryStream.h +++ b/mozilla/xpcom/io/nsBinaryStream.h @@ -34,9 +34,6 @@ private: // nsISupports methods NS_DECL_ISUPPORTS - // nsIBaseStream methods - NS_DECL_NSIBASESTREAM - // nsIOutputStream methods NS_DECL_NSIOUTPUTSTREAM @@ -60,9 +57,6 @@ private: // nsISupports methods NS_DECL_ISUPPORTS - // nsIBaseStream methods - NS_DECL_NSIBASESTREAM - // nsIInputStream methods NS_DECL_NSIINPUTSTREAM diff --git a/mozilla/xpcom/io/nsByteArrayInputStream.cpp b/mozilla/xpcom/io/nsByteArrayInputStream.cpp index 5f49a7ed81b..4f9502c0100 100644 --- a/mozilla/xpcom/io/nsByteArrayInputStream.cpp +++ b/mozilla/xpcom/io/nsByteArrayInputStream.cpp @@ -22,7 +22,7 @@ #include "nsByteArrayInputStream.h" #include "nsMemory.h" -NS_IMPL_THREADSAFE_ISUPPORTS3(nsByteArrayInputStream, nsIInputStream, nsIBaseStream, nsIByteArrayInputStream) +NS_IMPL_THREADSAFE_ISUPPORTS2(nsByteArrayInputStream, nsIInputStream, nsIByteArrayInputStream) nsByteArrayInputStream::nsByteArrayInputStream (char *buffer, PRUint32 bytes) : _buffer (buffer), _nbytes (bytes), _pos (0) @@ -81,6 +81,34 @@ nsByteArrayInputStream::Read (char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead return NS_OK; } +NS_IMETHODIMP +nsByteArrayInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsByteArrayInputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsByteArrayInputStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsByteArrayInputStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsByteArrayInputStream::Close () { diff --git a/mozilla/xpcom/io/nsByteArrayInputStream.h b/mozilla/xpcom/io/nsByteArrayInputStream.h index 23d524bcfdc..7170581ad3e 100644 --- a/mozilla/xpcom/io/nsByteArrayInputStream.h +++ b/mozilla/xpcom/io/nsByteArrayInputStream.h @@ -27,9 +27,6 @@ class nsByteArrayInputStream : public nsIByteArrayInputStream // nsISupports methods NS_DECL_ISUPPORTS - // nsIBaseStream methods - NS_DECL_NSIBASESTREAM - // nsIInputStream methods NS_DECL_NSIINPUTSTREAM diff --git a/mozilla/xpcom/io/nsIBinaryInputStream.idl b/mozilla/xpcom/io/nsIBinaryInputStream.idl index afb3c07e204..a31a94f734b 100644 --- a/mozilla/xpcom/io/nsIBinaryInputStream.idl +++ b/mozilla/xpcom/io/nsIBinaryInputStream.idl @@ -24,7 +24,7 @@ #include "nsString.h" %} -#include "nsIOutputStream.idl" +#include "nsIInputStream.idl" #include "nsrootidl.idl" /** diff --git a/mozilla/xpcom/io/nsIFileStream.cpp b/mozilla/xpcom/io/nsIFileStream.cpp index 16875fa5ea1..38ae5efda4f 100644 --- a/mozilla/xpcom/io/nsIFileStream.cpp +++ b/mozilla/xpcom/io/nsIFileStream.cpp @@ -66,10 +66,19 @@ class FileImpl // nsIInputStream interface NS_IMETHOD Available(PRUint32 *aLength); NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount); + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval); + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver); + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver); // nsIOutputStream interface NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); NS_IMETHOD Flush(); + NS_IMETHOD WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval); + NS_IMETHOD WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval); + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking); + NS_IMETHOD SetNonBlocking(PRBool aNonBlocking); + NS_IMETHOD GetObserver(nsIOutputStreamObserver * *aObserver); + NS_IMETHOD SetObserver(nsIOutputStreamObserver * aObserver); NS_IMETHOD GetAtEOF(PRBool* outAtEOF); NS_IMETHOD SetAtEOF(PRBool inAtEOF); @@ -105,9 +114,6 @@ NS_IMPL_QUERY_HEAD(FileImpl) NS_IMPL_QUERY_BODY(nsIInputStream) NS_IMPL_QUERY_BODY(nsIFileInputStream) NS_IMPL_QUERY_BODY(nsIFileOutputStream) - if ( aIID.Equals(NS_GET_IID(nsIBaseStream)) ) - foundInterface = NS_STATIC_CAST(nsIBaseStream*, NS_STATIC_CAST(nsIOutputStream*, this)); - else NS_IMPL_QUERY_TAIL(nsIOutputStream) @@ -350,6 +356,26 @@ NS_IMETHODIMP FileImpl::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) return NS_OK; } +NS_IMETHODIMP +FileImpl::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} //---------------------------------------------------------------------------------------- NS_IMETHODIMP FileImpl::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) @@ -418,6 +444,59 @@ NS_IMETHODIMP FileImpl::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWrit return NS_OK; } +static NS_METHOD +nsWriteSegmentToFile(nsIInputStream* in, + void* closure, + const char* fromRawSegment, + PRUint32 toOffset, + PRUint32 count, + PRUint32 *writeCount) +{ + NS_NOTREACHED("nsWriteSegmentToFile"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *result) +{ + return inStr->ReadSegments(nsWriteSegmentToFile, nsnull, count, result); +} + +NS_IMETHODIMP +FileImpl::WriteSegments(nsReadSegmentFun reader, void * closure, + PRUint32 count, PRUint32 *result) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +FileImpl::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} //---------------------------------------------------------------------------------------- NS_IMETHODIMP FileImpl::Tell(PRIntn* outWhere) diff --git a/mozilla/xpcom/io/nsIInputStream.idl b/mozilla/xpcom/io/nsIInputStream.idl index 0ab2c6aaf9a..90c8079e8ba 100644 --- a/mozilla/xpcom/io/nsIInputStream.idl +++ b/mozilla/xpcom/io/nsIInputStream.idl @@ -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.1 (the "License"); you may not use this file @@ -20,24 +20,89 @@ * Contributor(s): */ -#include "nsIBaseStream.idl" +#include "nsISupports.idl" +interface nsIInputStream; +interface nsIInputStreamObserver; -[scriptable, uuid(022396f0-93b5-11d1-895b-006008911b81)] -interface nsIInputStream : nsIBaseStream +%{C++ +/** + * The signature of the writer function passed to ReadSegments. This + * specifies where the data should go that gets read from the buffer. + * Implementers should return the following: + * @return NS_OK and writeCount - if successfully wrote something + * @return NS_BASE_STREAM_CLOSED - if no more can be written + * @return NS_BASE_STREAM_WOULD_BLOCK - if there is currently space to write (in + * a non-blocking mode) + * @return - on failure + */ +typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream* in, + void* closure, + const char* fromRawSegment, + PRUint32 toOffset, + PRUint32 count, + PRUint32 *writeCount); +%} + +native nsWriteSegmentFun(nsWriteSegmentFun); + +[scriptable, uuid(fa9c7f6c-61b3-11d4-9877-00c04fa0cf4a)] +interface nsIInputStream : nsISupports { - /** Return the number of bytes currently available in the stream - * @param aLength out parameter to hold the number of bytes - * if an error occurs, the parameter will be undefined - * @return error status + /** + * Closes the stream. */ - unsigned long Available(); + void close(); - /** Read data from the stream. - * @param aBuf the buffer into which the data is read - * @param aCount the maximum number of bytes to read - * @return aReadCount out parameter to hold the number of - * bytes read, eof if 0. if an error occurs, the - * read count will be undefined + /** + * Return the number of bytes currently available in the stream + * @param aLength out parameter to hold the number of bytes + * if an error occurs, the parameter will be undefined + * @return error status */ - [noscript] unsigned long Read(in charPtr buf, in unsigned long count); + unsigned long available(); + + /** + * Read data from the stream. + * @param aBuf the buffer into which the data is read + * @param aCount the maximum number of bytes to read + * @return aReadCount out parameter to hold the number of + * bytes read, eof if 0. if an error occurs, the + * read count will be undefined + */ + [noscript] unsigned long read(in charPtr buf, in unsigned long count); + + /** + * Low-level read method that has access to the stream's underlying buffer. The + * writer function may be called multiple times for segmented buffers. + */ + [noscript] unsigned long readSegments(in nsWriteSegmentFun writer, + in voidPtr closure, + in unsigned long count); + + /** + * Set this attribute to put the stream in non-blocking mode. + */ + readonly attribute boolean nonBlocking; + + /** + * Allows users to set an observer on an input stream to receive notifications + * about the producer writing data into the input stream, or filling the buffer, + * i.e. that more data is not available. This is necessary for non-blocking streams + * so that the consumer can suspend itself until more data is available. + */ + attribute nsIInputStreamObserver observer; +}; + +[scriptable, uuid(019d67cc-61b4-11d4-9877-00c04fa0cf4a)] +interface nsIInputStreamObserver : nsISupports +{ + /** + * Called when the output stream's consumer has read all the existing data from the stream. + */ + void onEmpty(in nsIInputStream outStr); + + /** + * Called when the consumer closes its end of the stream. + */ + void onClose(in nsIInputStream outStr); }; diff --git a/mozilla/xpcom/io/nsIOutputStream.idl b/mozilla/xpcom/io/nsIOutputStream.idl index db04fb17f5d..fa6c3831aa4 100644 --- a/mozilla/xpcom/io/nsIOutputStream.idl +++ b/mozilla/xpcom/io/nsIOutputStream.idl @@ -20,12 +20,45 @@ * Contributor(s): */ -#include "nsIBaseStream.idl" -#include "nsIInputStream.idl" +#include "nsISupports.idl" +interface nsIOutputStream; +interface nsIOutputStreamObserver; +interface nsIInputStream; -[scriptable, uuid(7f13b870-e95f-11d1-beae-00805f8a66dc)] -interface nsIOutputStream : nsIBaseStream +%{C++ +/** + * The signature for the reader function passed to WriteSegment. This + * specifies where the data should come from that gets written into the buffer. + * Implementers should return the following: + * @return NS_OK and readCount > 0 - if successfully read something + * @return NS_OK and readCount == 0 - if no more to read (EOF) + * @return NS_BASE_STREAM_WOULD_BLOCK - if there is currently no data (in + * a non-blocking mode) + * @return - on failure + */ +typedef NS_CALLBACK(nsReadSegmentFun)(nsIOutputStream* out, + void* closure, + char* toRawSegment, + PRUint32 fromOffset, + PRUint32 count, + PRUint32 *readCount); +%} + +native nsReadSegmentFun(nsReadSegmentFun); + +[scriptable, uuid(0d0acd2a-61b4-11d4-9877-00c04fa0cf4a)] +interface nsIOutputStream : nsISupports { + /** + * Closes the stream. + */ + void close(); + + /** + * Flushes the stream. + */ + void flush(); + /** Write data into the stream. * @param aBuf the buffer from which the data is read * @param aCount the maximum number of bytes to write @@ -33,10 +66,56 @@ interface nsIOutputStream : nsIBaseStream * bytes written. if an error occurs, the writecount * is undefined */ - unsigned long Write(in string buf, in unsigned long count); + unsigned long write(in string buf, in unsigned long count); /** - * Flushes the stream. + * 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 count the maximun number of bytes to write + * @return aWriteCount out parameter to hold the number of + * bytes written. if an error occurs, the writecount + * is undefined */ - void Flush(); + unsigned long writeFrom(in nsIInputStream inStr, + in unsigned long count); + + /** + * Low-level write method that has access to the stream's underlying buffer. The + * reader function may be called multiple times for segmented buffers. + */ + [noscript] unsigned long writeSegments(in nsReadSegmentFun reader, + in voidPtr closure, + in unsigned long count); + /** + * Set this attribute to put the stream in non-blocking mode. + */ + attribute boolean nonBlocking; + + /** + * Allows users to set an observer on an output stream to receive notifications + * about the consumer emptying the output stream's underlying buffer, or closing the + * stream. This is necessary for non-blocking streams so that the producer can suspend + * itself until more data can be written. + */ + attribute nsIOutputStreamObserver observer; +}; + +[scriptable, uuid(12314194-61b4-11d4-9877-00c04fa0cf4a)] +interface nsIOutputStreamObserver : nsISupports +{ + /** + * Called when the input stream's producer has written more data into the stream. + */ + void onWrite(in nsIOutputStream inStr, + in unsigned long amount); + + /** + * Called when the stream's underlying buffer becomes full. + */ + void onFull(in nsIOutputStream inStr); }; diff --git a/mozilla/xpcom/io/nsIPipe.idl b/mozilla/xpcom/io/nsIPipe.idl index 31db264671b..49272995c57 100644 --- a/mozilla/xpcom/io/nsIPipe.idl +++ b/mozilla/xpcom/io/nsIPipe.idl @@ -24,27 +24,18 @@ interface nsIPipe; interface nsIMemory; -interface nsIBufferInputStream; -interface nsIBufferOutputStream; +interface nsIInputStream; +interface nsIOutputStream; -[scriptable, uuid(686b2d98-56c2-11d3-8cd4-0060b0fc14a3)] -interface nsIPipeObserver : nsISupports { - void onFull(in nsIPipe pipe); - void onWrite(in nsIPipe pipe, - in unsigned long amount); - void onEmpty(in nsIPipe pipe); - void onClose(in nsIPipe pipe); -}; - -[scriptable, uuid(6c2c0146-56c2-11d3-8cd4-0060b0fc14a3)] +[scriptable, uuid(f4211abc-61b3-11d4-9877-00c04fa0cf4a)] interface nsIPipe : nsISupports { void initialize(in unsigned long segmentSize, in unsigned long maxSize, - in nsIPipeObserver observer, + in boolean nonBlockingInput, + in boolean nonBlockingOutput, in nsIMemory segmentAllocator); - readonly attribute nsIBufferInputStream inputStream; - readonly attribute nsIBufferOutputStream outputStream; - attribute nsIPipeObserver observer; + readonly attribute nsIInputStream inputStream; + readonly attribute nsIOutputStream outputStream; }; %{C++ @@ -52,9 +43,11 @@ interface nsIPipe : nsISupports { #define NS_PIPE_DEFAULT_BUFFER_SIZE (1024*1024) extern NS_COM nsresult -NS_NewPipe(nsIBufferInputStream* *inStrResult, - nsIBufferOutputStream* *outStrResult, - nsIPipeObserver* observer = nsnull, +NS_NewPipe(nsIInputStream* *inStrResult, + nsIOutputStream* *outStrResult, PRUint32 segmentSize = NS_PIPE_DEFAULT_SEGMENT_SIZE, - PRUint32 maxSize = NS_PIPE_DEFAULT_BUFFER_SIZE); + PRUint32 maxSize = NS_PIPE_DEFAULT_BUFFER_SIZE, + PRBool nonBlockingInput = PR_FALSE, + PRBool nonBlockingOutput = PR_FALSE, + nsIMemory* segmentAllocator = nsnull); %} diff --git a/mozilla/xpcom/io/nsIScriptableInputStream.idl b/mozilla/xpcom/io/nsIScriptableInputStream.idl index 3fb4fc09af2..159c334226d 100644 --- a/mozilla/xpcom/io/nsIScriptableInputStream.idl +++ b/mozilla/xpcom/io/nsIScriptableInputStream.idl @@ -18,13 +18,19 @@ * Copyright (C) 1998-1999 Netscape Communications Corporation. All * Rights Reserved. */ -#include "nsIBaseStream.idl" + +#include "nsISupports.idl" interface nsIInputStream; [scriptable, uuid(a2a32f90-9b90-11d3-a189-0050041caf44)] -interface nsIScriptableInputStream : nsIBaseStream +interface nsIScriptableInputStream : nsISupports { + /** + * Closes the stream. + */ + void close(); + /** Wrap the given nsIInputStream with this nsIScriptableInputStream. * @param aInputStream [in] parameter providing the stream to wrap */ diff --git a/mozilla/xpcom/io/nsIStringStream.cpp b/mozilla/xpcom/io/nsIStringStream.cpp index 304bbaecd7c..933cd8abb24 100644 --- a/mozilla/xpcom/io/nsIStringStream.cpp +++ b/mozilla/xpcom/io/nsIStringStream.cpp @@ -46,11 +46,21 @@ class BasicStringImpl NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount); + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) = 0; + NS_IMETHOD GetObserver(nsIInputStreamObserver * *aObserver); + NS_IMETHOD SetObserver(nsIInputStreamObserver * aObserver); // nsIOutputStream interface NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount); + NS_IMETHOD WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval); + NS_IMETHOD WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval); + NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking); + NS_IMETHOD SetNonBlocking(PRBool aNonBlocking); + NS_IMETHOD GetObserver(nsIOutputStreamObserver * *aObserver); + NS_IMETHOD SetObserver(nsIOutputStreamObserver * aObserver); + public: // nsISupports interface @@ -183,6 +193,20 @@ NS_IMETHODIMP BasicStringImpl::Read(char* aBuf, PRUint32 aCount, PRUint32 *aRead return NS_OK; } +NS_IMETHODIMP +BasicStringImpl::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +BasicStringImpl::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + //---------------------------------------------------------------------------------------- NS_IMETHODIMP BasicStringImpl::Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) //---------------------------------------------------------------------------------------- @@ -202,6 +226,48 @@ NS_IMETHODIMP BasicStringImpl::Write(const char* aBuf, PRUint32 aCount, PRUint32 return NS_OK; } +NS_IMETHODIMP +BasicStringImpl::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *result) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +BasicStringImpl::WriteSegments(nsReadSegmentFun reader, void * closure, + PRUint32 count, PRUint32 *result) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +BasicStringImpl::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +BasicStringImpl::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +BasicStringImpl::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +BasicStringImpl::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} //---------------------------------------------------------------------------------------- PRInt32 BasicStringImpl::write(const char*, PRUint32) @@ -245,6 +311,18 @@ class ConstCharImpl return aCount; } + NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void * closure, + PRUint32 aCount, PRUint32 *result) { + nsresult rv; + PRInt32 maxCount = mLength - mOffset; + if ((PRInt32)aCount > maxCount) + aCount = maxCount; + rv = writer(this, closure, mConstString + mOffset, + 0, aCount, result); + if (NS_SUCCEEDED(rv)) + mOffset += *result; + return rv; + } protected: @@ -404,9 +482,6 @@ NS_IMPL_QUERY_HEAD(BasicStringImpl) NS_IMPL_QUERY_BODY(nsIRandomAccessStore) NS_IMPL_QUERY_BODY(nsIOutputStream) NS_IMPL_QUERY_BODY(nsIInputStream) - if ( aIID.Equals(NS_GET_IID(nsIBaseStream)) ) - foundInterface = NS_STATIC_CAST(nsIBaseStream*, NS_STATIC_CAST(nsIOutputStream*, this)); - else NS_IMPL_QUERY_TAIL(nsIOutputStream) //---------------------------------------------------------------------------------------- diff --git a/mozilla/xpcom/io/nsPipe2.cpp b/mozilla/xpcom/io/nsPipe2.cpp index e50b0329eed..8c15c01ff6a 100644 --- a/mozilla/xpcom/io/nsPipe2.cpp +++ b/mozilla/xpcom/io/nsPipe2.cpp @@ -22,8 +22,8 @@ */ #include "nsIPipe.h" -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsSegmentedBuffer.h" #include "nsAutoLock.h" #include "nsIServiceManager.h" @@ -39,15 +39,23 @@ //////////////////////////////////////////////////////////////////////////////// +#define GET_INPUTSTREAM_PIPE(_this) \ + ((nsPipe*)((char*)(_this) - offsetof(nsPipe, mInput))) + +#define GET_OUTPUTSTREAM_PIPE(_this) \ + ((nsPipe*)((char*)(_this) - offsetof(nsPipe, mOutput))) + +//////////////////////////////////////////////////////////////////////////////// + class nsPipe : public nsIPipe { public: - // We can't inherit from both nsIBufferInputStream and nsIBufferOutputStream + // We can't inherit from both nsIInputStream and nsIOutputStream // because they collide on their Close method. Consequently we nest their // implementations to avoid the extra object allocation, and speed up method // invocation between them and the nsPipe's buffer manipulation methods. - class nsPipeInputStream : public nsIBufferInputStream { + class nsPipeInputStream : public nsIInputStream { public: NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD_(nsrefcnt) AddRef(void); @@ -57,25 +65,34 @@ public: // nsIInputStream methods: NS_IMETHOD Available(PRUint32 *result); NS_IMETHOD Read(char* toBuf, PRUint32 bufLen, PRUint32 *readCount); - // nsIBufferInputStream methods: - NS_IMETHOD GetBuffer(nsIBuffer * *aBuffer) { - return NS_ERROR_NOT_IMPLEMENTED; - } + // nsIInputStream methods: NS_IMETHOD ReadSegments(nsWriteSegmentFun writer, void* closure, PRUint32 count, PRUint32 *readCount); NS_IMETHOD Search(const char *forString, PRBool ignoreCase, PRBool *found, PRUint32 *offsetSearchedTo); NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking); NS_IMETHOD SetNonBlocking(PRBool aNonBlocking); + NS_IMETHOD GetObserver(nsIInputStreamObserver* *result) { + *result = mObserver; + NS_IF_ADDREF(*result); + return NS_OK; + } + + NS_IMETHOD SetObserver(nsIInputStreamObserver* obs) { + mObserver = obs; + return NS_OK; + } nsPipeInputStream() : mReaderRefCnt(0), mBlocking(PR_TRUE) {} nsresult Fill(); + protected: nsrefcnt mReaderRefCnt; // separate refcnt so that we know when to close the consumer PRBool mBlocking; + nsCOMPtr mObserver; }; - class nsPipeOutputStream : public nsIBufferOutputStream { + class nsPipeOutputStream : public nsIOutputStream { public: NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); NS_IMETHOD_(nsrefcnt) AddRef(void); @@ -84,20 +101,29 @@ public: NS_IMETHOD Close(void); NS_IMETHOD Write(const char* fromBuf, PRUint32 bufLen, PRUint32 *writeCount); NS_IMETHOD Flush(void); - // nsIBufferOutputStream methods: - NS_IMETHOD GetBuffer(nsIBuffer * *aBuffer) { - return NS_ERROR_NOT_IMPLEMENTED; - } + // nsIOutputStream methods: NS_IMETHOD WriteSegments(nsReadSegmentFun reader, void* closure, PRUint32 count, PRUint32 *writeCount); NS_IMETHOD WriteFrom(nsIInputStream* fromStream, PRUint32 count, PRUint32 *writeCount); NS_IMETHOD GetNonBlocking(PRBool *aNonBlocking); NS_IMETHOD SetNonBlocking(PRBool aNonBlocking); + NS_IMETHOD GetObserver(nsIOutputStreamObserver* *result) { + *result = mObserver; + NS_IF_ADDREF(*result); + return NS_OK; + } + + NS_IMETHOD SetObserver(nsIOutputStreamObserver* obs) { + mObserver = obs; + return NS_OK; + } nsPipeOutputStream() : mWriterRefCnt(0), mBlocking(PR_TRUE) {} + protected: nsrefcnt mWriterRefCnt; // separate refcnt so that we know when to close the producer PRBool mBlocking; + nsCOMPtr mObserver; }; friend class nsPipeInputStream; @@ -106,42 +132,36 @@ public: NS_DECL_ISUPPORTS // nsIPipe methods: - NS_IMETHOD Initialize(PRUint32 segmentSize, PRUint32 maxSize, - nsIPipeObserver *observer, nsIMemory *segmentAllocator) { + NS_IMETHOD Initialize(PRUint32 segmentSize, PRUint32 maxSize, + PRBool nonBlockingIn, PRBool nonBlockingOut, + nsIMemory *segmentAllocator) { nsresult rv; + mMonitor = PR_NewMonitor(); + if (mMonitor == nsnull) + return NS_ERROR_OUT_OF_MEMORY; rv = mBuffer.Init(segmentSize, maxSize, segmentAllocator); - if (NS_FAILED(rv)) return rv; - mObserver = observer; + GetInputStream()->SetNonBlocking(nonBlockingIn); + GetOutputStream()->SetNonBlocking(nonBlockingOut); return NS_OK; } - NS_IMETHOD GetInputStream(nsIBufferInputStream * *aInputStream) { + NS_IMETHOD GetInputStream(nsIInputStream * *aInputStream) { *aInputStream = &mInput; NS_IF_ADDREF(*aInputStream); return NS_OK; } - NS_IMETHOD GetOutputStream(nsIBufferOutputStream * *aOutputStream) { + NS_IMETHOD GetOutputStream(nsIOutputStream * *aOutputStream) { *aOutputStream = &mOutput; NS_IF_ADDREF(*aOutputStream); return NS_OK; } - NS_IMETHOD GetObserver(nsIPipeObserver* *result) { - *result = mObserver; - NS_IF_ADDREF(*result); - return NS_OK; - } - - NS_IMETHOD SetObserver(nsIPipeObserver* obs) { - mObserver = obs; - return NS_OK; - } - // nsPipe methods: nsPipe(); virtual ~nsPipe(); + PRMonitor* GetMonitor() { return mMonitor; } nsPipeInputStream* GetInputStream() { return &mInput; } nsPipeOutputStream* GetOutputStream() { return &mOutput; } @@ -152,11 +172,11 @@ public: PRUint32 *resultSegmentLen); protected: + PRMonitor* mMonitor; nsPipeInputStream mInput; nsPipeOutputStream mOutput; nsSegmentedBuffer mBuffer; - nsCOMPtr mObserver; char* mReadCursor; char* mReadLimit; @@ -167,17 +187,12 @@ protected: nsresult mCondition; }; -#define GET_INPUTSTREAM_PIPE(_this) \ - ((nsPipe*)((char*)(_this) - offsetof(nsPipe, mInput))) - -#define GET_OUTPUTSTREAM_PIPE(_this) \ - ((nsPipe*)((char*)(_this) - offsetof(nsPipe, mOutput))) - //////////////////////////////////////////////////////////////////////////////// // nsPipe methods: nsPipe::nsPipe() - : mReadCursor(nsnull), + : mMonitor(nsnull), + mReadCursor(nsnull), mReadLimit(nsnull), mWriteCursor(nsnull), mWriteLimit(nsnull), @@ -188,6 +203,7 @@ nsPipe::nsPipe() nsPipe::~nsPipe() { + if (mMonitor) PR_DestroyMonitor(mMonitor); } NS_IMPL_THREADSAFE_ADDREF(nsPipe); @@ -198,18 +214,14 @@ nsPipe::QueryInterface(const nsIID& aIID, void** aInstancePtr) { if (aInstancePtr == nsnull) return NS_ERROR_NULL_POINTER; - if (aIID.Equals(NS_GET_IID(nsIBufferInputStream)) || - aIID.Equals(NS_GET_IID(nsIInputStream)) || - aIID.Equals(NS_GET_IID(nsIBaseStream))) { - nsIBufferInputStream* in = GetInputStream(); + if (aIID.Equals(NS_GET_IID(nsIInputStream))) { + nsIInputStream* in = GetInputStream(); NS_ADDREF(in); *aInstancePtr = in; return NS_OK; } - if (aIID.Equals(NS_GET_IID(nsIBufferOutputStream)) || - aIID.Equals(NS_GET_IID(nsIOutputStream)) || - aIID.Equals(NS_GET_IID(nsIBaseStream))) { - nsIBufferOutputStream* out = GetOutputStream(); + if (aIID.Equals(NS_GET_IID(nsIOutputStream))) { + nsIOutputStream* out = GetOutputStream(); NS_ADDREF(out); *aInstancePtr = out; return NS_OK; @@ -228,7 +240,7 @@ nsPipe::GetReadSegment(PRUint32 segmentLogicalOffset, const char* *resultSegment, PRUint32 *resultSegmentLen) { - nsAutoCMonitor mon(this); + nsAutoMonitor mon(mMonitor); PRInt32 offset = (PRInt32)segmentLogicalOffset; PRInt32 segCount = mBuffer.GetSegmentCount(); @@ -266,7 +278,7 @@ nsresult nsPipe::GetWriteSegment(char* *resultSegment, PRUint32 *resultSegmentLen) { - nsAutoCMonitor mon(this); + nsAutoMonitor mon(mMonitor); *resultSegment = nsnull; *resultSegmentLen = 0; @@ -314,20 +326,20 @@ NS_IMETHODIMP nsPipe::nsPipeInputStream::Close(void) { nsPipe* pipe = GET_INPUTSTREAM_PIPE(this); - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); pipe->mCondition = NS_BASE_STREAM_CLOSED; pipe->mBuffer.Empty(); pipe->mWriteCursor = nsnull; pipe->mWriteLimit = nsnull; - if (pipe->mObserver) { - nsCOMPtr obs = pipe->mObserver; + if (mObserver) { + nsCOMPtr obs = mObserver; mon.Exit(); // XXXbe avoid deadlock better - nsresult rv = obs->OnClose(pipe); + nsresult rv = obs->OnClose(this); mon.Enter(); NS_ASSERTION(NS_SUCCEEDED(rv), "OnClose failed"); // don't return error from OnClose -- its not our problem - pipe->mObserver = nsnull; // so we don't call OnClose again + mObserver = nsnull; // so we don't call OnClose again } return NS_OK; } @@ -336,7 +348,7 @@ NS_IMETHODIMP nsPipe::nsPipeInputStream::Available(PRUint32 *result) { nsPipe* pipe = GET_INPUTSTREAM_PIPE(this); - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); PRUint32 len = pipe->mBuffer.GetSize(); if (pipe->mReadCursor) @@ -355,7 +367,7 @@ nsPipe::nsPipeInputStream::ReadSegments(nsWriteSegmentFun writer, PRUint32 *readCount) { nsPipe* pipe = GET_INPUTSTREAM_PIPE(this); - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); nsresult rv = NS_OK; PRUint32 readBufferLen; @@ -371,9 +383,9 @@ nsPipe::nsPipeInputStream::ReadSegments(nsWriteSegmentFun writer, rv = pipe->mCondition; if (*readCount > 0 || NS_FAILED(rv)) goto done; // don't Fill if we've got something - if (pipe->mObserver) { + if (mObserver) { mon.Exit(); // XXXbe avoid deadlock better - rv = pipe->mObserver->OnEmpty(pipe); + rv = mObserver->OnEmpty(this); mon.Enter(); if (NS_FAILED(rv)) goto done; } @@ -386,10 +398,16 @@ nsPipe::nsPipeInputStream::ReadSegments(nsWriteSegmentFun writer, readBufferLen = PR_MIN(readBufferLen, amt); while (readBufferLen > 0) { - PRUint32 writeCount; - rv = writer(closure, readBuffer, *readCount, readBufferLen, &writeCount); + PRUint32 writeCount = 0; + rv = writer(this, closure, readBuffer, *readCount, readBufferLen, &writeCount); if (NS_FAILED(rv) && rv != NS_BASE_STREAM_WOULD_BLOCK) goto done; + NS_ASSERTION(writeCount <= readBufferLen, "writer returned bad writeCount"); + readBuffer += writeCount; + readBufferLen -= writeCount; + *readCount += writeCount; + amt -= writeCount; + pipe->mReadCursor += writeCount; if (writeCount == 0 || rv == NS_BASE_STREAM_WOULD_BLOCK) { rv = pipe->mCondition; if (*readCount > 0 || NS_FAILED(rv)) @@ -400,20 +418,14 @@ nsPipe::nsPipeInputStream::ReadSegments(nsWriteSegmentFun writer, // else we filled the pipe, so go around again continue; } - NS_ASSERTION(writeCount <= readBufferLen, "writer returned bad writeCount"); - readBuffer += writeCount; - readBufferLen -= writeCount; - *readCount += writeCount; - amt -= writeCount; - pipe->mReadCursor += writeCount; } if (pipe->mReadCursor == pipe->mReadLimit) { pipe->mReadCursor = nsnull; pipe->mReadLimit = nsnull; PRBool empty = pipe->mBuffer.DeleteFirstSegment(); - if (empty && pipe->mObserver) { + if (empty && mObserver) { mon.Exit(); // XXXbe avoid deadlock better - rv = pipe->mObserver->OnEmpty(pipe); + rv = mObserver->OnEmpty(this); mon.Enter(); mon.Notify(); // wake up writer if (NS_FAILED(rv)) @@ -428,14 +440,14 @@ nsPipe::nsPipeInputStream::ReadSegments(nsWriteSegmentFun writer, } if (rv == NS_BASE_STREAM_CLOSED) { // EOF - if (pipe->mObserver) { - nsCOMPtr obs = pipe->mObserver; + if (mObserver) { + nsCOMPtr obs = mObserver; mon.Exit(); // XXXbe avoid deadlock better - nsresult rv2 = obs->OnClose(pipe); + nsresult rv2 = obs->OnClose(this); mon.Enter(); NS_ASSERTION(NS_SUCCEEDED(rv2), "OnClose failed"); // don't return error from OnClose -- its not our problem - pipe->mObserver = nsnull; // so we don't call OnClose again + mObserver = nsnull; // so we don't call OnClose again } rv = NS_OK; } @@ -447,7 +459,7 @@ nsresult nsPipe::nsPipeInputStream::Fill() { nsPipe* pipe = GET_INPUTSTREAM_PIPE(this); - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); nsresult rv; while (PR_TRUE) { @@ -474,7 +486,8 @@ nsPipe::nsPipeInputStream::Fill() } static NS_METHOD -nsWriteToRawBuffer(void* closure, +nsWriteToRawBuffer(nsIInputStream* inStr, + void* closure, const char* fromRawSegment, PRUint32 offset, PRUint32 count, @@ -608,7 +621,7 @@ NS_IMETHODIMP nsPipe::nsPipeOutputStream::Close(void) { nsPipe* pipe = GET_OUTPUTSTREAM_PIPE(this); - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); if (pipe->mCondition == NS_OK) pipe->mCondition = NS_BASE_STREAM_CLOSED; nsresult rv = mon.Notify(); // wake up the writer @@ -625,12 +638,12 @@ nsPipe::nsPipeOutputStream::WriteSegments(nsReadSegmentFun reader, { nsresult rv = NS_OK; #ifdef MASK_PREMATURE_STREAM_RELEASE - nsCOMPtr kungFuDeathGrip(this); + nsCOMPtr kungFuDeathGrip(this); #endif nsPipe* pipe = GET_OUTPUTSTREAM_PIPE(this); PRUint32 amt = count; { - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); *writeCount = 0; if (NS_FAILED(pipe->mCondition) @@ -648,9 +661,9 @@ nsPipe::nsPipeOutputStream::WriteSegments(nsReadSegmentFun reader, if (writeBufLen == 0) { if (*writeCount > 0 && !mBlocking) goto done; - if (pipe->mObserver/* && *writeCount == 0*/) { + if (mObserver/* && *writeCount == 0*/) { mon.Exit(); // XXXbe avoid deadlock better - rv = pipe->mObserver->OnFull(pipe); + rv = mObserver->OnFull(this); mon.Enter(); if (NS_FAILED(rv)) goto done; } @@ -664,8 +677,15 @@ nsPipe::nsPipeOutputStream::WriteSegments(nsReadSegmentFun reader, writeBufLen = PR_MIN(writeBufLen, amt); while (writeBufLen > 0) { PRUint32 readCount = 0; - rv = reader(closure, writeBuf, *writeCount, writeBufLen, &readCount); + rv = reader(this, closure, writeBuf, *writeCount, writeBufLen, &readCount); if (rv == NS_BASE_STREAM_WOULD_BLOCK) { + NS_ASSERTION(readCount <= writeBufLen, "reader returned bad readCount"); + writeBuf += readCount; + writeBufLen -= readCount; + *writeCount += readCount; + amt -= readCount; + pipe->mWriteCursor += readCount; + // The reader didn't have anything else to put in the buffer, so // call flush to notify the guy downstream, hoping that he'll somehow // wake up the guy upstream to eventually produce more data for us. @@ -705,15 +725,16 @@ nsPipe::nsPipeOutputStream::WriteSegments(nsReadSegmentFun reader, ; } // exit monitor - if (pipe->mObserver && *writeCount > 0) { - pipe->mObserver->OnWrite(pipe, *writeCount); + if (mObserver && *writeCount > 0) { + mObserver->OnWrite(this, *writeCount); } NS_ASSERTION(*writeCount <= count, "wrote more than expected"); return *writeCount == 0 ? rv : NS_OK; } static NS_METHOD -nsReadFromRawBuffer(void* closure, +nsReadFromRawBuffer(nsIOutputStream* outStr, + void* closure, char* toRawSegment, PRUint32 offset, PRUint32 count, @@ -737,7 +758,7 @@ NS_IMETHODIMP nsPipe::nsPipeOutputStream::Flush(void) { nsPipe* pipe = GET_OUTPUTSTREAM_PIPE(this); - nsAutoCMonitor mon(pipe); + nsAutoMonitor mon(pipe->GetMonitor()); nsresult rv = NS_OK; PRBool firstTime = PR_TRUE; while (PR_TRUE) { @@ -769,7 +790,8 @@ nsPipe::nsPipeOutputStream::Flush(void) } static NS_METHOD -nsReadFromInputStream(void* closure, +nsReadFromInputStream(nsIOutputStream* outStr, + void* closure, char* toRawSegment, PRUint32 offset, PRUint32 count, @@ -809,11 +831,13 @@ static NS_DEFINE_CID(kPageManagerCID, NS_PAGEMANAGER_CID); static NS_DEFINE_CID(kMemoryCID, NS_MEMORY_CID); NS_COM nsresult -NS_NewPipe(nsIBufferInputStream* *inStrResult, - nsIBufferOutputStream* *outStrResult, - nsIPipeObserver* observer, +NS_NewPipe(nsIInputStream* *inStrResult, + nsIOutputStream* *outStrResult, PRUint32 segmentSize, - PRUint32 maxSize) + PRUint32 maxSize, + PRBool nonBlockingInput, + PRBool nonBlockingOutput, + nsIMemory* memory) { nsresult rv; NS_ASSERTION(segmentSize > 0, "need to supply segmentSize for buffer"); @@ -831,13 +855,18 @@ NS_NewPipe(nsIBufferInputStream* *inStrResult, } #endif #endif - NS_WITH_SERVICE(nsIMemory, alloc, *cid, &rv); - if (NS_FAILED(rv)) return rv; + nsCOMPtr alloc = memory; + if (alloc == nsnull) { + alloc = do_GetService(*cid, &rv); + if (NS_FAILED(rv)) return rv; + } nsPipe* pipe = new nsPipe(); if (pipe == nsnull) return NS_ERROR_OUT_OF_MEMORY; - rv = pipe->Initialize(segmentSize, maxSize, observer, alloc); + rv = pipe->Initialize(segmentSize, maxSize, + nonBlockingInput, nonBlockingOutput, + alloc); if (NS_FAILED(rv)) { delete pipe; return rv; diff --git a/mozilla/xpcom/io/nsScriptableInputStream.cpp b/mozilla/xpcom/io/nsScriptableInputStream.cpp index d34b8cf0481..0e09934addf 100644 --- a/mozilla/xpcom/io/nsScriptableInputStream.cpp +++ b/mozilla/xpcom/io/nsScriptableInputStream.cpp @@ -23,7 +23,7 @@ #include "nsScriptableInputStream.h" #include "nsMemory.h" -NS_IMPL_ISUPPORTS2(nsScriptableInputStream, nsIBaseStream, nsIScriptableInputStream); +NS_IMPL_ISUPPORTS1(nsScriptableInputStream, nsIScriptableInputStream); // nsIBaseStream methods NS_IMETHODIMP diff --git a/mozilla/xpcom/io/nsScriptableInputStream.h b/mozilla/xpcom/io/nsScriptableInputStream.h index 77b1a6d420c..beb75509b3b 100644 --- a/mozilla/xpcom/io/nsScriptableInputStream.h +++ b/mozilla/xpcom/io/nsScriptableInputStream.h @@ -38,9 +38,6 @@ public: // nsISupports methods NS_DECL_ISUPPORTS - // nsIBaseStream methods - NS_DECL_NSIBASESTREAM - // nsIScriptableInputStream methods NS_DECL_NSISCRIPTABLEINPUTSTREAM diff --git a/mozilla/xpcom/io/nsStorageStream.cpp b/mozilla/xpcom/io/nsStorageStream.cpp index baa250550be..91f942d30ff 100644 --- a/mozilla/xpcom/io/nsStorageStream.cpp +++ b/mozilla/xpcom/io/nsStorageStream.cpp @@ -33,7 +33,7 @@ #include "nsSegmentedBuffer.h" #include "nsCOMPtr.h" #include "prbit.h" - +#include "nsIInputStream.h" #include "prlog.h" #if defined(PR_LOGGING) @@ -208,6 +208,48 @@ nsStorageStream::Write(const char *aBuffer, PRUint32 aCount, PRUint32 *aNumWritt return rv; } +NS_IMETHODIMP +nsStorageStream::WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteFrom"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("WriteSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageStream::SetNonBlocking(PRBool aNonBlocking) +{ + NS_NOTREACHED("SetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageStream::GetObserver(nsIOutputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageStream::SetObserver(nsIOutputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_IMETHODIMP nsStorageStream::GetLength(PRUint32 *aLength) { @@ -307,7 +349,6 @@ public: } NS_DECL_ISUPPORTS - NS_DECL_NSIBASESTREAM NS_DECL_NSIINPUTSTREAM protected: @@ -400,6 +441,34 @@ nsStorageInputStream::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aNumRead) return NS_OK; } +NS_IMETHODIMP +nsStorageInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval) +{ + NS_NOTREACHED("ReadSegments"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageInputStream::GetNonBlocking(PRBool *aNonBlocking) +{ + NS_NOTREACHED("GetNonBlocking"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageInputStream::GetObserver(nsIInputStreamObserver * *aObserver) +{ + NS_NOTREACHED("GetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsStorageInputStream::SetObserver(nsIInputStreamObserver * aObserver) +{ + NS_NOTREACHED("SetObserver"); + return NS_ERROR_NOT_IMPLEMENTED; +} + NS_METHOD nsStorageInputStream::Seek(PRUint32 aPosition) { diff --git a/mozilla/xpcom/io/nsStorageStream.h b/mozilla/xpcom/io/nsStorageStream.h index a3d6d4f4d83..1b10618f7ba 100644 --- a/mozilla/xpcom/io/nsStorageStream.h +++ b/mozilla/xpcom/io/nsStorageStream.h @@ -47,7 +47,6 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSISTORAGESTREAM - NS_DECL_NSIBASESTREAM NS_DECL_NSIOUTPUTSTREAM friend class nsStorageInputStream; diff --git a/mozilla/xpcom/tests/TestPipes.cpp b/mozilla/xpcom/tests/TestPipes.cpp index c80f0ca6208..8d375780ebe 100644 --- a/mozilla/xpcom/tests/TestPipes.cpp +++ b/mozilla/xpcom/tests/TestPipes.cpp @@ -23,14 +23,8 @@ #include "nsIThread.h" #include "nsIRunnable.h" -#if 0 // obsolete old implementation -#include "nsIByteBufferInputStream.h" -#endif -#ifdef OLD_BUFFERS -#include "nsIBuffer.h" -#endif -#include "nsIBufferInputStream.h" -#include "nsIBufferOutputStream.h" +#include "nsIInputStream.h" +#include "nsIOutputStream.h" #include "nsIServiceManager.h" #include "prprf.h" #include "prinrval.h" @@ -98,7 +92,7 @@ protected: PRUint32 mCount; }; -NS_IMPL_ISUPPORTS(nsReceiver, NS_GET_IID(nsIRunnable)); +NS_IMPL_THREADSAFE_ISUPPORTS1(nsReceiver, nsIRunnable); nsresult TestPipe(nsIInputStream* in, nsIOutputStream* out) @@ -208,7 +202,7 @@ protected: PRUint32 mReceived; }; -NS_IMPL_ISUPPORTS(nsShortReader, NS_GET_IID(nsIRunnable)); +NS_IMPL_THREADSAFE_ISUPPORTS1(nsShortReader, nsIRunnable); nsresult TestShortWrites(nsIInputStream* in, nsIOutputStream* out) @@ -255,27 +249,29 @@ TestShortWrites(nsIInputStream* in, nsIOutputStream* out) //////////////////////////////////////////////////////////////////////////////// -class nsPipeObserver : public nsIPipeObserver { +class nsPipeObserver : public nsIInputStreamObserver, + public nsIOutputStreamObserver +{ public: NS_DECL_ISUPPORTS - NS_IMETHOD OnFull(nsIPipe *pipe) { - printf("OnFull pipe=%p\n", pipe); + NS_IMETHOD OnFull(nsIOutputStream *outStr) { + printf("OnFull outStr=%p\n", outStr); return NS_OK; } - NS_IMETHOD OnWrite(nsIPipe *pipe, PRUint32 amount) { - printf("OnWrite pipe=%p amount=%d\n", pipe, amount); + NS_IMETHOD OnWrite(nsIOutputStream *outStr, PRUint32 amount) { + printf("OnWrite outStr=%p amount=%d\n", outStr, amount); return NS_OK; } - NS_IMETHOD OnEmpty(nsIPipe *pipe) { - printf("OnEmpty pipe=%p\n", pipe); + NS_IMETHOD OnEmpty(nsIInputStream* inStr) { + printf("OnEmpty inStr=%p\n", inStr); return NS_OK; } - NS_IMETHOD OnClose(nsIPipe *pipe) { - printf("OnClose pipe=%p\n", pipe); + NS_IMETHOD OnClose(nsIInputStream* inStr) { + printf("OnClose inStr=%p\n", inStr); return NS_OK; } @@ -283,7 +279,7 @@ public: virtual ~nsPipeObserver() {} }; -NS_IMPL_ISUPPORTS(nsPipeObserver, NS_GET_IID(nsIPipeObserver)); +NS_IMPL_ISUPPORTS2(nsPipeObserver, nsIInputStreamObserver, nsIOutputStreamObserver); nsresult TestPipeObserver() @@ -294,14 +290,14 @@ TestPipeObserver() NS_ADDREF(obs); printf("TestPipeObserver: OnWrite and OnFull should be called once, OnEmpty should be called twice.\n"); - nsIBufferInputStream* in; - nsIBufferOutputStream* out; - rv = NS_NewPipe(&in, &out, obs, 20, 20); + nsIInputStream* in; + nsIOutputStream* out; + rv = NS_NewPipe(&in, &out, 20, 20, PR_TRUE, PR_TRUE); if (NS_FAILED(rv)) return rv; - rv = in->SetNonBlocking(PR_TRUE); + rv = in->SetObserver(obs); if (NS_FAILED(rv)) return rv; - rv = out->SetNonBlocking(PR_TRUE); + rv = out->SetObserver(obs); if (NS_FAILED(rv)) return rv; char buf[] = "puirt a beul: a style of Gaelic vocal music intended for dancing."; @@ -335,31 +331,34 @@ TestPipeObserver() //////////////////////////////////////////////////////////////////////////////// -class nsPump : public nsIPipeObserver, public nsIRunnable { +class nsPump : public nsIInputStreamObserver, + public nsIOutputStreamObserver, + public nsIRunnable +{ public: NS_DECL_ISUPPORTS - NS_IMETHOD OnFull(nsIPipe *pipe) { - printf("OnFull pipe=%p\n", pipe); + NS_IMETHOD OnFull(nsIOutputStream *outStr) { + printf("OnFull outStr=%p\n", outStr); nsAutoCMonitor mon(this); mon.Notify(); return NS_OK; } - NS_IMETHOD OnWrite(nsIPipe *pipe, PRUint32 amount) { - printf("OnWrite pipe=%p amount=%d\n", pipe, amount); + NS_IMETHOD OnWrite(nsIOutputStream *outStr, PRUint32 amount) { + printf("OnWrite outStr=%p amount=%d\n", outStr, amount); return NS_OK; } - NS_IMETHOD OnEmpty(nsIPipe *pipe) { - printf("OnEmpty pipe=%p\n", pipe); + NS_IMETHOD OnEmpty(nsIInputStream *inStr) { + printf("OnEmpty inStr=%p\n", inStr); nsAutoCMonitor mon(this); mon.Notify(); return NS_OK; } - NS_IMETHOD OnClose(nsIPipe *pipe) { - printf("OnClose pipe=%p\n", pipe); + NS_IMETHOD OnClose(nsIInputStream *inStr) { + printf("OnClose inStr=%p\n", inStr); nsAutoCMonitor mon(this); mon.Notify(); return NS_OK; @@ -389,8 +388,8 @@ public: return rv; } - nsPump(nsIBufferInputStream* in, - nsIBufferOutputStream* out) + nsPump(nsIInputStream* in, + nsIOutputStream* out) : mIn(in), mOut(out), mCount(0) { NS_INIT_REFCNT(); } @@ -399,12 +398,13 @@ public: } protected: - nsCOMPtr mIn; - nsCOMPtr mOut; + nsCOMPtr mIn; + nsCOMPtr mOut; PRUint32 mCount; }; -NS_IMPL_ISUPPORTS2(nsPump, nsIPipeObserver, nsIRunnable) +NS_IMPL_THREADSAFE_ISUPPORTS3(nsPump, nsIInputStreamObserver, + nsIOutputStreamObserver, nsIRunnable) nsresult TestChainedPipes() @@ -412,14 +412,14 @@ TestChainedPipes() nsresult rv; printf("TestChainedPipes\n"); - nsIBufferInputStream* in1; - nsIBufferOutputStream* out1; - rv = NS_NewPipe(&in1, &out1, nsnull, 20, 1999); + nsIInputStream* in1; + nsIOutputStream* out1; + rv = NS_NewPipe(&in1, &out1, 20, 1999); if (NS_FAILED(rv)) return rv; - nsIBufferInputStream* in2; - nsIBufferOutputStream* out2; - rv = NS_NewPipe(&in2, &out2, nsnull, 200, 401); + nsIInputStream* in2; + nsIOutputStream* out2; + rv = NS_NewPipe(&in2, &out2, 200, 401); if (NS_FAILED(rv)) return rv; nsIThread* thread; @@ -476,34 +476,15 @@ void RunTests(PRUint32 segSize, PRUint32 segCount) { nsresult rv; - nsIBufferInputStream* in; - nsIBufferOutputStream* out; + nsIInputStream* in; + nsIOutputStream* out; PRUint32 bufSize; -#ifdef OLD_BUFFERS - bufSize = (segSize + nsIBuffer::SEGMENT_OVERHEAD) * segCount; - printf("Testing Old Pipes: segment size %d buffer size %d\n", segSize, segSize * segCount); - printf("Testing long writes...\n"); - rv = NS_NewPipe(&in, &out, segSize + nsIBuffer::SEGMENT_OVERHEAD, bufSize, PR_TRUE, nsnull); - NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewPipe failed"); - rv = TestPipe(in, out); - NS_RELEASE(in); - NS_RELEASE(out); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestPipe failed"); - - printf("Testing short writes...\n"); - rv = NS_NewPipe(&in, &out, segSize + nsIBuffer::SEGMENT_OVERHEAD, bufSize, PR_TRUE, nsnull); - NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewPipe failed"); - rv = TestShortWrites(in, out); - NS_RELEASE(in); - NS_RELEASE(out); - NS_ASSERTION(NS_SUCCEEDED(rv), "TestPipe failed"); -#endif bufSize = segSize * segCount; printf("Testing New Pipes: segment size %d buffer size %d\n", segSize, bufSize); printf("Testing long writes...\n"); - rv = NS_NewPipe(&in, &out, nsnull, segSize, bufSize); + rv = NS_NewPipe(&in, &out, segSize, bufSize); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewPipe failed"); rv = TestPipe(in, out); NS_RELEASE(in); @@ -511,7 +492,7 @@ RunTests(PRUint32 segSize, PRUint32 segCount) NS_ASSERTION(NS_SUCCEEDED(rv), "TestPipe failed"); printf("Testing short writes...\n"); - rv = NS_NewPipe(&in, &out, nsnull, segSize, bufSize); + rv = NS_NewPipe(&in, &out, segSize, bufSize); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewPipe failed"); rv = TestShortWrites(in, out); NS_RELEASE(in); @@ -520,7 +501,7 @@ RunTests(PRUint32 segSize, PRUint32 segCount) } //////////////////////////////////////////////////////////////////////////////// - +#if 0 void TestSearch(const char* delim, PRUint32 segSize) { @@ -528,9 +509,9 @@ TestSearch(const char* delim, PRUint32 segSize) // need at least 2 segments to test boundary conditions: PRUint32 bufDataSize = segSize * 2; PRUint32 bufSize = segSize * 2; - nsIBufferInputStream* in; - nsIBufferOutputStream* out; - rv = NS_NewPipe(&in, &out, nsnull, segSize, bufSize); + nsIInputStream* in; + nsIOutputStream* out; + rv = NS_NewPipe(&in, &out, segSize, bufSize); NS_ASSERTION(NS_SUCCEEDED(rv), "NS_NewPipe failed"); out->SetNonBlocking(PR_TRUE); @@ -550,7 +531,7 @@ TestSearch(const char* delim, PRUint32 segSize) NS_ASSERTION(NS_SUCCEEDED(rv) && amt == 1, "Write failed"); } } - + // now search for the delimiter PRBool found; PRUint32 offset; @@ -568,7 +549,7 @@ TestSearch(const char* delim, PRUint32 segSize) NS_RELEASE(in); NS_RELEASE(out); } - +#endif //////////////////////////////////////////////////////////////////////////////// #ifdef DEBUG @@ -593,7 +574,7 @@ main(int argc, char* argv[]) #endif #if 0 // obsolete old implementation - rv = NS_NewPipe(&in, &out, PR_TRUE, 4096 * 4); + rv = NS_NewPipe(&in, &out, 4096 * 4); if (NS_FAILED(rv)) { printf("NewPipe failed\n"); return -1; @@ -607,9 +588,11 @@ main(int argc, char* argv[]) return -1; } #endif +#if 0 TestSearch("foo", 8); TestSearch("bar", 6); TestSearch("baz", 2); +#endif rv = TestPipeObserver(); NS_ASSERTION(NS_SUCCEEDED(rv), "TestPipeObserver failed"); diff --git a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp index 6abb005326d..d85ea638941 100644 --- a/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp +++ b/mozilla/xpfe/components/bookmarks/src/nsBookmarksService.cpp @@ -88,7 +88,7 @@ #include "nsIStringBundle.h" #include "nsIInputStream.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsIStreamListener.h" #include "nsIHTTPHeader.h" diff --git a/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp b/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp index 61f5624283d..6e0f0e7a03b 100644 --- a/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp +++ b/mozilla/xpfe/components/related/src/nsRelatedLinksHandler.cpp @@ -42,7 +42,7 @@ #include "nsIStreamListener.h" #include "nsIURL.h" #include "nsNetUtil.h" -#include "nsIBufferInputStream.h" +#include "nsIInputStream.h" #include "nsIPref.h" #include "nsRDFCID.h" #include "nsString.h" diff --git a/mozilla/xpinstall/src/nsXPInstallManager.cpp b/mozilla/xpinstall/src/nsXPInstallManager.cpp index de194265cff..bcdd178f52b 100644 --- a/mozilla/xpinstall/src/nsXPInstallManager.cpp +++ b/mozilla/xpinstall/src/nsXPInstallManager.cpp @@ -35,7 +35,6 @@ #include "nsIFileTransportService.h" #include "nsIOutputStream.h" #include "nsNetUtil.h" -#include "nsIBufferInputStream.h" #include "nsIInputStream.h" #include "nsIFileStreams.h" #include "nsIStreamListener.h"