Back to index

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

List of all members.

Classes

struct  WriteSegmentsState

Public Member Functions

 nsStreamCopierOB ()
virtual ~nsStreamCopierOB ()
PRUint32 DoCopy (nsresult *sourceCondition, nsresult *sinkCondition)
nsresult Start (nsIInputStream *source, nsIOutputStream *sink, nsIEventTarget *target, nsAsyncCopyCallbackFun callback, void *closure, PRUint32 chunksize)
void Process ()
NS_IMETHOD OnInputStreamReady (nsIAsyncInputStream *source)
NS_IMETHOD OnOutputStreamReady (nsIAsyncOutputStream *sink)
 PR_STATIC_CALLBACK (void *) HandleContinuationEvent(PLEvent *event)
 PR_STATIC_CALLBACK (void) DestroyContinuationEvent(PLEvent *event)
nsresult PostContinuationEvent ()
nsresult PostContinuationEvent_Locked ()
void onInputStreamReady (in nsIAsyncInputStream aStream)
 Called to indicate that the stream is either readable or closed.
void onOutputStreamReady (in nsIAsyncOutputStream aStream)
 Called to indicate that the stream is either writable or closed.

Static Public Member Functions

static NS_METHOD FillOutputBuffer (nsIOutputStream *outStr, void *closure, char *buffer, PRUint32 offset, PRUint32 count, PRUint32 *countRead)

Protected Attributes

nsCOMPtr< nsIInputStreammSource
nsCOMPtr< nsIOutputStreammSink
nsCOMPtr< nsIAsyncInputStreammAsyncSource
nsCOMPtr< nsIAsyncOutputStreammAsyncSink
nsCOMPtr< nsIEventTargetmTarget
PRLockmLock
nsAsyncCopyCallbackFun mCallback
voidmClosure
PRUint32 mChunkSize
PRPackedBool mEventInProcess
PRPackedBool mEventIsPending

Detailed Description

Definition at line 512 of file nsStreamUtils.cpp.


Class Documentation

struct nsStreamCopierOB::WriteSegmentsState

Definition at line 518 of file nsStreamUtils.cpp.

Collaboration diagram for nsStreamCopierOB::WriteSegmentsState:
Class Members
nsIInputStream * mSource
nsresult mSourceCondition

Constructor & Destructor Documentation

Definition at line 515 of file nsStreamUtils.cpp.

virtual nsStreamCopierOB::~nsStreamCopierOB ( ) [inline, virtual]

Definition at line 516 of file nsStreamUtils.cpp.

{}

Member Function Documentation

PRUint32 nsStreamCopierOB::DoCopy ( nsresult sourceCondition,
nsresult sinkCondition 
) [inline, virtual]

Implements nsAStreamCopier.

Definition at line 541 of file nsStreamUtils.cpp.

    {
        WriteSegmentsState state;
        state.mSource = mSource;
        state.mSourceCondition = NS_OK;

        PRUint32 n;
        *sinkCondition =
            mSink->WriteSegments(FillOutputBuffer, &state, mChunkSize, &n);
        *sourceCondition = state.mSourceCondition;
        return n;
    }

Here is the call graph for this function:

static NS_METHOD nsStreamCopierOB::FillOutputBuffer ( nsIOutputStream outStr,
void closure,
char *  buffer,
PRUint32  offset,
PRUint32  count,
PRUint32 countRead 
) [inline, static]

Definition at line 523 of file nsStreamUtils.cpp.

    {
        WriteSegmentsState *state = (WriteSegmentsState *) closure;

        nsresult rv = state->mSource->Read(buffer, count, countRead);
        if (NS_FAILED(rv))
            state->mSourceCondition = rv;
        else if (*countRead == 0)
            state->mSourceCondition = NS_BASE_STREAM_CLOSED;

        return state->mSourceCondition;
    }

Here is the caller graph for this function:

Called to indicate that the stream is either readable or closed.

Parameters:
aStreamThe stream whose asyncWait method was called.

Definition at line 377 of file nsStreamUtils.cpp.

    {
        PostContinuationEvent();
        return NS_OK;
    }

Here is the call graph for this function:

Called to indicate that the stream is either writable or closed.

Parameters:
aStreamThe stream whose asyncWait method was called.

Definition at line 383 of file nsStreamUtils.cpp.

    {
        PostContinuationEvent();
        return NS_OK;
    }

Here is the call graph for this function:

Definition at line 411 of file nsStreamUtils.cpp.

    {
        // we cannot post a continuation event if there is currently
        // an event in process.  doing so could result in Process being
        // run simultaneously on multiple threads, so we mark the event
        // as pending, and if an event is already in process then we 
        // just let that existing event take care of posting the real
        // continuation event.

        nsAutoLock lock(mLock);
        return PostContinuationEvent_Locked();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 424 of file nsStreamUtils.cpp.

    {
        nsresult rv = NS_OK;
        if (mEventInProcess)
            mEventIsPending = PR_TRUE;
        else {
            PLEvent *event = new PLEvent;
            if (!event)
                rv = NS_ERROR_OUT_OF_MEMORY;
            else {
                NS_ADDREF_THIS();
                PL_InitEvent(event, this,
                             HandleContinuationEvent,
                             DestroyContinuationEvent);

                rv = mTarget->PostEvent(event);
                if (NS_SUCCEEDED(rv))
                    mEventInProcess = PR_TRUE;
                else {
                    NS_ERROR("unable to post continuation event");
                    PL_DestroyEvent(event);
                }
            }
        }
        return rv;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

nsAStreamCopier::PR_STATIC_CALLBACK ( void ) [inline, inherited]

Definition at line 389 of file nsStreamUtils.cpp.

    {
        nsAStreamCopier *self = (nsAStreamCopier *) event->owner;
        self->Process();

        // clear "in process" flag and post any pending continuation event
        nsAutoLock lock(self->mLock);
        self->mEventInProcess = PR_FALSE;
        if (self->mEventIsPending) {
            self->mEventIsPending = PR_FALSE;
            self->PostContinuationEvent_Locked();
        }
        return nsnull;
    }
nsAStreamCopier::PR_STATIC_CALLBACK ( void  ) [inline, inherited]

Definition at line 404 of file nsStreamUtils.cpp.

    {
        nsAStreamCopier *self = (nsAStreamCopier *) event->owner;
        NS_RELEASE(self);
        delete event;
    }
void nsAStreamCopier::Process ( ) [inline, inherited]

Definition at line 313 of file nsStreamUtils.cpp.

    {
        if (!mSource || !mSink)
            return;

        nsresult sourceCondition, sinkCondition;

        // ok, copy data from source to sink.
        for (;;) {
            PRUint32 n = DoCopy(&sourceCondition, &sinkCondition);
            if (NS_FAILED(sourceCondition) || NS_FAILED(sinkCondition) || n == 0) {
                if (sourceCondition == NS_BASE_STREAM_WOULD_BLOCK && mAsyncSource) {
                    // need to wait for more data from source.  while waiting for
                    // more source data, be sure to observe failures on output end.
                    mAsyncSource->AsyncWait(this, 0, 0, nsnull);

                    if (mAsyncSink)
                        mAsyncSink->AsyncWait(this,
                                              nsIAsyncOutputStream::WAIT_CLOSURE_ONLY,
                                              0, nsnull);
                }
                else if (sinkCondition == NS_BASE_STREAM_WOULD_BLOCK && mAsyncSink) {
                    // need to wait for more room in the sink.  while waiting for
                    // more room in the sink, be sure to observer failures on the
                    // input end.
                    mAsyncSink->AsyncWait(this, 0, 0, nsnull);

                    if (mAsyncSource)
                        mAsyncSource->AsyncWait(this,
                                                nsIAsyncInputStream::WAIT_CLOSURE_ONLY,
                                                0, nsnull);
                }
                else {
                    // close source
                    if (mAsyncSource)
                        mAsyncSource->CloseWithStatus(sinkCondition);
                    else
                        mSource->Close();
                    mAsyncSource = nsnull;
                    mSource = nsnull;

                    // close sink
                    if (mAsyncSink)
                        mAsyncSink->CloseWithStatus(sourceCondition);
                    else
                        mSink->Close();
                    mAsyncSink = nsnull;
                    mSink = nsnull;

                    // notify state complete...
                    if (mCallback) {
                        nsresult status = sourceCondition;
                        if (NS_SUCCEEDED(status))
                            status = sinkCondition;
                        if (status == NS_BASE_STREAM_CLOSED)
                            status = NS_OK;
                        mCallback(mClosure, status);
                    }
                }
                break;
            }
        }
    }

Here is the call graph for this function:

nsresult nsAStreamCopier::Start ( nsIInputStream source,
nsIOutputStream sink,
nsIEventTarget target,
nsAsyncCopyCallbackFun  callback,
void closure,
PRUint32  chunksize 
) [inline, inherited]

Definition at line 285 of file nsStreamUtils.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 455 of file nsStreamUtils.cpp.

Definition at line 454 of file nsStreamUtils.cpp.

Definition at line 458 of file nsStreamUtils.cpp.

PRUint32 nsAStreamCopier::mChunkSize [protected, inherited]

Definition at line 460 of file nsStreamUtils.cpp.

void* nsAStreamCopier::mClosure [protected, inherited]

Definition at line 459 of file nsStreamUtils.cpp.

Definition at line 461 of file nsStreamUtils.cpp.

Definition at line 462 of file nsStreamUtils.cpp.

PRLock* nsAStreamCopier::mLock [protected, inherited]

Definition at line 457 of file nsStreamUtils.cpp.

Definition at line 453 of file nsStreamUtils.cpp.

Definition at line 452 of file nsStreamUtils.cpp.

Definition at line 456 of file nsStreamUtils.cpp.


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