Back to index

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsAStreamCopier ()
virtual ~nsAStreamCopier ()
nsresult Start (nsIInputStream *source, nsIOutputStream *sink, nsIEventTarget *target, nsAsyncCopyCallbackFun callback, void *closure, PRUint32 chunksize)
virtual PRUint32 DoCopy (nsresult *sourceCondition, nsresult *sinkCondition)=0
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.

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 261 of file nsStreamUtils.cpp.


Constructor & Destructor Documentation

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

Definition at line 278 of file nsStreamUtils.cpp.

Here is the call graph for this function:


Member Function Documentation

virtual PRUint32 nsAStreamCopier::DoCopy ( nsresult sourceCondition,
nsresult sinkCondition 
) [pure virtual]

Implemented in nsStreamCopierOB.

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:

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;
    }

Definition at line 404 of file nsStreamUtils.cpp.

    {
        nsAStreamCopier *self = (nsAStreamCopier *) event->owner;
        NS_RELEASE(self);
        delete event;
    }

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]

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.

Definition at line 460 of file nsStreamUtils.cpp.

Definition at line 459 of file nsStreamUtils.cpp.

Definition at line 461 of file nsStreamUtils.cpp.

Definition at line 462 of file nsStreamUtils.cpp.

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: