зеркало из https://github.com/mozilla/pjs.git
15300 r=warren. Changed NS_NewThread api to default to PR_UNJOINABLE_THREAD, also added new NS_NewThread() function so you don't have to combine the runnable w/ thread creation. added threads to xpcom init so you can create them w/ the com mgr. 15298 r=gagan, FTP threads are now synched w/ ftp handler shutdown, removed extraneous buffer work, added ftp authentication, and ftp channel content length
This commit is contained in:
Родитель
a05208badc
Коммит
0155919623
|
@ -156,7 +156,7 @@ nsresult nsSocketTransportService::Init(void)
|
|||
//
|
||||
if (NS_SUCCEEDED(rv) && !mThread) {
|
||||
mThreadRunning = PR_TRUE;
|
||||
rv = NS_NewThread(&mThread, this);
|
||||
rv = NS_NewThread(&mThread, this, 0, PR_JOINABLE_THREAD);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
|
|
@ -24,6 +24,7 @@ interface nsIFTPContext : nsISupports
|
|||
boolean IsCmdResponse();
|
||||
|
||||
attribute string ContentType;
|
||||
attribute long ContentLength;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "nsFTPChannel.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsFtpConnectionThread.h"
|
||||
|
@ -42,7 +43,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
|||
extern PRLogModuleInfo* gFTPLog;
|
||||
#endif /* PR_LOGGING */
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
// There are actually two transport connections established for an
|
||||
|
@ -55,7 +55,7 @@ static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
|
|||
|
||||
nsFTPChannel::nsFTPChannel() {
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mConnectionThread = nsnull;
|
||||
mUrl = nsnull;
|
||||
mEventQueue = nsnull;
|
||||
mEventSink = nsnull;
|
||||
|
@ -68,6 +68,7 @@ nsFTPChannel::nsFTPChannel() {
|
|||
mSourceOffset = 0;
|
||||
mAmount = 0;
|
||||
mLoadGroup = nsnull;
|
||||
mContentLength = -1;
|
||||
}
|
||||
|
||||
nsFTPChannel::~nsFTPChannel() {
|
||||
|
@ -102,10 +103,14 @@ nsFTPChannel::QueryInterface(const nsIID& aIID, void** aInstancePtr) {
|
|||
|
||||
nsresult
|
||||
nsFTPChannel::Init(const char* verb, nsIURI* uri, nsILoadGroup *aGroup,
|
||||
nsIEventSinkGetter* getter)
|
||||
nsIEventSinkGetter* getter, nsHashtable *aConnectionList,
|
||||
nsIThread **_retval)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(aConnectionList, "FTP needs a connection list");
|
||||
mConnectionList = aConnectionList;
|
||||
|
||||
if (mConnected)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
|
@ -133,8 +138,16 @@ nsFTPChannel::Init(const char* verb, nsIURI* uri, nsILoadGroup *aGroup,
|
|||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
// go ahead and create the thread for the connection.
|
||||
// we'll init it and kick it off later
|
||||
rv = NS_NewThread(&mConnectionThread, 0, PR_JOINABLE_THREAD);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*_retval = mConnectionThread;
|
||||
NS_ADDREF(*_retval);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -194,6 +207,7 @@ NS_IMETHODIMP
|
|||
nsFTPChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
#if 0
|
||||
// The ftp channel will act as the listener which will receive
|
||||
// events from the ftp connection thread. It then uses a syncstreamlistener
|
||||
// as it's mListener which receives the listener notifications and writes
|
||||
|
@ -205,13 +219,6 @@ nsFTPChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
|||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!mEventQueue) {
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rv = serv->NewSyncStreamListener(_retval /* nsIInputStream **inStream */,
|
||||
&mBufferOutputStream /* nsIBufferOutputStream **outStream */,
|
||||
&mListener/* nsIStreamListener **listener */);
|
||||
|
@ -238,6 +245,8 @@ nsFTPChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
#endif // 0
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -266,15 +275,8 @@ nsFTPChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
|||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!mEventQueue) {
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
rv = serv->NewAsyncStreamListener(listener, mEventQueue, &mListener);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mListener = listener;
|
||||
NS_ADDREF(mListener);
|
||||
|
||||
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
|
||||
nsnull/*this*/, // XXX need channel to implement nsIPipeObserver
|
||||
|
@ -289,19 +291,27 @@ nsFTPChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
|||
|
||||
////////////////////////////////
|
||||
//// setup the channel thread
|
||||
|
||||
nsIThread* workerThread = nsnull;
|
||||
nsFtpConnectionThread* protocolInterpreter =
|
||||
new nsFtpConnectionThread(mEventQueue, this, this, ctxt);
|
||||
nsFtpConnectionThread* protocolInterpreter;
|
||||
NS_NEWXPCOM(protocolInterpreter, nsFtpConnectionThread);
|
||||
if (!protocolInterpreter) return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(protocolInterpreter);
|
||||
|
||||
if (!protocolInterpreter)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = protocolInterpreter->Init(mUrl, mEventQueue, this, this, ctxt, mConnectionList);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = protocolInterpreter->SetUsePasv(PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
protocolInterpreter->Init(mUrl);
|
||||
protocolInterpreter->SetUsePasv(PR_TRUE);
|
||||
nsCOMPtr<nsIRunnable> runnable = do_QueryInterface(protocolInterpreter , &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_NewThread(&workerThread, protocolInterpreter);
|
||||
rv = mConnectionThread->Init(runnable,
|
||||
0, /* stack size */
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_JOINABLE_THREAD);
|
||||
|
||||
NS_RELEASE(mConnectionThread);
|
||||
NS_RELEASE(protocolInterpreter);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
|
@ -383,8 +393,7 @@ nsFTPChannel::GetContentType(char* *aContentType) {
|
|||
NS_IMETHODIMP
|
||||
nsFTPChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
{
|
||||
// XXX: The content length is always unknown?
|
||||
*aContentLength = -1;
|
||||
*aContentLength = mContentLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -421,26 +430,7 @@ nsFTPChannel::Get(void) {
|
|||
|
||||
NS_IMETHODIMP
|
||||
nsFTPChannel::Put(void) {
|
||||
nsresult rv;
|
||||
nsIThread* workerThread = nsnull;
|
||||
nsFtpConnectionThread* protocolInterpreter =
|
||||
new nsFtpConnectionThread(mEventQueue, this, this, nsnull);
|
||||
NS_ASSERTION(protocolInterpreter, "ftp protocol interpreter alloc failed");
|
||||
NS_ADDREF(protocolInterpreter);
|
||||
|
||||
if (!protocolInterpreter)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
protocolInterpreter->Init(mUrl);
|
||||
protocolInterpreter->SetAction(PUT);
|
||||
protocolInterpreter->SetUsePasv(PR_TRUE);
|
||||
|
||||
rv = NS_NewThread(&workerThread, protocolInterpreter);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "new thread failed");
|
||||
|
||||
// XXX this release should probably be in the destructor.
|
||||
NS_RELEASE(protocolInterpreter);
|
||||
return NS_OK;
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -487,20 +477,23 @@ nsFTPChannel::OnDataAvailable(nsIChannel* channel, nsISupports* context,
|
|||
|
||||
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::OnDataAvailable(channel = %x, context = %x, stream = %x, srcOffset = %d, length = %d)\n", channel, context, aIStream, aSourceOffset, aLength));
|
||||
|
||||
nsIFTPContext *ftpCtxt = nsnull;
|
||||
rv = context->QueryInterface(NS_GET_IID(nsIFTPContext), (void**)&ftpCtxt);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (context) {
|
||||
nsCOMPtr<nsIFTPContext> ftpCtxt = do_QueryInterface(context, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *type = nsnull;
|
||||
rv = ftpCtxt->GetContentType(&type);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *type = nsnull;
|
||||
rv = ftpCtxt->GetContentType(&type);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString cType(type);
|
||||
cType.ToLowerCase();
|
||||
mContentType = cType.GetBuffer();
|
||||
nsAllocator::Free(type);
|
||||
nsCAutoString cType(type);
|
||||
cType.ToLowerCase();
|
||||
mContentType = cType.GetBuffer();
|
||||
nsAllocator::Free(type);
|
||||
|
||||
rv = ftpCtxt->GetContentLength(&mContentLength);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
if (mListener) {
|
||||
rv = mListener->OnDataAvailable(channel, context, aIStream, aSourceOffset, aLength);
|
||||
}
|
||||
|
|
|
@ -30,9 +30,8 @@
|
|||
#include "nsIBufferOutputStream.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsILoadGroup.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsHashtable.h"
|
||||
|
||||
class nsIEventSinkGetter;
|
||||
class nsIProgressEventSink;
|
||||
|
@ -55,8 +54,12 @@ public:
|
|||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
// initializes the channel. creates the FTP connection thread
|
||||
// and returns it so the protocol handler can cache it and
|
||||
// join() it on shutdown.
|
||||
nsresult Init(const char* verb, nsIURI* uri, nsILoadGroup *aGroup,
|
||||
nsIEventSinkGetter* getter);
|
||||
nsIEventSinkGetter* getter, nsHashtable *aConnectionList,
|
||||
nsIThread **_retval);
|
||||
|
||||
protected:
|
||||
nsIURI* mUrl;
|
||||
|
@ -73,8 +76,11 @@ protected:
|
|||
PRUint32 mSourceOffset;
|
||||
PRInt32 mAmount;
|
||||
nsILoadGroup* mLoadGroup;
|
||||
nsString2 mContentType;
|
||||
nsAutoString mContentType;
|
||||
PRInt32 mContentLength;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
nsHashtable* mConnectionList; // thread safe list of connections.
|
||||
nsIThread* mConnectionThread; // the thread for this connection.
|
||||
};
|
||||
|
||||
#define NS_FTP_SEGMENT_SIZE (4*1024)
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -30,6 +30,43 @@
|
|||
#include "prtime.h"
|
||||
#include "nsString2.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIFTPContext.h"
|
||||
|
||||
// The cache object string key has the following syntax
|
||||
// "HostPort" NOTE: no seperators.
|
||||
class nsConnCacheObj {
|
||||
public:
|
||||
nsConnCacheObj(nsIChannel *aChannel,
|
||||
nsIInputStream *aInputStream,
|
||||
nsIOutputStream *aOutputStream)
|
||||
{
|
||||
mSocketTransport = aChannel;
|
||||
NS_ADDREF(mSocketTransport);
|
||||
|
||||
mInputStream = aInputStream;
|
||||
NS_ADDREF(mInputStream);
|
||||
|
||||
mOutputStream = aOutputStream;
|
||||
NS_ADDREF(mOutputStream);
|
||||
|
||||
mServerType = 0;
|
||||
};
|
||||
~nsConnCacheObj()
|
||||
{
|
||||
NS_RELEASE(mSocketTransport);
|
||||
NS_RELEASE(mInputStream);
|
||||
NS_RELEASE(mOutputStream);
|
||||
};
|
||||
|
||||
nsIChannel *mSocketTransport; // the connection
|
||||
nsIInputStream *mInputStream; // to read from server
|
||||
nsIOutputStream *mOutputStream; // to write to server
|
||||
PRUint32 mServerType; // what kind of server is it.
|
||||
nsCAutoString mCwd; // what dir are we in
|
||||
PRBool mList; // are we sending LIST or NLST
|
||||
};
|
||||
|
||||
// ftp server types
|
||||
#define FTP_GENERIC_TYPE 0
|
||||
|
@ -111,11 +148,15 @@ public:
|
|||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIRUNNABLE
|
||||
|
||||
nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamListener *aListener,
|
||||
nsIChannel* channel, nsISupports* ctxt);
|
||||
nsFtpConnectionThread();
|
||||
virtual ~nsFtpConnectionThread();
|
||||
|
||||
nsresult Init(nsIURI* aUrl);
|
||||
nsresult Init(nsIURI* aUrl,
|
||||
nsIEventQueue* aEventQ,
|
||||
nsIStreamListener *aListener,
|
||||
nsIChannel* channel,
|
||||
nsISupports* ctxt,
|
||||
nsHashtable* aConnectionList);
|
||||
nsresult Process();
|
||||
|
||||
// user level setup
|
||||
|
@ -178,7 +219,7 @@ private:
|
|||
|
||||
FTP_STATE mState; // the current state
|
||||
FTP_STATE mNextState; // the next state
|
||||
FTP_ACTION mAction; // the higher level action
|
||||
FTP_ACTION mAction; // the higher level action (GET/PUT)
|
||||
|
||||
nsISocketTransportService *mSTS; // the socket transport service;
|
||||
|
||||
|
@ -188,14 +229,11 @@ private:
|
|||
nsIOutputStream* mCOutStream; // command channel output
|
||||
nsIInputStream* mCInStream; // command channel input
|
||||
|
||||
//nsString2 mDataAddress; // the host:port combo for the data connection
|
||||
nsIOutputStream* mDOutStream; // data channel output
|
||||
nsIInputStream* mDInStream; // data channel input
|
||||
|
||||
nsIBufferInputStream* mCBufInStream; // data channel input (async)
|
||||
|
||||
PRInt32 mResponseCode; // the last command response code.
|
||||
nsString2 mResponseMsg; // the last command response text
|
||||
nsCAutoString mResponseMsg; // the last command response text
|
||||
nsString2 mUsername;
|
||||
nsString2 mPassword;
|
||||
nsString2 mFilename; // url filename (if any)
|
||||
|
@ -206,24 +244,37 @@ private:
|
|||
PRInt32 mServerType;
|
||||
PRBool mPasv;
|
||||
PRBool mList; // use LIST instead of NLST
|
||||
nsCAutoString mCwd; // Our current working dir.
|
||||
nsCAutoString mCwdAttempt; // the dir we're trying to get into.
|
||||
// end "these ...."
|
||||
|
||||
nsStringKey *mCacheKey; // the key into the cache hash.
|
||||
PRLock *mCacheLock; // the lock for accessing the cache.
|
||||
|
||||
PRBool mConnected;
|
||||
PRBool mUseDefaultPath; // use PWD to figure out path
|
||||
PRBool mUsePasv; // use a passive data connection.
|
||||
PRBool mDirectory; // this url is a directory
|
||||
PRBool mBin; // transfer mode (ascii or binary)
|
||||
PRBool mContinueRead; // continue digesting a multi-line reponse
|
||||
PRBool mResetMode; // have we reset the mode to ascii
|
||||
PRBool mAnonymous; // try connecting anonymous (default)
|
||||
PRBool mRetryPass; // retrying the password
|
||||
PRBool mCachedConn; // is this connection from the cache
|
||||
PRBool mSentStart; // have we sent an OnStartRequest() notification
|
||||
nsresult mInternalError; // represents internal state errors
|
||||
|
||||
nsIStreamListener* mListener; // the listener we want to call
|
||||
// during our event firing.
|
||||
nsIChannel* mChannel;
|
||||
nsISupports* mContext;
|
||||
nsIFTPContext* mFTPContext; // FTP channel specific context.
|
||||
|
||||
PRBool mKeepRunning; // thread event loop boolean
|
||||
|
||||
nsString2 mContentType; // the content type of the data we're dealing w/.
|
||||
char* mURLSpec;
|
||||
nsHashtable* mConnectionList; // list of open FTP connections
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -48,9 +48,28 @@ static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
|||
|
||||
nsFtpProtocolHandler::nsFtpProtocolHandler() {
|
||||
NS_INIT_REFCNT();
|
||||
NS_NEWXPCOM(mRootConnectionList, nsHashtable);
|
||||
NS_NEWXPCOM(mThreadArray, nsVoidArray);
|
||||
}
|
||||
|
||||
// cleans up a connection list entry
|
||||
PRBool CleanupConnEntry(nsHashKey *aKey, void *aData, void *closure) {
|
||||
// XXX do we need to explicitly close the streams?
|
||||
delete aData;
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsFtpProtocolHandler::~nsFtpProtocolHandler() {
|
||||
mRootConnectionList->Reset(CleanupConnEntry);
|
||||
NS_DELETEXPCOM(mRootConnectionList);
|
||||
|
||||
nsIThread *thread;
|
||||
while ( (thread = (nsIThread*)mThreadArray->ElementAt(0)) ) {
|
||||
thread->Join();
|
||||
NS_RELEASE(thread);
|
||||
mThreadArray->RemoveElementAt(0);
|
||||
}
|
||||
NS_DELETEXPCOM(mThreadArray);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFtpProtocolHandler, NS_GET_IID(nsIProtocolHandler));
|
||||
|
@ -169,13 +188,22 @@ nsFtpProtocolHandler::NewChannel(const char* verb, nsIURI* url,
|
|||
rv = nsFTPChannel::Create(nsnull, NS_GET_IID(nsIFTPChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(verb, url, aGroup, eventSinkGetter);
|
||||
nsIThread* connThread = nsnull;
|
||||
rv = channel->Init(verb, url, aGroup, eventSinkGetter,
|
||||
mRootConnectionList, &connThread);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFtpProtocolHandler::NewChannel() FAILED\n"));
|
||||
return rv;
|
||||
}
|
||||
|
||||
// add this thread to the array.
|
||||
if (!mThreadArray->AppendElement(connThread)) {
|
||||
NS_RELEASE(connThread);
|
||||
NS_RELEASE(channel);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*result = channel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
#define nsFtpProtocolHandler_h___
|
||||
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
// {25029490-F132-11d2-9588-00805F369F95}
|
||||
#define NS_FTPPROTOCOLHANDLER_CID \
|
||||
|
@ -43,6 +45,8 @@ public:
|
|||
|
||||
protected:
|
||||
nsISupports* mEventSinkGetter;
|
||||
nsHashtable* mRootConnectionList; // hash of FTP connections
|
||||
nsVoidArray* mThreadArray; // array of FTP connection threads
|
||||
};
|
||||
|
||||
#endif /* nsFtpProtocolHandler_h___ */
|
||||
|
|
|
@ -73,7 +73,7 @@ public:
|
|||
}
|
||||
|
||||
nsReader()
|
||||
: mEventQueue(nsnull), mStartTime(0), mThread(nsnull)
|
||||
: mEventQueue(nsnull), mStartTime(0), mThread(nsnull), mBytesRead(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMonitor = PR_NewMonitor();
|
||||
|
@ -133,6 +133,7 @@ public:
|
|||
buf[amt] = '\0';
|
||||
printf(buf);
|
||||
aLength -= amt;
|
||||
mBytesRead += amt;
|
||||
gVolume += amt;
|
||||
}
|
||||
PR_ExitMonitor(mMonitor);
|
||||
|
@ -148,6 +149,8 @@ public:
|
|||
PRIntervalTime endTime = PR_IntervalNow();
|
||||
gDuration += (endTime - mStartTime);
|
||||
printf("stop binding, %d\n", aStatus);
|
||||
if (NS_FAILED(aStatus)) printf("channel failed.\n");
|
||||
printf("read %d bytes\n", mBytesRead);
|
||||
PR_ExitMonitor(mMonitor);
|
||||
|
||||
// get me out of my event loop
|
||||
|
@ -161,6 +164,7 @@ protected:
|
|||
nsIEventQueue* mEventQueue;
|
||||
PRIntervalTime mStartTime;
|
||||
nsIThread* mThread;
|
||||
PRUint32 mBytesRead;
|
||||
|
||||
private:
|
||||
PRMonitor* mMonitor;
|
||||
|
@ -175,13 +179,13 @@ nsReader::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
|
|||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIRunnable>::GetIID()) ||
|
||||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIRunnable)) ||
|
||||
aIID.Equals(NS_GET_IID(nsISupports))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIRunnable*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIStreamListener>::GetIID())) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIStreamListener))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIStreamListener*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
|
@ -215,14 +219,14 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
|
|||
rv = NS_NewTypicalInputFileStream(&fs, spec);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
rv = fs->QueryInterface(nsCOMTypeInfo<nsIInputStream>::GetIID(), (void**)&fileStr);
|
||||
rv = fs->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&fileStr);
|
||||
NS_RELEASE(fs);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
#ifndef NSPIPE2
|
||||
rv = NS_NewBuffer(getter_AddRefs(buf), NS_FILE_TRANSPORT_BUFFER_SIZE,
|
||||
NS_FILE_TRANSPORT_BUFFER_SIZE, nsnull);
|
||||
rv = NS_NewBufferInputStream(&bufStr, buf);
|
||||
rv = NS_NewBufferInputStream(&bufStr, buf, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
#else
|
||||
rv = NS_NewPipe(&bufStr, getter_AddRefs(out), nsnull,
|
||||
|
@ -287,14 +291,14 @@ SerialReadTest(char* dirName)
|
|||
NS_ADDREF(reader);
|
||||
|
||||
nsIThread* readerThread;
|
||||
rv = NS_NewThread(&readerThread, reader);
|
||||
rv = NS_NewThread(&readerThread, reader, 0, PR_JOINABLE_THREAD);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "new thread failed");
|
||||
|
||||
rv = reader->Init(readerThread);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "init failed");
|
||||
|
||||
nsIStreamListener* listener;
|
||||
reader->QueryInterface(nsCOMTypeInfo<nsIStreamListener>::GetIID(), (void**)&listener);
|
||||
reader->QueryInterface(NS_GET_IID(nsIStreamListener), (void**)&listener);
|
||||
NS_ASSERTION(listener, "QI failed");
|
||||
|
||||
rv = Simulated_nsFileTransport_Run(reader, spec);
|
||||
|
@ -349,7 +353,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts)
|
|||
|
||||
nsIThread* readerThread;
|
||||
|
||||
rv = NS_NewThread(&readerThread, reader);
|
||||
rv = NS_NewThread(&readerThread, reader, 0, PR_JOINABLE_THREAD);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "new thread failed");
|
||||
|
||||
|
@ -357,7 +361,7 @@ ParallelReadTest(char* dirName, nsIFileTransportService* fts)
|
|||
NS_ASSERTION(NS_SUCCEEDED(rv), "init failed");
|
||||
|
||||
nsIStreamListener* listener;
|
||||
reader->QueryInterface(nsCOMTypeInfo<nsIStreamListener>::GetIID(), (void**)&listener);
|
||||
reader->QueryInterface(NS_GET_IID(nsIStreamListener), (void**)&listener);
|
||||
NS_ASSERTION(listener, "QI failed");
|
||||
|
||||
nsIChannel* trans;
|
||||
|
@ -415,7 +419,7 @@ main(int argc, char* argv[])
|
|||
|
||||
SerialReadTest(dirName);
|
||||
|
||||
ParallelReadTest(dirName, fts);
|
||||
//ParallelReadTest(dirName, fts);
|
||||
|
||||
fts->ProcessPendingRequests();
|
||||
|
||||
|
|
|
@ -157,14 +157,14 @@ public:
|
|||
// Open the input stream:
|
||||
rv = NS_NewTypicalInputFileStream(&str, inSpec);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = str->QueryInterface(nsCOMTypeInfo<nsIInputStream>::GetIID(), (void**)&inStr);
|
||||
rv = str->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&inStr);
|
||||
NS_RELEASE(str);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
// Open the output stream:
|
||||
rv = NS_NewTypicalOutputFileStream(&str, outSpec);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = str->QueryInterface(nsCOMTypeInfo<nsIOutputStream>::GetIID(), (void**)&outStr);
|
||||
rv = str->QueryInterface(NS_GET_IID(nsIOutputStream), (void**)&outStr);
|
||||
NS_RELEASE(str);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
|
@ -234,7 +234,7 @@ protected:
|
|||
PRUint32 mBufferSize;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(FileSpecWorker, nsCOMTypeInfo<nsIRunnable>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(FileSpecWorker, NS_GET_IID(nsIRunnable));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -341,7 +341,7 @@ protected:
|
|||
PRUint32 mBufferSize;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(FileChannelWorker, nsCOMTypeInfo<nsIRunnable>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(FileChannelWorker, NS_GET_IID(nsIRunnable));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -382,7 +382,7 @@ Test(CreateFun create, PRUint32 count,
|
|||
bufSize);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
rv = NS_NewThread(&thread, worker);
|
||||
rv = NS_NewThread(&thread, worker, 0, PR_JOINABLE_THREAD);
|
||||
NS_RELEASE(worker);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ URLLoadInfo::~URLLoadInfo()
|
|||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(URLLoadInfo,nsCOMTypeInfo<nsISupports>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(URLLoadInfo,NS_GET_IID(nsISupports));
|
||||
|
||||
|
||||
class TestHTTPEventSink : public nsIHTTPEventSink
|
||||
|
@ -131,7 +131,7 @@ TestHTTPEventSink::~TestHTTPEventSink()
|
|||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestHTTPEventSink,nsCOMTypeInfo<nsIHTTPEventSink>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(TestHTTPEventSink,NS_GET_IID(nsIHTTPEventSink));
|
||||
|
||||
NS_IMETHODIMP
|
||||
TestHTTPEventSink::OnAwaitingInput(nsISupports* context)
|
||||
|
@ -267,7 +267,7 @@ InputTestConsumer::~InputTestConsumer()
|
|||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(InputTestConsumer,nsCOMTypeInfo<nsIStreamListener>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(InputTestConsumer,NS_GET_IID(nsIStreamListener));
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -402,7 +402,7 @@ public:
|
|||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
if (nsCRT::strcmp(verb, "load") == 0) { // makeshift verb for now
|
||||
if (eventSinkIID.Equals(nsCOMTypeInfo<nsIHTTPEventSink>::GetIID())) {
|
||||
if (eventSinkIID.Equals(NS_GET_IID(nsIHTTPEventSink))) {
|
||||
TestHTTPEventSink *sink;
|
||||
|
||||
sink = new TestHTTPEventSink();
|
||||
|
@ -417,7 +417,7 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsEventSinkGetter, nsCOMTypeInfo<nsIEventSinkGetter>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(nsEventSinkGetter, NS_GET_IID(nsIEventSinkGetter));
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -462,14 +462,13 @@ nsresult StartLoadingURL(const char* aUrlString)
|
|||
nsCOMPtr<nsIHTTPChannel> pHTTPCon(do_QueryInterface(pChannel));
|
||||
|
||||
if (pHTTPCon) {
|
||||
// Setting a sample user agent string.
|
||||
nsCOMPtr<nsIAtom> userAgent;
|
||||
// Setting a sample header.
|
||||
nsCOMPtr<nsIAtom> sampleHeader;
|
||||
|
||||
userAgent = NS_NewAtom("user-agent");
|
||||
rv = pHTTPCon->SetRequestHeader(userAgent, "Mozilla/5.0 [en] (Win98; U)");
|
||||
sampleHeader = NS_NewAtom("sample-header-minus-the-colon");
|
||||
rv = pHTTPCon->SetRequestHeader(sampleHeader, "Sample-Value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
}
|
||||
InputTestConsumer* listener;
|
||||
|
||||
listener = new InputTestConsumer;
|
||||
|
|
|
@ -145,7 +145,7 @@ TestWriteObserver::~TestWriteObserver()
|
|||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestWriteObserver,nsCOMTypeInfo<nsIStreamObserver>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(TestWriteObserver,NS_GET_IID(nsIStreamObserver));
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
|
|
@ -270,18 +270,18 @@ TestConnection::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
|
|||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIRunnable>::GetIID()) ||
|
||||
aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIRunnable)) ||
|
||||
aIID.Equals(NS_GET_IID(nsISupports))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIRunnable*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIStreamListener>::GetIID())) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIStreamListener))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIStreamListener*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIStreamObserver>::GetIID())) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIStreamObserver))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIStreamObserver*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
|
@ -574,7 +574,7 @@ main(int argc, char* argv[])
|
|||
//
|
||||
for (i=0; i<NUM_TEST_THREADS; i++) {
|
||||
gConnections[i] = new TestConnection(hostName, 7, bIsAsync);
|
||||
rv = NS_NewThread(&gThreads[i], gConnections[i]);
|
||||
rv = NS_NewThread(&gThreads[i], gConnections[i], 0, PR_JOINABLE_THREAD);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
rv = NS_NewStringInputStream(&inputDataSup, convDataStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = inputDataSup->QueryInterface(nsCOMTypeInfo<nsIInputStream>::GetIID(), (void**)&inputData);
|
||||
rv = inputDataSup->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&inputData);
|
||||
NS_RELEASE(inputDataSup);
|
||||
*_retval = inputData;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -93,7 +93,7 @@ public:
|
|||
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(TestConverter,nsCOMTypeInfo<nsIStreamConverter>::GetIID());
|
||||
NS_IMPL_ISUPPORTS(TestConverter,NS_GET_IID(nsIStreamConverter));
|
||||
|
||||
class TestConverterFactory : public nsIFactory
|
||||
{
|
||||
|
@ -144,7 +144,7 @@ TestConverterFactory::QueryInterface(const nsIID &aIID, void **aResult)
|
|||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID())) {
|
||||
if (aIID.Equals(NS_GET_IID(nsISupports))) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
|
@ -178,7 +178,7 @@ TestConverterFactory::CreateInstance(nsISupports *aOuter,
|
|||
if (mClassID.Equals(kTestConverterCID)) {
|
||||
TestConverter *conv = new TestConverter();
|
||||
if (!conv) return NS_ERROR_OUT_OF_MEMORY;
|
||||
conv->QueryInterface(nsCOMTypeInfo<nsISupports>::GetIID(), (void**)&inst);
|
||||
conv->QueryInterface(NS_GET_IID(nsISupports), (void**)&inst);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
|
@ -218,7 +218,7 @@ main(int argc, char* argv[])
|
|||
|
||||
TestConverterFactory *convFactory = new TestConverterFactory(kTestConverterCID, "TestConverter", NS_ISTREAMCONVERTER_KEY);
|
||||
nsIFactory *convFactSup = nsnull;
|
||||
rv = convFactory->QueryInterface(nsCOMTypeInfo<nsIFactory>::GetIID(), (void**)&convFactSup);
|
||||
rv = convFactory->QueryInterface(NS_GET_IID(nsIFactory), (void**)&convFactSup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// register the TestConverter with the component manager. One progid registration
|
||||
|
@ -234,11 +234,13 @@ main(int argc, char* argv[])
|
|||
NS_ISTREAMCONVERTER_KEY "?from=b/foo?to=c/foo",
|
||||
convFactSup,
|
||||
PR_TRUE);
|
||||
#if 0
|
||||
rv = nsComponentManager::RegisterFactory(kTestConverterCID,
|
||||
"TestConverter",
|
||||
NS_ISTREAMCONVERTER_KEY "?from=b/foo?to=d/foo",
|
||||
convFactSup,
|
||||
PR_TRUE);
|
||||
#endif // 0
|
||||
rv = nsComponentManager::RegisterFactory(kTestConverterCID,
|
||||
"TestConverter",
|
||||
NS_ISTREAMCONVERTER_KEY "?from=c/foo?to=d/foo",
|
||||
|
@ -284,8 +286,10 @@ main(int argc, char* argv[])
|
|||
rv = registry->AddSubtreeRaw(key, "?from=b/foo?to=c/foo", &key1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#if 0
|
||||
rv = registry->AddSubtreeRaw(key, "?from=b/foo?to=d/foo", &key1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif // 0
|
||||
|
||||
rv = registry->AddSubtreeRaw(key, "?from=c/foo?to=d/foo", &key1);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -319,7 +323,7 @@ main(int argc, char* argv[])
|
|||
nsString2 toStr ("e/foo");
|
||||
to = toStr.ToNewUnicode();
|
||||
|
||||
rv = inputDataSup->QueryInterface(nsCOMTypeInfo<nsIInputStream>::GetIID(), (void**)&inputData);
|
||||
rv = inputDataSup->QueryInterface(NS_GET_IID(nsIInputStream), (void**)&inputData);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче