mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
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
This commit is contained in:
parent
5b1229a9a8
commit
e05eef45e9
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#define nsURLFetcher_h_
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsFileStream.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<nsIOutputStream> m_outputStream; // this will be obtained from the transport interface
|
||||
nsCOMPtr<nsIInputStream> m_inputStream;
|
||||
|
||||
nsCOMPtr<nsIBufferInputStream> m_channelInputStream;
|
||||
nsCOMPtr<nsIBufferOutputStream> m_channelOutputStream;
|
||||
nsCOMPtr<nsIInputStream> m_channelInputStream;
|
||||
nsCOMPtr<nsIOutputStream> m_channelOutputStream;
|
||||
nsCOMPtr<nsIStreamListener> m_channelListener; // if we are displaying an article this is the rfc-822 display sink...
|
||||
nsCOMPtr<nsISupports> m_channelContext;
|
||||
nsCOMPtr<nsIImapMockChannel> m_mockChannel; // this is the channel we should forward to people
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<nsIPipeObserver> 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<nsIInputStreamObserver> inObs = do_QueryInterface(mEmitter, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mInputStream->SetObserver(inObs);
|
||||
nsCOMPtr<nsIOutputStreamObserver> outObs = do_QueryInterface(mEmitter, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mOutputStream->SetObserver(outObs);
|
||||
}
|
||||
|
||||
// initialize our emitter
|
||||
|
@ -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<nsIBufferOutputStream> mOutputStream; // output stream
|
||||
nsCOMPtr<nsIBufferInputStream> mInputStream;
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream; // output stream
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
|
||||
nsCOMPtr<nsIStreamListener> mOutListener; // output stream listener
|
||||
nsCOMPtr<nsIChannel> mOutgoingChannel;
|
||||
|
@ -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 <nsIMsgNewsFolder> m_newsFolder;
|
||||
nsCOMPtr <nsIMsgWindow> m_msgWindow;
|
||||
|
||||
nsCOMPtr<nsIBufferInputStream> mDisplayInputStream;
|
||||
nsCOMPtr<nsIBufferOutputStream> mDisplayOutputStream;
|
||||
nsCOMPtr<nsIInputStream> mDisplayInputStream;
|
||||
nsCOMPtr<nsIOutputStream> mDisplayOutputStream;
|
||||
nsMsgLineStreamBuffer * m_lineStreamBuffer; // used to efficiently extract lines from the incoming data stream
|
||||
|
||||
// the nsINntpURL that is currently running
|
||||
|
@ -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()
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -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++
|
||||
|
@ -391,7 +391,7 @@ NS_NewAsyncStreamListener(nsIStreamListener **result,
|
||||
|
||||
inline nsresult
|
||||
NS_NewSyncStreamListener(nsIInputStream **inStream,
|
||||
nsIBufferOutputStream **outStream,
|
||||
nsIOutputStream **outStream,
|
||||
nsIStreamListener **listener)
|
||||
{
|
||||
nsresult rv;
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "nsAsyncStreamListener.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -48,9 +48,6 @@ public:
|
||||
// nsISupportsInterface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream interface
|
||||
NS_DECL_NSIBASESTREAM
|
||||
|
||||
// nsIInputStream interface
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -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
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<nsIStreamListener> mListener;
|
||||
nsCOMPtr<nsIInputStream> mSource;
|
||||
nsCOMPtr<nsIBufferInputStream> mBufferInputStream;
|
||||
nsCOMPtr<nsIBufferOutputStream> mBufferOutputStream;
|
||||
nsCOMPtr<nsIInputStream> mInputStream;
|
||||
nsCOMPtr<nsIOutputStream> mOutputStream;
|
||||
|
||||
// writing state variables:
|
||||
nsCOMPtr<nsIStreamObserver> mObserver;
|
||||
|
@ -344,6 +344,41 @@ nsIOService::SetOffline(PRBool offline)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsIOService::ConsumeInput(nsIChannel* channel, nsISupports* context,
|
||||
nsIStreamListener* consumer)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> 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
|
||||
|
||||
|
@ -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<nsIBufferInputStream> 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<nsIBufferInputStream> 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<nsIBufferInputStream> 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<nsIBufferOutputStream> out;
|
||||
nsCOMPtr<nsIBufferInputStream> in;
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
nsCOMPtr<nsIInputStream> 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;
|
||||
|
@ -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<nsISupports> mReadContext;
|
||||
nsCOMPtr<nsIStreamListener> mReadListener;
|
||||
nsCOMPtr<nsIBufferInputStream> mReadPipeIn;
|
||||
nsCOMPtr<nsIBufferOutputStream> mReadPipeOut;
|
||||
nsCOMPtr<nsIInputStream> mReadPipeIn;
|
||||
nsCOMPtr<nsIOutputStream> mReadPipeOut;
|
||||
PRUint32 mReadWriteState;
|
||||
PRInt16 mSelectFlags;
|
||||
nsSocketTransportService* mService;
|
||||
@ -253,8 +255,8 @@ protected:
|
||||
PRUint32 mWriteBufferLength;
|
||||
|
||||
nsCOMPtr<nsIStreamObserver> mWriteObserver;
|
||||
nsCOMPtr<nsIBufferInputStream> mWritePipeIn;
|
||||
nsCOMPtr<nsIBufferOutputStream> mWritePipeOut;
|
||||
nsCOMPtr<nsIInputStream> mWritePipeIn;
|
||||
nsCOMPtr<nsIOutputStream> mWritePipeOut;
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
|
||||
|
@ -27,25 +27,26 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
nsSyncStreamListener::Init(nsIInputStream* *inStr, nsIBufferOutputStream* *outStr)
|
||||
nsSyncStreamListener::Init(nsIInputStream* *inStr, nsIOutputStream* *outStr)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIBufferInputStream* in;
|
||||
nsCOMPtr<nsIInputStream> 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,
|
||||
|
@ -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<nsIOutputStream> mOutputStream;
|
||||
};
|
||||
|
||||
#define NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE (4 * 1024)
|
||||
|
@ -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()
|
||||
|
62
netwerk/cache/memcache/nsMemCacheChannel.cpp
vendored
62
netwerk/cache/memcache/nsMemCacheChannel.cpp
vendored
@ -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<nsIOutputStream> mBaseStream;
|
||||
|
36
netwerk/cache/mgr/nsCacheEntryChannel.cpp
vendored
36
netwerk/cache/mgr/nsCacheEntryChannel.cpp
vendored
@ -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<nsIOutputStream> mOutputStream;
|
||||
nsCOMPtr<nsCachedNetData> mCacheEntry;
|
||||
|
20
netwerk/cache/mgr/nsCachedNetData.cpp
vendored
20
netwerk/cache/mgr/nsCachedNetData.cpp
vendored
@ -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) {
|
||||
|
@ -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<nsIBufferInputStream> bufInStream;
|
||||
nsCOMPtr<nsIBufferOutputStream> bufOutStream;
|
||||
nsCOMPtr<nsIInputStream> bufInStream;
|
||||
nsCOMPtr<nsIOutputStream> bufOutStream;
|
||||
|
||||
rv = NS_NewPipe(getter_AddRefs(bufInStream), getter_AddRefs(bufOutStream));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -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<nsIBufferOutputStream> bufOutStream; // we don't use this piece
|
||||
nsCOMPtr<nsIOutputStream> bufOutStream; // we don't use this piece
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
rv = NS_NewSyncStreamListener(result, getter_AddRefs(bufOutStream),
|
||||
getter_AddRefs(listener));
|
||||
|
@ -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"
|
||||
|
@ -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<nsIInterfaceRequestor> mCallbacks;
|
||||
|
||||
nsCOMPtr<nsIStreamListener> mResponseDataListener;
|
||||
nsCOMPtr<nsIBufferOutputStream> mBufOutputStream;
|
||||
nsCOMPtr<nsIOutputStream> mBufOutputStream;
|
||||
|
||||
PRUint32 mLoadAttributes;
|
||||
|
||||
|
@ -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:
|
||||
|
||||
|
@ -33,7 +33,6 @@ class nsHTTPEncodeStream : public nsIInputStream,
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIBASESTREAM
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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<nsIBufferInputStream> bufferInStream =
|
||||
nsCOMPtr<nsIInputStream> 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()) ) ;
|
||||
|
||||
//
|
||||
|
@ -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:
|
||||
|
@ -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<nsIBufferInputStream> in;
|
||||
nsCOMPtr<nsIBufferOutputStream> out;
|
||||
nsCOMPtr<nsIInputStream> in;
|
||||
nsCOMPtr<nsIOutputStream> 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)) {
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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<nsIInputStream> fileStr;
|
||||
nsIBufferInputStream* bufStr = nsnull;
|
||||
nsIInputStream* bufStr = nsnull;
|
||||
PRUint32 sourceOffset = 0;
|
||||
nsCOMPtr<nsIBufferOutputStream> out;
|
||||
nsCOMPtr<nsIOutputStream> out;
|
||||
nsCOMPtr<nsILocalFile> 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;
|
||||
|
@ -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"
|
||||
|
@ -28,8 +28,6 @@
|
||||
#include <os2.h>
|
||||
#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<nsIBuffer> buf;
|
||||
rv = NS_NewBuffer(&buf, 1024, 4096, nsnull);
|
||||
rv = NS_NewBufferInputStream(&stream, buf);
|
||||
#else
|
||||
nsCOMPtr<nsIBufferOutputStream> out;
|
||||
rv = NS_NewPipe(&stream, getter_AddRefs(out), nsnull,
|
||||
1024, 4096);
|
||||
#endif
|
||||
nsCOMPtr<nsIOutputStream> 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...
|
||||
|
@ -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);
|
||||
|
@ -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)) {
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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'
|
||||
|
@ -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 \
|
||||
|
@ -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 \
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 ()
|
||||
{
|
||||
|
@ -27,9 +27,6 @@ class nsByteArrayInputStream : public nsIByteArrayInputStream
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods
|
||||
NS_DECL_NSIBASESTREAM
|
||||
|
||||
// nsIInputStream methods
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "nsString.h"
|
||||
%}
|
||||
|
||||
#include "nsIOutputStream.idl"
|
||||
#include "nsIInputStream.idl"
|
||||
#include "nsrootidl.idl"
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
|
@ -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 <other-error> - 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);
|
||||
};
|
||||
|
@ -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 <other-error> - 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);
|
||||
};
|
||||
|
@ -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);
|
||||
%}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -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)
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
@ -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<nsIInputStreamObserver> 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<nsIOutputStreamObserver> 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<nsIPipeObserver> 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<nsIPipeObserver> obs = pipe->mObserver;
|
||||
if (mObserver) {
|
||||
nsCOMPtr<nsIInputStreamObserver> 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<nsIPipeObserver> obs = pipe->mObserver;
|
||||
if (mObserver) {
|
||||
nsCOMPtr<nsIInputStreamObserver> 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<nsIBufferOutputStream> kungFuDeathGrip(this);
|
||||
nsCOMPtr<nsIOutputStream> 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<nsIMemory> 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;
|
||||
|
@ -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
|
||||
|
@ -38,9 +38,6 @@ public:
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIBaseStream methods
|
||||
NS_DECL_NSIBASESTREAM
|
||||
|
||||
// nsIScriptableInputStream methods
|
||||
NS_DECL_NSISCRIPTABLEINPUTSTREAM
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -47,7 +47,6 @@ public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTORAGESTREAM
|
||||
NS_DECL_NSIBASESTREAM
|
||||
NS_DECL_NSIOUTPUTSTREAM
|
||||
|
||||
friend class nsStorageInputStream;
|
||||
|
@ -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<nsIBufferInputStream> mIn;
|
||||
nsCOMPtr<nsIBufferOutputStream> mOut;
|
||||
nsCOMPtr<nsIInputStream> mIn;
|
||||
nsCOMPtr<nsIOutputStream> 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");
|
||||
|
@ -88,7 +88,7 @@
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIHTTPHeader.h"
|
||||
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user