Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
nsSyncStreamListener Class Reference

#include <nsSyncStreamListener.h>

Inheritance diagram for nsSyncStreamListener:
Inheritance graph
[legend]
Collaboration diagram for nsSyncStreamListener:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSISYNCSTREAMLISTENER
NS_DECL_NSIINPUTSTREAM 
nsSyncStreamListener ()
virtual ~nsSyncStreamListener ()
nsresult Init ()
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.
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

readonly attribute nsIInputStream inputStream
 Returns an input stream that when read will fetch data delivered to the sync stream listener.

Private Member Functions

nsresult WaitForData ()

Private Attributes

nsCOMPtr< nsIInputStreammPipeIn
nsCOMPtr< nsIOutputStreammPipeOut
nsCOMPtr< nsIEventQueuemEventQ
nsresult mStatus
PRPackedBool mKeepWaiting
PRPackedBool mDone

Detailed Description

Definition at line 48 of file nsSyncStreamListener.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSIREQUESTOBSERVER NS_DECL_NSISTREAMLISTENER NS_DECL_NSISYNCSTREAMLISTENER NS_DECL_NSIINPUTSTREAM nsSyncStreamListener::nsSyncStreamListener ( ) [inline]

Definition at line 58 of file nsSyncStreamListener.h.

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

Definition at line 62 of file nsSyncStreamListener.h.

{}

Member Function Documentation

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

Close the stream.

Definition at line 43 of file nsSyncStreamListener.cpp.

Here is the call graph for this function:

Returns:
true if stream is non-blocking
void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:

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).

Definition at line 54 of file nsSyncStreamListener.cpp.

{
    nsresult rv;

    if (!mEventQ) {
        rv = NS_GetCurrentEventQ(getter_AddRefs(mEventQ));
        if (NS_FAILED(rv)) return rv;
    }

    mKeepWaiting = PR_TRUE;

    PLEvent *ev;
    while (mKeepWaiting) {
        rv = mEventQ->WaitForEvent(&ev);
        if (NS_FAILED(rv)) return rv;

        rv = mEventQ->HandleEvent(ev);
        if (NS_FAILED(rv)) return rv;
    }

    return NS_OK;
}

Here is the call graph for this function:


Member Data Documentation

Returns an input stream that when read will fetch data delivered to the sync stream listener.

The nsIInputStream implementation will wait for OnDataAvailable events before returning from Read.

NOTE: Reading from the returned nsIInputStream may spin the current thread's event queue, which could result in any event being processed.

Definition at line 50 of file nsISyncStreamListener.idl.

Definition at line 75 of file nsSyncStreamListener.h.

Definition at line 72 of file nsSyncStreamListener.h.

Definition at line 74 of file nsSyncStreamListener.h.

Definition at line 70 of file nsSyncStreamListener.h.

Definition at line 71 of file nsSyncStreamListener.h.

Definition at line 73 of file nsSyncStreamListener.h.


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