Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
nsInputStreamTee Class Reference
Inheritance diagram for nsInputStreamTee:
Inheritance graph
[legend]
Collaboration diagram for nsInputStreamTee:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIINPUTSTREAMTEE 
nsInputStreamTee ()
void close ()
 Close the stream.
unsigned long available ()
unsigned long read (in charPtr aBuf, in unsigned long aCount)
 Read data from the stream.
unsigned long readSegments (in nsWriteSegmentFun aWriter, in voidPtr aClosure, in unsigned long aCount)
 Low-level read method that has access to the stream's underlying buffer.
boolean isNonBlocking ()

Public Attributes

attribute nsIInputStream source
attribute nsIOutputStream sink

Private Member Functions

 ~nsInputStreamTee ()
nsresult TeeSegment (const char *buf, PRUint32 count)

Static Private Member Functions

static NS_METHOD WriteSegmentFun (nsIInputStream *, void *, const char *, PRUint32, PRUint32, PRUint32 *)

Private Attributes

nsCOMPtr< nsIInputStreammSource
nsCOMPtr< nsIOutputStreammSink
nsWriteSegmentFun mWriter
voidmClosure

Detailed Description

Definition at line 44 of file nsInputStreamTee.cpp.


Constructor & Destructor Documentation

Definition at line 68 of file nsInputStreamTee.cpp.

{
}
nsInputStreamTee::~nsInputStreamTee ( ) [inline, private]

Definition at line 54 of file nsInputStreamTee.cpp.

{}

Member Function Documentation

unsigned long nsIInputStream::available ( ) [inherited]
Returns:
number of bytes currently available in the stream
void nsIInputStream::close ( ) [inherited]

Close the stream.

Returns:
true if stream is non-blocking
unsigned long nsIInputStream::read ( in charPtr  aBuf,
in unsigned long  aCount 
) [inherited]

Read data from the stream.

Parameters:
aBufthe buffer into which the data is to be read
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount).
0 if reached end of file
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure
unsigned long nsIInputStream::readSegments ( in nsWriteSegmentFun  aWriter,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

Low-level read method that has access to the stream's underlying buffer.

The writer function may be called multiple times for segmented buffers. ReadSegments is expected to keep calling the writer until either there is nothing left to read or the writer returns an error. ReadSegments should not call the writer with zero bytes to consume.

Parameters:
aWriterthe "consumer" of the data to be read
aClosureopaque parameter passed to writer
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount)
0 if reached end of file (or if aWriter refused to consume data)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: this function may be unimplemented if a stream has no underlying buffer (e.g., socket input stream).

nsresult nsInputStreamTee::TeeSegment ( const char *  buf,
PRUint32  count 
) [private]

Definition at line 73 of file nsInputStreamTee.cpp.

{
    if (!mSink)
        return NS_OK; // nothing to do
    nsresult rv;
    PRUint32 bytesWritten = 0;
    while (count) {
        rv = mSink->Write(buf + bytesWritten, count, &bytesWritten);
        if (NS_FAILED(rv)) {
            // ok, this is not a fatal error... just drop our reference to mSink
            // and continue on as if nothing happened.
            NS_WARNING("Write failed (non-fatal)");
            // catch possible misuse of the input stream tee
            NS_ASSERTION(rv != NS_BASE_STREAM_WOULD_BLOCK, "sink must be a blocking stream");
            mSink = 0;
            break;
        }
        NS_ASSERTION(bytesWritten <= count, "wrote too much");
        count -= bytesWritten;
    }
    return NS_OK;
}

Here is the caller graph for this function:

NS_METHOD nsInputStreamTee::WriteSegmentFun ( nsIInputStream in,
void closure,
const char *  fromSegment,
PRUint32  offset,
PRUint32  count,
PRUint32 writeCount 
) [static, private]

Definition at line 97 of file nsInputStreamTee.cpp.

{
    nsInputStreamTee *tee = NS_REINTERPRET_CAST(nsInputStreamTee *, closure);

    nsresult rv = tee->mWriter(in, tee->mClosure, fromSegment, offset, count, writeCount);
    if (NS_FAILED(rv) || (*writeCount == 0)) {
        NS_ASSERTION((NS_FAILED(rv) ? (*writeCount == 0) : PR_TRUE),
                "writer returned an error with non-zero writeCount");
        return rv;
    }

    return tee->TeeSegment(fromSegment, *writeCount);
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 65 of file nsInputStreamTee.cpp.

Definition at line 63 of file nsInputStreamTee.cpp.

Definition at line 62 of file nsInputStreamTee.cpp.

Definition at line 64 of file nsInputStreamTee.cpp.

Definition at line 52 of file nsIInputStreamTee.idl.

Definition at line 51 of file nsIInputStreamTee.idl.


The documentation for this class was generated from the following file: