зеркало из https://github.com/mozilla/gecko-dev.git
Added Write(nsIInputStream) and Flush to nsIOutputStream.
This commit is contained in:
Родитель
0f30442aa1
Коммит
c289c670cd
|
@ -42,25 +42,6 @@ public:
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX regenerate:
|
||||
#define NS_IBYTEBUFFEROUTPUTSTREAM_IID \
|
||||
{ /* 924df6d0-f192-11d2-9322-000000000000 */ \
|
||||
0x924df6d0, \
|
||||
0xf192, \
|
||||
0x11d2, \
|
||||
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
|
||||
}
|
||||
|
||||
class nsIByteBufferOutputStream : public nsIOutputStream {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBYTEBUFFEROUTPUTSTREAM_IID);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewByteBufferInputStream(nsIByteBufferInputStream* *result,
|
||||
PRBool blocking = PR_FALSE,
|
||||
|
|
|
@ -101,8 +101,6 @@ class nsIFileOutputStream
|
|||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; }
|
||||
NS_IMETHOD Flush() = 0;
|
||||
// Forces a write to disk.
|
||||
}; // class nsIFileOutputStream
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
|
|
@ -24,7 +24,7 @@ class nsByteBufferInputStream;
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsByteBufferOutputStream : public nsIByteBufferOutputStream
|
||||
class nsByteBufferOutputStream : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -34,9 +34,8 @@ public:
|
|||
|
||||
// nsIOutputStream methods:
|
||||
NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsIByteBufferOutputStream methods:
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Flush(void);
|
||||
|
||||
// nsByteBufferOutputStream methods:
|
||||
nsByteBufferOutputStream(nsByteBufferInputStream* in);
|
||||
|
@ -71,7 +70,8 @@ public:
|
|||
friend class nsByteBufferOutputStream;
|
||||
|
||||
nsresult Init(void);
|
||||
void SetEOF(void);
|
||||
nsresult SetEOF(void);
|
||||
nsresult Drain(void);
|
||||
|
||||
PRBool AtEOF() { return mEOF && (mReadCursor == mWriteCursor) && !mFull; }
|
||||
|
||||
|
@ -101,8 +101,8 @@ public:
|
|||
PRInt32 amt = PR_MIN(max, diff);
|
||||
if (amt > 0) {
|
||||
nsCRT::memcpy(toBuf, &mBuffer[mReadCursor], amt);
|
||||
#ifdef NS_DEBUG
|
||||
nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt);
|
||||
#ifdef DEBUG_warren
|
||||
// nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt);
|
||||
#endif
|
||||
mReadCursor += amt;
|
||||
*totalRef += amt;
|
||||
|
@ -243,14 +243,17 @@ nsByteBufferInputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::Close(void)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
mClosed = PR_TRUE;
|
||||
if (mBlocking) {
|
||||
PR_CNotify(this); // wake up the writer
|
||||
PRStatus status = PR_CNotify(this); // wake up the writer
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -281,7 +284,7 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
|||
PR_CEnterMonitor(this);
|
||||
*aReadCount = 0;
|
||||
|
||||
/*while (aCount > 0)*/ { // XXX should this block trying to fill the buffer, or return ASAP?
|
||||
/*while (aCount > 0)*/ {
|
||||
if (ReadableAmount() == 0) {
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
@ -325,8 +328,11 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
|||
if (*aReadCount)
|
||||
mFull = PR_FALSE;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CNotify(this); // tell the writer there's space
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // tell the writer there's space
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (mBlocking)
|
||||
|
@ -401,8 +407,11 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount)
|
|||
if (mWriteCursor == mReadCursor)
|
||||
mFull = PR_TRUE;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CNotify(this); // tell the reader there's more
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // tell the reader there's more
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (mBlocking)
|
||||
|
@ -410,16 +419,46 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsByteBufferInputStream::SetEOF()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
mEOF = PR_TRUE;
|
||||
if (mBlocking) {
|
||||
PR_CNotify(this); // wake up the reader
|
||||
PRStatus status = PR_CNotify(this); // wake up the reader
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsByteBufferInputStream::Drain()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking) {
|
||||
PR_CEnterMonitor(this);
|
||||
while (ReadableAmount() != 0) {
|
||||
PRStatus status = PR_CNotify(this); // wake up the reader
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// wait for the reader to take all the data
|
||||
status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -447,8 +486,7 @@ nsByteBufferOutputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIByteBufferOutputStream::GetIID()) ||
|
||||
aIID.Equals(nsIOutputStream::GetIID()) ||
|
||||
if (aIID.Equals(nsIOutputStream::GetIID()) ||
|
||||
aIID.Equals(nsIBaseStream::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
|
@ -477,6 +515,12 @@ nsByteBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCoun
|
|||
return mInputStream->Fill(fromStream, aWriteCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::Flush(void)
|
||||
{
|
||||
return mInputStream->Drain();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
|
|
|
@ -154,6 +154,10 @@ class FileImpl
|
|||
*aWriteCount = bytesWrit;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Flush();
|
||||
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "nsIBaseStream.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
/* 7f13b870-e95f-11d1-beae-00805f8a66dc */
|
||||
#define NS_IOUTPUTSTREAM_IID \
|
||||
{ 0x7f13b870, 0xe95f, 0x11d1, \
|
||||
|
@ -42,6 +44,29 @@ public:
|
|||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
/**
|
||||
* Writes data into the stream from an input stream.
|
||||
* Implementer's note: This method is defined by this interface in order
|
||||
* to allow the output stream to efficiently copy the data from the input
|
||||
* stream into its internal buffer (if any). If this method was provide
|
||||
* as an external facility, a separate char* buffer would need to be used
|
||||
* in order to call the output stream's other Write method.
|
||||
* @param fromStream the stream from which the data is read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
* is undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
/**
|
||||
* Flushes the stream.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Flush(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
|
@ -110,6 +110,10 @@ class BasicStringImpl
|
|||
*aWriteCount = bytesWrit;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
public:
|
||||
|
||||
// nsISupports interface
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "nsIThread.h"
|
||||
#include "nsIByteBufferInputStream.h"
|
||||
#include "prprf.h"
|
||||
#include "prinrval.h"
|
||||
#include "plstr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -34,22 +35,26 @@ public:
|
|||
nsresult rv;
|
||||
char buf[101];
|
||||
PRUint32 count;
|
||||
PRIntervalTime start = PR_IntervalNow();
|
||||
while (PR_TRUE) {
|
||||
rv = mIn->Read(buf, 100, &count);
|
||||
if (rv == NS_BASE_STREAM_EOF) {
|
||||
printf("EOF count = %d\n", mCount);
|
||||
return NS_OK;
|
||||
// printf("EOF count = %d\n", mCount);
|
||||
rv = NS_OK;
|
||||
break;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("read failed\n");
|
||||
return rv;
|
||||
break;
|
||||
}
|
||||
|
||||
buf[count] = '\0';
|
||||
printf(buf);
|
||||
// printf(buf);
|
||||
|
||||
mCount += count;
|
||||
}
|
||||
PRIntervalTime end = PR_IntervalNow();
|
||||
printf("read time = %dms\n", PR_IntervalToMilliseconds(end - start));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -83,6 +88,7 @@ main()
|
|||
rv = NS_NewThread(&receiver, new nsReceiver(in));
|
||||
NS_RELEASE(in);
|
||||
|
||||
PRIntervalTime start = PR_IntervalNow();
|
||||
for (PRUint32 i = 0; i < ITERATIONS; i++) {
|
||||
PRUint32 writeCount;
|
||||
char* buf = PR_smprintf("%d %s", i, kTestPattern);
|
||||
|
@ -92,9 +98,11 @@ main()
|
|||
}
|
||||
rv = out->Close();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "close failed");
|
||||
PRIntervalTime end = PR_IntervalNow();
|
||||
|
||||
receiver->Join();
|
||||
NS_RELEASE(receiver);
|
||||
|
||||
printf("write time = %dms\n", PR_IntervalToMilliseconds(end - start));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -447,6 +447,15 @@ public:
|
|||
fflush(stdout);
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Flush()
|
||||
{
|
||||
fflush(stdout);
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ADDREF(ConsoleOutput)
|
||||
|
|
|
@ -55,6 +55,13 @@ public:
|
|||
NS_IMETHOD Write(const char *aBuf,
|
||||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Flush(void) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIBaseStream interface
|
||||
NS_IMETHOD Close(void);
|
||||
|
|
|
@ -216,6 +216,14 @@ public:
|
|||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Specific methods to nsIPluginManagerStream.
|
||||
|
|
|
@ -158,6 +158,14 @@ public:
|
|||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
|
|
|
@ -158,6 +158,14 @@ public:
|
|||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
NS_IMETHOD
|
||||
|
|
|
@ -216,6 +216,14 @@ public:
|
|||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Specific methods to nsIPluginManagerStream.
|
||||
|
|
|
@ -674,8 +674,15 @@ public:
|
|||
* @return number of bytes read or an error if < 0
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount,
|
||||
PRInt32 *resultingCount);
|
||||
Write(const char* aBuf, PRInt32 aCount, PRInt32 *resultingCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsPluginManagerStream specific methods:
|
||||
|
|
|
@ -41,8 +41,15 @@ public:
|
|||
* @return number of bytes read or an error if < 0
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRInt32 aOffset, PRInt32 aCount,
|
||||
PRInt32 *resultingCount);
|
||||
Write(const char* aBuf, PRInt32 aCount, PRInt32 *resultingCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// nsPluginManagerStream specific methods:
|
||||
|
|
|
@ -48,6 +48,13 @@ public:
|
|||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIBaseStream interface
|
||||
|
||||
|
|
|
@ -112,6 +112,14 @@ public:
|
|||
PRUint32 aLen,
|
||||
PRUint32 *aWriteCount);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~nsBufferedStream();
|
||||
|
||||
|
@ -148,6 +156,14 @@ public:
|
|||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~nsAsyncStream();
|
||||
|
||||
|
@ -186,6 +202,14 @@ public:
|
|||
PRUint32 aLen,
|
||||
PRUint32 *aWriteLength);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual ~nsBlockingStream();
|
||||
|
||||
|
|
|
@ -23,11 +23,8 @@
|
|||
#include "nscore.h"
|
||||
|
||||
/* forward declaration */
|
||||
class nsIInputStream;
|
||||
class nsString;
|
||||
class nsIURL;
|
||||
|
||||
|
||||
/* 97566110-ff60-11d1-beb9-00805f8a66dc */
|
||||
#define NS_ISTREAMOBSERVER_IID \
|
||||
{ 0x97566110, 0xff60, 0x11d1, \
|
||||
|
|
|
@ -146,6 +146,15 @@ public:
|
|||
*aWriteCount = aCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) {
|
||||
PR_Sync(PR_GetSpecialFD(PR_StandardOutput));
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, kIOutputStreamIID);
|
||||
|
|
|
@ -136,6 +136,16 @@ public:
|
|||
*aWriteCount = aCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush() {
|
||||
PR_Sync(PR_GetSpecialFD(PR_StandardOutput));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(ConsoleOutputStreamImpl, kIOutputStreamIID);
|
||||
|
|
|
@ -24,7 +24,7 @@ class nsByteBufferInputStream;
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsByteBufferOutputStream : public nsIByteBufferOutputStream
|
||||
class nsByteBufferOutputStream : public nsIOutputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -34,9 +34,8 @@ public:
|
|||
|
||||
// nsIOutputStream methods:
|
||||
NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
|
||||
|
||||
// nsIByteBufferOutputStream methods:
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount);
|
||||
NS_IMETHOD Flush(void);
|
||||
|
||||
// nsByteBufferOutputStream methods:
|
||||
nsByteBufferOutputStream(nsByteBufferInputStream* in);
|
||||
|
@ -71,7 +70,8 @@ public:
|
|||
friend class nsByteBufferOutputStream;
|
||||
|
||||
nsresult Init(void);
|
||||
void SetEOF(void);
|
||||
nsresult SetEOF(void);
|
||||
nsresult Drain(void);
|
||||
|
||||
PRBool AtEOF() { return mEOF && (mReadCursor == mWriteCursor) && !mFull; }
|
||||
|
||||
|
@ -101,8 +101,8 @@ public:
|
|||
PRInt32 amt = PR_MIN(max, diff);
|
||||
if (amt > 0) {
|
||||
nsCRT::memcpy(toBuf, &mBuffer[mReadCursor], amt);
|
||||
#ifdef NS_DEBUG
|
||||
nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt);
|
||||
#ifdef DEBUG_warren
|
||||
// nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt);
|
||||
#endif
|
||||
mReadCursor += amt;
|
||||
*totalRef += amt;
|
||||
|
@ -243,14 +243,17 @@ nsByteBufferInputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_IMETHODIMP
|
||||
nsByteBufferInputStream::Close(void)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
mClosed = PR_TRUE;
|
||||
if (mBlocking) {
|
||||
PR_CNotify(this); // wake up the writer
|
||||
PRStatus status = PR_CNotify(this); // wake up the writer
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -281,7 +284,7 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
|||
PR_CEnterMonitor(this);
|
||||
*aReadCount = 0;
|
||||
|
||||
/*while (aCount > 0)*/ { // XXX should this block trying to fill the buffer, or return ASAP?
|
||||
/*while (aCount > 0)*/ {
|
||||
if (ReadableAmount() == 0) {
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
@ -325,8 +328,11 @@ nsByteBufferInputStream::Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount)
|
|||
if (*aReadCount)
|
||||
mFull = PR_FALSE;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CNotify(this); // tell the writer there's space
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // tell the writer there's space
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (mBlocking)
|
||||
|
@ -401,8 +407,11 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount)
|
|||
if (mWriteCursor == mReadCursor)
|
||||
mFull = PR_TRUE;
|
||||
|
||||
if (mBlocking)
|
||||
PR_CNotify(this); // tell the reader there's more
|
||||
if (mBlocking) {
|
||||
PRStatus status = PR_CNotify(this); // tell the reader there's more
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (mBlocking)
|
||||
|
@ -410,16 +419,46 @@ nsByteBufferInputStream::Fill(nsIInputStream* stream, PRUint32 *aWriteCount)
|
|||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsresult
|
||||
nsByteBufferInputStream::SetEOF()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking)
|
||||
PR_CEnterMonitor(this);
|
||||
mEOF = PR_TRUE;
|
||||
if (mBlocking) {
|
||||
PR_CNotify(this); // wake up the reader
|
||||
PRStatus status = PR_CNotify(this); // wake up the reader
|
||||
if (status != PR_SUCCESS)
|
||||
rv = NS_ERROR_FAILURE;
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsByteBufferInputStream::Drain()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mBlocking) {
|
||||
PR_CEnterMonitor(this);
|
||||
while (ReadableAmount() != 0) {
|
||||
PRStatus status = PR_CNotify(this); // wake up the reader
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
// wait for the reader to take all the data
|
||||
status = PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
if (status != PR_SUCCESS) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -447,8 +486,7 @@ nsByteBufferOutputStream::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
{
|
||||
if (aInstancePtr == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(nsIByteBufferOutputStream::GetIID()) ||
|
||||
aIID.Equals(nsIOutputStream::GetIID()) ||
|
||||
if (aIID.Equals(nsIOutputStream::GetIID()) ||
|
||||
aIID.Equals(nsIBaseStream::GetIID()) ||
|
||||
aIID.Equals(nsISupports::GetIID())) {
|
||||
*aInstancePtr = this;
|
||||
|
@ -477,6 +515,12 @@ nsByteBufferOutputStream::Write(nsIInputStream* fromStream, PRUint32 *aWriteCoun
|
|||
return mInputStream->Fill(fromStream, aWriteCount);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsByteBufferOutputStream::Flush(void)
|
||||
{
|
||||
return mInputStream->Drain();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_BASE nsresult
|
||||
|
|
|
@ -42,25 +42,6 @@ public:
|
|||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX regenerate:
|
||||
#define NS_IBYTEBUFFEROUTPUTSTREAM_IID \
|
||||
{ /* 924df6d0-f192-11d2-9322-000000000000 */ \
|
||||
0x924df6d0, \
|
||||
0xf192, \
|
||||
0x11d2, \
|
||||
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
|
||||
}
|
||||
|
||||
class nsIByteBufferOutputStream : public nsIOutputStream {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IBYTEBUFFEROUTPUTSTREAM_IID);
|
||||
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
extern NS_BASE nsresult
|
||||
NS_NewByteBufferInputStream(nsIByteBufferInputStream* *result,
|
||||
PRBool blocking = PR_FALSE,
|
||||
|
|
|
@ -154,6 +154,10 @@ class FileImpl
|
|||
*aWriteCount = bytesWrit;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHOD Flush();
|
||||
|
||||
NS_IMETHOD GetAtEOF(PRBool* outAtEOF)
|
||||
|
|
|
@ -101,8 +101,6 @@ class nsIFileOutputStream
|
|||
{
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IFILEOUTPUTSTREAM_IID; return iid; }
|
||||
NS_IMETHOD Flush() = 0;
|
||||
// Forces a write to disk.
|
||||
}; // class nsIFileOutputStream
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "nsIBaseStream.h"
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
/* 7f13b870-e95f-11d1-beae-00805f8a66dc */
|
||||
#define NS_IOUTPUTSTREAM_IID \
|
||||
{ 0x7f13b870, 0xe95f, 0x11d1, \
|
||||
|
@ -42,6 +44,29 @@ public:
|
|||
*/
|
||||
NS_IMETHOD
|
||||
Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
/**
|
||||
* Writes data into the stream from an input stream.
|
||||
* Implementer's note: This method is defined by this interface in order
|
||||
* to allow the output stream to efficiently copy the data from the input
|
||||
* stream into its internal buffer (if any). If this method was provide
|
||||
* as an external facility, a separate char* buffer would need to be used
|
||||
* in order to call the output stream's other Write method.
|
||||
* @param fromStream the stream from which the data is read
|
||||
* @param aWriteCount out parameter to hold the number of
|
||||
* bytes written. if an error occurs, the writecount
|
||||
* is undefined
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Write(nsIInputStream* fromStream, PRUint32 *aWriteCount) = 0;
|
||||
|
||||
/**
|
||||
* Flushes the stream.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Flush(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
|
@ -110,6 +110,10 @@ class BasicStringImpl
|
|||
*aWriteCount = bytesWrit;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
public:
|
||||
|
||||
// nsISupports interface
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "nsIThread.h"
|
||||
#include "nsIByteBufferInputStream.h"
|
||||
#include "prprf.h"
|
||||
#include "prinrval.h"
|
||||
#include "plstr.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
@ -34,22 +35,26 @@ public:
|
|||
nsresult rv;
|
||||
char buf[101];
|
||||
PRUint32 count;
|
||||
PRIntervalTime start = PR_IntervalNow();
|
||||
while (PR_TRUE) {
|
||||
rv = mIn->Read(buf, 100, &count);
|
||||
if (rv == NS_BASE_STREAM_EOF) {
|
||||
printf("EOF count = %d\n", mCount);
|
||||
return NS_OK;
|
||||
// printf("EOF count = %d\n", mCount);
|
||||
rv = NS_OK;
|
||||
break;
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
printf("read failed\n");
|
||||
return rv;
|
||||
break;
|
||||
}
|
||||
|
||||
buf[count] = '\0';
|
||||
printf(buf);
|
||||
// printf(buf);
|
||||
|
||||
mCount += count;
|
||||
}
|
||||
PRIntervalTime end = PR_IntervalNow();
|
||||
printf("read time = %dms\n", PR_IntervalToMilliseconds(end - start));
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -83,6 +88,7 @@ main()
|
|||
rv = NS_NewThread(&receiver, new nsReceiver(in));
|
||||
NS_RELEASE(in);
|
||||
|
||||
PRIntervalTime start = PR_IntervalNow();
|
||||
for (PRUint32 i = 0; i < ITERATIONS; i++) {
|
||||
PRUint32 writeCount;
|
||||
char* buf = PR_smprintf("%d %s", i, kTestPattern);
|
||||
|
@ -92,9 +98,11 @@ main()
|
|||
}
|
||||
rv = out->Close();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "close failed");
|
||||
PRIntervalTime end = PR_IntervalNow();
|
||||
|
||||
receiver->Join();
|
||||
NS_RELEASE(receiver);
|
||||
|
||||
printf("write time = %dms\n", PR_IntervalToMilliseconds(end - start));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class nsWidgetListener : public nsIWidgetController,
|
|||
{
|
||||
public:
|
||||
nsWidgetListener();
|
||||
NS_IMETHOD ProcessEvent(class nsIDOMEvent *) { return NS_OK; }
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -72,4 +73,4 @@ protected:
|
|||
nsresult AddEventListener(nsISupports* aNode, const nsIID& aInterfaceIID);
|
||||
};
|
||||
|
||||
#endif /* nsWidgetListener_h__ */
|
||||
#endif /* nsWidgetListener_h__ */
|
||||
|
|
Загрузка…
Ссылка в новой задаче