Back to index

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

#include <nsFtpControlConnection.h>

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

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIREQUESTOBSERVER 
nsFtpControlConnection (const char *host, PRUint32 port)
 ~nsFtpControlConnection ()
nsresult Connect (nsIProxyInfo *proxyInfo, nsITransportEventSink *eventSink)
nsresult Disconnect (nsresult status)
nsresult Write (nsCString &command, PRBool suspend)
PRBool IsAlive ()
nsIRequestReadRequest ()
nsITransportTransport ()
void SetStreamListener (nsIStreamListener *l)
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.

Public Attributes

PRUint32 mServerType
nsString mPassword
PRInt32 mSuspendedWrite
nsCString mPwd

Private Attributes

nsCString mHost
PRUint32 mPort
nsCOMPtr< nsIRequestmReadRequest
nsCOMPtr< nsISocketTransportmCPipe
nsCOMPtr< nsIOutputStreammOutStream
nsCOMPtr< nsIStreamListenermListener

Detailed Description

Definition at line 56 of file nsFtpControlConnection.h.


Constructor & Destructor Documentation

NS_DECL_ISUPPORTS NS_DECL_NSISTREAMLISTENER NS_DECL_NSIREQUESTOBSERVER nsFtpControlConnection::nsFtpControlConnection ( const char *  host,
PRUint32  port 
)

Definition at line 79 of file nsFtpControlConnection.cpp.

{
    LOG_ALWAYS(("(%x) nsFtpControlConnection destroyed", this));
}

Member Function Documentation

Definition at line 95 of file nsFtpControlConnection.cpp.

{
    nsresult rv;

    if (!mCPipe) {
        // build our own
        nsCOMPtr<nsISocketTransportService> sts =
                do_GetService(kSocketTransportServiceCID, &rv);

        rv = sts->CreateTransport(nsnull, 0, mHost, mPort, proxyInfo,
                                  getter_AddRefs(mCPipe)); // the command transport
        if (NS_FAILED(rv)) return rv;

        // proxy transport events back to current thread
        if (eventSink) {
            nsCOMPtr<nsIEventQueue> eventQ;
            rv = NS_GetCurrentEventQ(getter_AddRefs(eventQ));
            if (NS_SUCCEEDED(rv))
                mCPipe->SetEventSink(eventSink, eventQ);
        }

        // open buffered, blocking output stream to socket.  so long as commands
        // do not exceed 1024 bytes in length, the writing thread (the main thread)
        // will not block.  this should be OK.
        rv = mCPipe->OpenOutputStream(nsITransport::OPEN_BLOCKING, 1024, 1,
                                      getter_AddRefs(mOutStream));
        if (NS_FAILED(rv)) return rv;

        // open buffered, non-blocking/asynchronous input stream to socket.
        nsCOMPtr<nsIInputStream> inStream;
        rv = mCPipe->OpenInputStream(0,
                                     FTP_COMMAND_CHANNEL_SEG_SIZE, 
                                     FTP_COMMAND_CHANNEL_SEG_COUNT,
                                     getter_AddRefs(inStream));
        if (NS_FAILED(rv)) return rv;

        nsCOMPtr<nsIInputStreamPump> pump;
        rv = NS_NewInputStreamPump(getter_AddRefs(pump), inStream);
        if (NS_FAILED(rv)) return rv;

        // get the ball rolling by reading on the control socket.
        rv = pump->AsyncRead(NS_STATIC_CAST(nsIStreamListener*, this), nsnull);
        if (NS_FAILED(rv)) return rv;

        // cyclic reference!
        mReadRequest = pump;
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 147 of file nsFtpControlConnection.cpp.

{
    if (!mCPipe) return NS_ERROR_FAILURE;
    
    LOG_ALWAYS(("(%x) nsFtpControlConnection disconnecting (%x)", this, status));

    if (NS_FAILED(status)) {
        // break cyclic reference!
        mOutStream = 0;
        mReadRequest->Cancel(status);
        mReadRequest = 0;
        mCPipe->Close(status);
        mCPipe = 0;
    }

    return NS_OK;
}

Here is the caller graph for this function:

Definition at line 85 of file nsFtpControlConnection.cpp.

{
    if (!mCPipe) 
        return PR_FALSE;

    PRBool isAlive = PR_FALSE;
    mCPipe->IsAlive(&isAlive);
    return isAlive;
}

Here is the caller graph for this function:

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:

Definition at line 72 of file nsFtpControlConnection.h.

{ return mReadRequest; }

Definition at line 75 of file nsFtpControlConnection.h.

{ mListener = l; }

Here is the caller graph for this function:

Definition at line 73 of file nsFtpControlConnection.h.

{ return mCPipe; }

Here is the caller graph for this function:

Definition at line 166 of file nsFtpControlConnection.cpp.

{
    if (!mCPipe)
        return NS_ERROR_FAILURE;

    PRUint32 len = command.Length();
    PRUint32 cnt;
    nsresult rv = mOutStream->Write(command.get(), len, &cnt);

    if (NS_FAILED(rv))
        return rv;

    if (len != cnt)
        return NS_ERROR_FAILURE;
    
    if (suspend)
        return NS_OK;

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 87 of file nsFtpControlConnection.h.

Definition at line 83 of file nsFtpControlConnection.h.

Definition at line 89 of file nsFtpControlConnection.h.

Definition at line 88 of file nsFtpControlConnection.h.

Definition at line 78 of file nsFtpControlConnection.h.

Definition at line 84 of file nsFtpControlConnection.h.

Definition at line 80 of file nsFtpControlConnection.h.

Definition at line 86 of file nsFtpControlConnection.h.

Definition at line 77 of file nsFtpControlConnection.h.

Definition at line 79 of file nsFtpControlConnection.h.


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