Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions | Friends
nsPipe Class Reference
Inheritance diagram for nsPipe:
Inheritance graph
Collaboration diagram for nsPipe:
Collaboration graph

List of all members.

Public Member Functions

void PeekSegment (PRUint32 n, char *&cursor, char *&limit)
nsresult GetReadSegment (const char *&segment, PRUint32 &segmentLen)
void AdvanceReadCursor (PRUint32 count)
nsresult GetWriteSegment (char *&segment, PRUint32 &segmentLen)
void AdvanceWriteCursor (PRUint32 count)
void OnPipeException (nsresult reason, PRBool outputOnly=PR_FALSE)
void init (in boolean nonBlockingInput, in boolean nonBlockingOutput, in unsigned long segmentSize, in unsigned long segmentCount, in nsIMemory segmentAllocator)
 initialize this pipe

Public Attributes

readonly attribute
 The pipe's input end, which also implements nsISearchableInputStream.
readonly attribute
 The pipe's output end.

Protected Attributes

nsPipeInputStream mInput
nsPipeOutputStream mOutput
nsSegmentedBuffer mBuffer
char * mReadCursor
char * mReadLimit
PRInt32 mWriteSegment
char * mWriteCursor
char * mWriteLimit
nsresult mStatus

Private Member Functions

 ~nsPipe ()


class nsPipeInputStream
class nsPipeOutputStream

Detailed Description

Definition at line 216 of file nsPipe3.cpp.

Constructor & Destructor Documentation

Definition at line 313 of file nsPipe3.cpp.

nsPipe::~nsPipe ( ) [private]

Definition at line 326 of file nsPipe3.cpp.

Here is the call graph for this function:

Member Function Documentation

Definition at line 414 of file nsPipe3.cpp.

    NS_ASSERTION(bytesRead, "dont call if no bytes read");

    nsPipeEvents events;
        nsAutoMonitor mon(mMonitor);

        LOG(("III advancing read cursor by %u\n", bytesRead));
        NS_ASSERTION(bytesRead <= mBuffer.GetSegmentSize(), "read too much");

        mReadCursor += bytesRead;
        NS_ASSERTION(mReadCursor <= mReadLimit, "read cursor exceeds limit");


        if (mReadCursor == mReadLimit) {
            // we've reached the limit of how much we can read from this segment.
            // if at the end of this segment, then we must discard this segment.

            // if still writing in this segment then bail because we're not done
            // with the segment and have to wait for now...
            if (mWriteSegment == 0 && mWriteLimit > mWriteCursor) {
                NS_ASSERTION(mReadLimit == mWriteCursor, "unexpected state");

            // shift write segment index (-1 indicates an empty buffer).

            // done with this segment
            LOG(("III deleting first segment\n"));

            if (mWriteSegment == -1) {
                // buffer is completely empty
                mReadCursor = nsnull;
                mReadLimit = nsnull;
                mWriteCursor = nsnull;
                mWriteLimit = nsnull;
            else {
                // advance read cursor and limit to next buffer segment
                mReadCursor = mBuffer.GetSegment(0);
                if (mWriteSegment == 0)
                    mReadLimit = mWriteCursor;
                    mReadLimit = mReadCursor + mBuffer.GetSegmentSize();

            // we've free'd up a segment, so notify output stream that pipe has
            // room for a new segment.
            if (mOutput.OnOutputWritable(events))

Here is the call graph for this function:

Definition at line 512 of file nsPipe3.cpp.

    NS_ASSERTION(bytesWritten, "dont call if no bytes written");

    nsPipeEvents events;
        nsAutoMonitor mon(mMonitor);

        LOG(("OOO advancing write cursor by %u\n", bytesWritten));

        char *newWriteCursor = mWriteCursor + bytesWritten;
        NS_ASSERTION(newWriteCursor <= mWriteLimit, "write cursor exceeds limit");

        // update read limit if reading in the same segment
        if (mWriteSegment == 0 && mReadLimit == mWriteCursor)
            mReadLimit = newWriteCursor;

        mWriteCursor = newWriteCursor;

        NS_ASSERTION(mReadCursor != mWriteCursor, "read cursor is bad");

        // update the writable flag on the output stream
        if (mWriteCursor == mWriteLimit) {
            if (mBuffer.GetSize() >= mBuffer.GetMaxSize())

        // notify input stream that pipe now contains additional data
        if (mInput.OnInputReadable(bytesWritten, events))

Here is the call graph for this function:

nsresult nsPipe::GetReadSegment ( const char *&  segment,
PRUint32 segmentLen 

Definition at line 401 of file nsPipe3.cpp.

    nsAutoMonitor mon(mMonitor);

    if (mReadCursor == mReadLimit)
        return NS_FAILED(mStatus) ? mStatus : NS_BASE_STREAM_WOULD_BLOCK;

    segment    = mReadCursor;
    segmentLen = mReadLimit - mReadCursor;
    return NS_OK;
nsresult nsPipe::GetWriteSegment ( char *&  segment,
PRUint32 segmentLen 

Definition at line 473 of file nsPipe3.cpp.

    nsAutoMonitor mon(mMonitor);

    if (NS_FAILED(mStatus))
        return mStatus;

    // write cursor and limit may both be null indicating an empty buffer.
    if (mWriteCursor == mWriteLimit) {
        char *seg = mBuffer.AppendNewSegment();
        // pipe is full
        if (seg == nsnull)
            return NS_BASE_STREAM_WOULD_BLOCK;
        LOG(("OOO appended new segment\n"));
        mWriteCursor = seg;
        mWriteLimit = mWriteCursor + mBuffer.GetSegmentSize();

    // make sure read cursor is initialized
    if (mReadCursor == nsnull) {
        NS_ASSERTION(mWriteSegment == 0, "unexpected null read cursor");
        mReadCursor = mReadLimit = mWriteCursor;

    // check to see if we can roll-back our read and write cursors to the 
    // beginning of the current/first segment.  this is purely an optimization.
    if (mReadCursor == mWriteCursor && mWriteSegment == 0) {
        char *head = mBuffer.GetSegment(0);
        LOG(("OOO rolling back write cursor %u bytes\n", mWriteCursor - head));
        mWriteCursor = mReadCursor = mReadLimit = head;

    segment    = mWriteCursor;
    segmentLen = mWriteLimit - mWriteCursor;
    return NS_OK;

Here is the call graph for this function:

void nsIPipe::init ( in boolean  nonBlockingInput,
in boolean  nonBlockingOutput,
in unsigned long  segmentSize,
in unsigned long  segmentCount,
in nsIMemory  segmentAllocator 
) [inherited]

initialize this pipe

void nsPipe::OnPipeException ( nsresult  reason,
PRBool  outputOnly = PR_FALSE 

Definition at line 546 of file nsPipe3.cpp.

    LOG(("PPP nsPipe::OnPipeException [reason=%x output-only=%d]\n",
        reason, outputOnly));

    nsPipeEvents events;
        nsAutoMonitor mon(mMonitor);

        // if we've already hit an exception, then ignore this one.
        if (NS_FAILED(mStatus))

        mStatus = reason;

        // an output-only exception applies to the input end if the pipe has
        // zero bytes available.
        if (outputOnly && !mInput.Available())
            outputOnly = PR_FALSE;

        if (!outputOnly)
            if (mInput.OnInputException(reason, events))

        if (mOutput.OnOutputException(reason, events))

Here is the call graph for this function:

Here is the caller graph for this function:

void nsPipe::PeekSegment ( PRUint32  n,
char *&  cursor,
char *&  limit 

Definition at line 379 of file nsPipe3.cpp.

    if (index == 0) {
        NS_ASSERTION(!mReadCursor || mBuffer.GetSegmentCount(), "unexpected state");
        cursor = mReadCursor;
        limit = mReadLimit;
    else {
        PRUint32 numSegments = mBuffer.GetSegmentCount();
        if (index >= numSegments)
            cursor = limit = nsnull;
        else {
            cursor = mBuffer.GetSegment(index);
            if (mWriteSegment == (PRInt32) index)
                limit = mWriteCursor;
                limit = cursor + mBuffer.GetSegmentSize();

Here is the call graph for this function:

Friends And Related Function Documentation

friend class nsPipeInputStream [friend]

Definition at line 219 of file nsPipe3.cpp.

friend class nsPipeOutputStream [friend]

Definition at line 220 of file nsPipe3.cpp.

Member Data Documentation

The pipe's input end, which also implements nsISearchableInputStream.

Definition at line 86 of file nsIPipe.idl.

Definition at line 258 of file nsPipe3.cpp.

Definition at line 254 of file nsPipe3.cpp.

Definition at line 257 of file nsPipe3.cpp.

Definition at line 255 of file nsPipe3.cpp.

char* nsPipe::mReadCursor [protected]

Definition at line 260 of file nsPipe3.cpp.

char* nsPipe::mReadLimit [protected]

Definition at line 261 of file nsPipe3.cpp.

Definition at line 267 of file nsPipe3.cpp.

char* nsPipe::mWriteCursor [protected]

Definition at line 264 of file nsPipe3.cpp.

char* nsPipe::mWriteLimit [protected]

Definition at line 265 of file nsPipe3.cpp.

Definition at line 263 of file nsPipe3.cpp.

The pipe's output end.

Definition at line 91 of file nsIPipe.idl.

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