changed over to nsIEventQueue interface, from straight PL_EventQueue. Also took a whack at getting socketTRansport::OpenOutputSTream to work (hasn't been tested)

This commit is contained in:
valeski%netscape.com 1999-05-05 22:41:44 +00:00
Родитель fd79ce63e6
Коммит 943c469643
30 изменённых файлов: 110 добавлений и 392 удалений

Просмотреть файл

@ -20,7 +20,7 @@
#define nsIProtocolHandler_h___
#include "nsISupports.h"
#include "plevent.h"
#include "nsIEventQueue.h"
class nsIConnectionGroup;
class nsIUrl;
@ -59,7 +59,7 @@ public:
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIProtocolConnection* *result) = 0;
};

Просмотреть файл

@ -20,7 +20,8 @@
#define nsIStreamListener_h___
#include "nsIStreamObserver.h"
#include "plevent.h"
#include "nsIOutputStream.h"
#include "nsIEventQueue.h"
class nsIInputStream;
@ -59,7 +60,7 @@ public:
// the data on the other thread.
extern nsresult
NS_NewAsyncStreamListener(nsIStreamListener* *result,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIStreamListener* receiver);
// A synchronous stream listener pushes data through a pipe that ends up
@ -68,4 +69,8 @@ extern nsresult
NS_NewSyncStreamListener(nsIStreamListener* *listener,
nsIInputStream* *inStream);
extern nsresult
NS_NewSyncOutStreamListener(nsIStreamListener* *listener,
nsIOutputStream* *outStream);
#endif /* nsIIStreamListener_h___ */

Просмотреть файл

@ -1,81 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIStreamObserver_h___
#define nsIStreamObserver_h___
#include "nsISupports.h"
#include "plevent.h"
class nsIUrl;
class nsIString;
// XXX regenerate:
#define NS_ISTREAMOBSERVER_IID \
{ /* 00ca4510-f14a-11d2-9322-000000000000 */ \
0x00ca4510, \
0xf14a, \
0x11d2, \
{0x93, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} \
}
class nsIStreamObserver : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISTREAMOBSERVER_IID);
/**
* Notify the observer that the URL has started to load. This method is
* called only once, at the beginning of a URL load.<BR><BR>
*
* @return The return value is currently ignored. In the future it may be
* used to cancel the URL load..
*/
NS_IMETHOD OnStartBinding(nsISupports* context) = 0;
/**
* Notify the observer that the URL has finished loading. This method is
* called once when the networking library has finished processing the
* URL transaction initiatied via the nsINetService::Open(...) call.<BR><BR>
*
* This method is called regardless of whether the URL loaded successfully.<BR><BR>
*
* @param status Status code for the URL load.
* @param msg A text string describing the error.
* @return The return value is currently ignored.
*/
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg) = 0;
};
// An asynchronous stream observer is used to ship data over to another thread specified
// by the thread's event queue. The receiver stream observer is then used to receive
// the notifications on the other thread.
extern nsresult
NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
PLEventQueue* eventQueue,
nsIStreamObserver* receiver);
// Generic status codes for OnStopBinding:
#define NS_BINDING_SUCCEEDED NS_OK
#define NS_BINDING_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 1)
#define NS_BINDING_ABORTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
#endif /* nsIIStreamObserver_h___ */

Просмотреть файл

@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsITransport_h___
#define nsITransport_h___
#include "nsICancelable.h"
#include "plevent.h"
class nsIStreamListener;
class nsIStreamObserver;
class nsIInputStream;
class nsIOutputStream;
#define NS_ITRANSPORT_IID \
{ /* 7aa38100-ea35-11d2-931b-00104ba0fd40 */ \
0x7aa38100, \
0xea35, \
0x11d2, \
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
}
class nsITransport : public nsICancelable
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITRANSPORT_IID);
// Async routines: By calling these the calling thread agrees
// to eventually return to an event loop that will be notified
// with incoming data, calling the listener.
NS_IMETHOD AsyncRead(nsISupports* context,
PLEventQueue* appEventQueue,
nsIStreamListener* listener) = 0;
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
nsISupports* context,
PLEventQueue* appEventQueue,
nsIStreamObserver* observer) = 0;
// Synchronous routines
NS_IMETHOD OpenInputStream(nsIInputStream* *result) = 0;
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result) = 0;
};
#endif /* nsITransport_h___ */

Просмотреть файл

@ -27,6 +27,7 @@ CPPSRCS = \
nsConnectionGroup.cpp \
nsAsyncStreamListener.cpp \
nsSyncStreamListener.cpp \
nsSyncOutStreamListener.cpp \
nsFileTransport.cpp \
nsFileTransportService.cpp \
nsSocketTransport.cpp \

Просмотреть файл

@ -33,6 +33,7 @@ CPP_OBJS = \
.\$(OBJDIR)\nsConnectionGroup.obj \
.\$(OBJDIR)\nsAsyncStreamListener.obj \
.\$(OBJDIR)\nsSyncStreamListener.obj \
.\$(OBJDIR)\nsSyncOutStreamListener.obj \
.\$(OBJDIR)\nsFileTransport.obj \
.\$(OBJDIR)\nsFileTransportService.obj \
.\$(OBJDIR)\nsSocketTransport.obj \

Просмотреть файл

@ -34,10 +34,12 @@ public:
nsIString* aMsg);
// nsAsyncStreamObserver methods:
nsAsyncStreamObserver(PLEventQueue* aEventQ)
: mEventQueue(aEventQ), mReceiver(nsnull), mStatus(NS_OK)
nsAsyncStreamObserver(nsIEventQueue* aEventQ)
: mReceiver(nsnull), mStatus(NS_OK)
{
NS_INIT_REFCNT();
mEventQueue = aEventQ;
NS_IF_ADDREF(mEventQueue);
}
virtual ~nsAsyncStreamObserver();
@ -52,7 +54,7 @@ public:
void SetStatus(nsresult value) { mStatus = value; }
protected:
PLEventQueue* mEventQueue;
nsIEventQueue* mEventQueue;
nsIStreamObserver* mReceiver;
nsresult mStatus;
};
@ -83,7 +85,7 @@ public:
PRUint32 aLength);
// nsAsyncStreamListener methods:
nsAsyncStreamListener(PLEventQueue* aEventQ)
nsAsyncStreamListener(nsIEventQueue* aEventQ)
: nsAsyncStreamObserver(aEventQ) {}
void Init(nsIStreamListener* aListener) {
@ -101,7 +103,7 @@ public:
nsISupports* context);
virtual ~nsStreamListenerEvent();
nsresult Fire(PLEventQueue* aEventQ);
nsresult Fire(nsIEventQueue* aEventQ);
NS_IMETHOD HandleEvent() = 0;
@ -149,15 +151,15 @@ void PR_CALLBACK nsStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
}
nsresult
nsStreamListenerEvent::Fire(PLEventQueue* aEventQueue)
nsStreamListenerEvent::Fire(nsIEventQueue* aEventQueue)
{
NS_PRECONDITION(nsnull != aEventQueue, "PLEventQueue for thread is null");
NS_PRECONDITION(nsnull != aEventQueue, "nsIEventQueue for thread is null");
PL_InitEvent(this, nsnull,
(PLHandleEventProc) nsStreamListenerEvent::HandlePLEvent,
(PLDestroyEventProc) nsStreamListenerEvent::DestroyPLEvent);
PRStatus status = PL_PostEvent(aEventQueue, this);
PRStatus status = aEventQueue->PostEvent(this);
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}
@ -166,6 +168,7 @@ nsStreamListenerEvent::Fire(PLEventQueue* aEventQueue)
nsAsyncStreamObserver::~nsAsyncStreamObserver()
{
NS_RELEASE(mReceiver);
NS_IF_RELEASE(mEventQueue);
}
NS_IMPL_ISUPPORTS(nsAsyncStreamObserver, nsIStreamObserver::GetIID());
@ -372,7 +375,7 @@ nsAsyncStreamObserver::OnStopBinding(nsISupports* context,
nsresult
NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIStreamObserver* receiver)
{
nsAsyncStreamObserver* l =
@ -387,7 +390,7 @@ NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
nsresult
NS_NewAsyncStreamListener(nsIStreamListener* *result,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIStreamListener* receiver)
{
nsAsyncStreamListener* l =

Просмотреть файл

@ -170,7 +170,7 @@ nsFileTransport::Resume(void)
NS_IMETHODIMP
nsFileTransport::AsyncRead(nsISupports* context,
PLEventQueue* appEventQueue,
nsIEventQueue* appEventQueue,
nsIStreamListener* listener)
{
nsresult rv;
@ -191,7 +191,7 @@ nsFileTransport::AsyncRead(nsISupports* context,
NS_IMETHODIMP
nsFileTransport::AsyncWrite(nsIInputStream* fromStream,
nsISupports* context,
PLEventQueue* appEventQueue,
nsIEventQueue* appEventQueue,
nsIStreamObserver* observer)
{
return NS_ERROR_NOT_IMPLEMENTED;

Просмотреть файл

@ -21,7 +21,7 @@
#include "nsITransport.h"
#include "nsIThread.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "prmon.h"
class nsFileTransportService;
@ -42,11 +42,11 @@ public:
// nsITransport methods:
NS_IMETHOD AsyncRead(nsISupports* context,
PLEventQueue* appEventQueue,
nsIEventQueue* appEventQueue,
nsIStreamListener* listener);
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
nsISupports* context,
PLEventQueue* appEventQueue,
nsIEventQueue* appEventQueue,
nsIStreamObserver* observer);
NS_IMETHOD OpenInputStream(nsIInputStream* *result);
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result);

Просмотреть файл

@ -23,7 +23,7 @@
#include "nsISupportsArray.h"
#include "nsIThread.h"
#include "nscore.h"
#include "plevent.h"
#include "nsIEventQueue.h"
class nsFileTransport;

Просмотреть файл

@ -30,7 +30,7 @@
#include <ctype.h> // for isalpha
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUE_CID);
////////////////////////////////////////////////////////////////////////////////
@ -185,7 +185,7 @@ nsNetService::NewConnection(nsIUrl* url,
rv = GetProtocolHandler(scheme, &handler);
if (NS_FAILED(rv)) return rv;
PLEventQueue* eventQ;
nsIEventQueue* eventQ;
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
if (NS_SUCCEEDED(rv)) {
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);

Просмотреть файл

@ -651,7 +651,7 @@ nsSocketTransport::Resume(void)
NS_IMETHODIMP
nsSocketTransport::AsyncRead(nsISupports* aContext,
PLEventQueue* aAppEventQueue,
nsIEventQueue* aAppEventQueue,
nsIStreamListener* aListener)
{
nsresult rv = NS_OK;
@ -688,7 +688,7 @@ nsSocketTransport::AsyncRead(nsISupports* aContext,
NS_IMETHODIMP
nsSocketTransport::AsyncWrite(nsIInputStream* aFromStream,
nsISupports* aContext,
PLEventQueue* aAppEventQueue,
nsIEventQueue* aAppEventQueue,
nsIStreamObserver* aObserver)
{
nsresult rv = NS_OK;
@ -756,10 +756,11 @@ nsSocketTransport::OpenInputStream(nsIInputStream* *result)
}
static NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
NS_IMETHODIMP
nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
{
#if 0
nsresult rv = NS_OK;
if (eSocketOperation_None != mOperation) {
@ -767,15 +768,26 @@ nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
rv = NS_ERROR_FAILURE;
}
if (NS_SUCCEEDED(rv) && !mWriteStream) {
nsIByteBufferInputStream* tmp = nsnull;
rv = NS_NewByteBufferInputStream(&tmp, PR_FALSE,
MAX_IO_BUFFER_SIZE);
if (NS_SUCCEEDED(rv)) {
rv = tmp->QueryInterface(kIInputStreamIID, (void **) mWriteStream);
NS_RELEASE(tmp);
if (NS_FAILED(rv)) return rv;
}
}
if (NS_SUCCEEDED(rv)) {
NS_IF_RELEASE(mWriteStream);
mWriteStream = nsnull;
//NS_IF_RELEASE(mWriteStream);
//mWriteStream = nsnull;
NS_IF_RELEASE(mContext);
mContext = nsnull;
NS_IF_RELEASE(mListener);
rv = NS_NewSyncStreamObserver(&mListener, result);
rv = NS_NewSyncOutStreamListener(&mListener, result);
}
if (NS_SUCCEEDED(rv)) {
@ -784,8 +796,6 @@ nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
}
return rv;
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -66,11 +66,11 @@ public:
// nsITransport methods:
NS_IMETHOD AsyncRead(nsISupports* context,
PLEventQueue* appEventQueue,
nsIEventQueue* appEventQueue,
nsIStreamListener* listener);
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
nsISupports* context,
PLEventQueue* appEventQueue,
nsIEventQueue* appEventQueue,
nsIStreamObserver* observer);
NS_IMETHOD OpenInputStream(nsIInputStream* *result);
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result);

Просмотреть файл

@ -28,7 +28,7 @@
#endif
#include "plstr.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "nsIComponentManager.h"

Просмотреть файл

@ -55,11 +55,12 @@ nsFtpConnectionThread::QueryInterface(const nsIID& aIID, void** aInstancePtr) {
return NS_NOINTERFACE;
}
nsFtpConnectionThread::nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamListener* aListener) {
nsFtpConnectionThread::nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamListener* aListener) {
NS_INIT_REFCNT();
mEventQueue = aEventQ; // whoever creates us must provide an event queue
// so we can post events back to them.
NS_IF_ADDREF(mEventQueue);
mListener = aListener;
NS_IF_ADDREF(mListener);
mAction = GET;
@ -72,6 +73,7 @@ nsFtpConnectionThread::nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamLis
nsFtpConnectionThread::~nsFtpConnectionThread() {
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mEventQueue);
}

Просмотреть файл

@ -25,7 +25,7 @@
#include "nsIString.h"
#include "nsString2.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "time.h" // XXX should probably be using PRTime stuff
@ -110,7 +110,7 @@ class nsFtpConnectionThread : public nsIRunnable {
public:
NS_DECL_ISUPPORTS
nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamListener *aListener);
nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamListener *aListener);
virtual ~nsFtpConnectionThread();
// nsIRunnable method
@ -132,7 +132,7 @@ private:
// Private members
PLEventQueue* mEventQueue; // used to communicate outside this thread
nsIEventQueue* mEventQueue; // used to communicate outside this thread
nsIUrl* mUrl;
FTP_STATE mState; // the current state

Просмотреть файл

@ -23,10 +23,12 @@
#include "nsIServiceManager.h"
#include "nsIByteBufferInputStream.h"
#include "nsFtpConnectionThread.h"
#include "nsIEventQueueService.h"
#include "prprf.h" // PR_sscanf
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUE_CID);
// There are actually two transport connections established for an
// ftp connection. One is used for the command channel , and
@ -39,13 +41,22 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsFtpProtocolConnection::nsFtpProtocolConnection()
: mUrl(nsnull), mConnected(PR_FALSE), mListener(nsnull) {
mEventQueue = PL_CreateEventQueue("FTP Event Queue", PR_CurrentThread());
nsresult rv;
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
if (NS_SUCCEEDED(rv)) {
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
}
if (NS_FAILED(rv))
mEventQueue = nsnull;
NS_INIT_REFCNT();
}
nsFtpProtocolConnection::~nsFtpProtocolConnection() {
NS_IF_RELEASE(mUrl);
NS_IF_RELEASE(mListener);
NS_IF_RELEASE(mEventQueue);
}
NS_IMPL_ADDREF(nsFtpProtocolConnection);
@ -71,7 +82,7 @@ nsFtpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
}
nsresult
nsFtpProtocolConnection::Init(nsIUrl* aUrl, nsISupports* aEventSink, PLEventQueue* aEventQueue) {
nsFtpProtocolConnection::Init(nsIUrl* aUrl, nsISupports* aEventSink, nsIEventQueue* aEventQueue) {
if (mConnected)
return NS_ERROR_NOT_IMPLEMENTED;
@ -80,6 +91,7 @@ nsFtpProtocolConnection::Init(nsIUrl* aUrl, nsISupports* aEventSink, PLEventQueu
NS_ADDREF(mUrl);
mEventQueue = aEventQueue;
NS_IF_ADDREF(mEventQueue);
return NS_OK;
}

Просмотреть файл

@ -1,82 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// ftp implementation header
#ifndef nsFtpProtocolConnection_h___
#define nsFtpProtocolConnection_h___
#include "nsIFtpProtocolConnection.h"
#include "nsIStreamListener.h"
#include "nsITransport.h"
#include "nsIThread.h"
#include "nsIUrl.h"
#include "nsString2.h"
#include "plevent.h"
class nsFtpProtocolConnection : public nsIFtpProtocolConnection
,public nsIStreamListener {
public:
NS_DECL_ISUPPORTS
// nsICancelable methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
// nsIProtocolConnection methods:
NS_IMETHOD Open(void);
NS_IMETHOD GetContentType(char* *contentType);
NS_IMETHOD GetInputStream(nsIInputStream* *result);
NS_IMETHOD GetOutputStream(nsIOutputStream* *result);
// nsIFtpProtocolConnection methods:
NS_IMETHOD Get(void);
NS_IMETHOD Put(void);
// nsIStreamObserver methods:
NS_IMETHOD OnStartBinding(nsISupports* context);
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg);
// nsIStreamListener methods:
NS_IMETHOD OnDataAvailable(nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength);
// nsFtpProtocolConnection methods:
NS_IMETHOD SetStreamListener(nsIStreamListener* aListener);
nsFtpProtocolConnection();
virtual ~nsFtpProtocolConnection();
nsresult Init(nsIUrl* aUrl, nsISupports* aEventSink, PLEventQueue* aEventQueue);
protected:
nsIUrl* mUrl;
PLEventQueue* mEventQueue;
PRBool mConnected;
nsIStreamListener* mListener;
};
#endif /* nsFtpProtocolConnection_h___ */

Просмотреть файл

@ -108,7 +108,7 @@ nsFtpProtocolHandler::NewUrl(const char* aSpec,
NS_IMETHODIMP
nsFtpProtocolHandler::NewConnection(nsIUrl* url,
nsISupports* eventSink,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIProtocolConnection* *result)
{
nsresult rv;

Просмотреть файл

@ -41,7 +41,7 @@ public:
nsIUrl* *result);
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIProtocolConnection* *result);
// nsFtpProtocolHandler methods:

Просмотреть файл

@ -57,15 +57,15 @@ void PR_CALLBACK nsFtpStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
}
nsresult
nsFtpStreamListenerEvent::Fire(PLEventQueue* aEventQueue)
nsFtpStreamListenerEvent::Fire(nsIEventQueue* aEventQueue)
{
NS_PRECONDITION(nsnull != aEventQueue, "PLEventQueue for thread is null");
NS_PRECONDITION(nsnull != aEventQueue, "nsIEventQueue for thread is null");
PL_InitEvent(this, nsnull,
(PLHandleEventProc) nsFtpStreamListenerEvent::HandlePLEvent,
(PLDestroyEventProc) nsFtpStreamListenerEvent::DestroyPLEvent);
PRStatus status = PL_PostEvent(aEventQueue, this);
PRStatus status = aEventQueue->PostEvent(this);
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
}

Просмотреть файл

@ -20,7 +20,7 @@
#include "nsIStreamListener.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "nscore.h"
#include "nsString.h"
@ -30,7 +30,7 @@ public:
nsFtpStreamListenerEvent(nsIStreamListener* listener, nsISupports* context);
virtual ~nsFtpStreamListenerEvent();
nsresult Fire(PLEventQueue* aEventQ);
nsresult Fire(nsIEventQueue* aEventQ);
NS_IMETHOD HandleEvent() = 0;

Просмотреть файл

@ -45,6 +45,7 @@ nsHttpProtocolConnection::~nsHttpProtocolConnection()
NS_IF_RELEASE(mHandler);
NS_IF_RELEASE(mUrl);
NS_IF_RELEASE(mEventSink);
NS_IF_RELEASE(mEventQueue);
}
NS_IMPL_ADDREF(nsHttpProtocolConnection);
@ -73,7 +74,7 @@ nsHttpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
nsresult
nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
nsHttpProtocolHandler* handler,
PLEventQueue* eventQueue)
nsIEventQueue* eventQueue)
{
nsresult rv;
@ -87,6 +88,7 @@ nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
if (NS_FAILED(rv)) return rv;
mEventQueue = eventQueue;
NS_IF_ADDREF(mEventQueue);
return rv;
}

Просмотреть файл

@ -1,107 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsHttpProtocolConnection_h___
#define nsHttpProtocolConnection_h___
#include "nsIHttpProtocolConnection.h"
#include "nsIStreamListener.h"
class nsIConnectionGroup;
class nsIHttpEventSink;
class nsIString;
class nsITransport;
class nsHttpProtocolHandler;
class nsHttpProtocolConnection : public nsIHttpProtocolConnection,
public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
// nsICancelable methods:
NS_IMETHOD Cancel(void);
NS_IMETHOD Suspend(void);
NS_IMETHOD Resume(void);
// nsIProtocolConnection methods:
NS_IMETHOD Open(void);
NS_IMETHOD GetContentType(char* *contentType);
NS_IMETHOD GetInputStream(nsIInputStream* *result);
NS_IMETHOD GetOutputStream(nsIOutputStream* *result);
// nsIHttpProtocolConnection methods:
NS_IMETHOD GetHeader(const char* header, char* *result);
NS_IMETHOD AddHeader(const char* header, const char* value);
NS_IMETHOD RemoveHeader(const char* header);
NS_IMETHOD Get(void);
NS_IMETHOD GetByteRange(PRUint32 from, PRUint32 to);
NS_IMETHOD Put(void);
NS_IMETHOD Post(void);
// nsIStreamObserver methods:
NS_IMETHOD OnStartBinding(nsISupports* context);
NS_IMETHOD OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg);
// nsIStreamListener methods:
NS_IMETHOD OnDataAvailable(nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength);
// nsHttpProtocolConnection methods:
nsHttpProtocolConnection();
virtual ~nsHttpProtocolConnection();
nsresult Init(nsIUrl* url, nsISupports* eventSink,
nsHttpProtocolHandler* handler,
PLEventQueue* eventQueue);
nsresult GetExistingTransport(const char* host, PRInt32 port,
nsITransport* *result);
enum State {
UNCONNECTED,
POSTING,
CONNECTED,
WAITING_REPLY
};
protected:
nsHttpProtocolHandler* mHandler;
nsIUrl* mUrl;
nsIHttpEventSink* mEventSink;
State mState;
nsITransport* mTransport;
PLEventQueue* mEventQueue;
};
const char HTTP_VERSION_STRING_1_1[] = "HTTP/1.1";
const char HTTP_VERSION_STRING_1_0[] = "HTTP/1.0";
const PRUint32 HTTP_VERSION_STRING_LENGTH = 8;
#define HTTP_DEFAULT_VERSION_STRING HTTP_VERSION_STRING_1_1
enum nsHttpVersion {
nsHttpVersion_0_9,
nsHttpVersion_1_0,
nsHttpVersion_1_1
};
const nsHttpVersion kHttpDefaultVersion = nsHttpVersion_1_1;
#endif /* nsHttpProtocolConnection_h___ */

Просмотреть файл

@ -122,7 +122,7 @@ nsHttpProtocolHandler::NewUrl(const char* aSpec,
NS_IMETHODIMP
nsHttpProtocolHandler::NewConnection(nsIUrl* url,
nsISupports* eventSink,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIProtocolConnection* *result)
{
nsresult rv;

Просмотреть файл

@ -49,7 +49,7 @@ public:
nsIUrl* *result);
NS_IMETHOD NewConnection(nsIUrl* url,
nsISupports* eventSink,
PLEventQueue* eventQueue,
nsIEventQueue* eventQueue,
nsIProtocolConnection* *result);
// nsHttpProtocolHandler methods:

Просмотреть файл

@ -21,7 +21,8 @@
#include "nsIServiceManager.h"
#include "nsIInputStream.h"
#include "nsIThread.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "nsIEventQueueService.h"
#include "prinrval.h"
#include "prmon.h"
#include "prio.h"
@ -35,6 +36,7 @@
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUE_CID);
PRIntervalTime gDuration = 0;
PRUint32 gVolume = 0;
@ -53,7 +55,13 @@ public:
PR_ExitMonitor(mMonitor);
// printf("running\n");
PL_EventLoop(mEventQueue);
// event loop
mEventQueue->ProcessPendingEvents();
while (PR_TRUE) {
}
// printf("quitting\n");
return NS_OK;
}
@ -67,17 +75,23 @@ public:
virtual ~nsReader() {
NS_IF_RELEASE(mThread);
NS_IF_RELEASE(mEventQueue);
PR_DestroyMonitor(mMonitor);
}
nsresult Init(nsIThread* thread) {
nsresult rv;
mThread = thread;
NS_ADDREF(mThread);
PRThread* prthread;
thread->GetPRThread(&prthread);
PR_EnterMonitor(mMonitor);
mEventQueue = PL_CreateEventQueue("runner event loop",
prthread);
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
if (NS_SUCCEEDED(rv)) {
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
}
if (NS_FAILED(rv)) return rv;
// wake up event loop
PR_Notify(mMonitor);
PR_ExitMonitor(mMonitor);
@ -85,7 +99,7 @@ public:
return NS_OK;
}
PLEventQueue* GetEventQueue() { return mEventQueue; }
nsIEventQueue* GetEventQueue() { return mEventQueue; }
NS_IMETHOD OnStartBinding(nsISupports* context) {
PR_EnterMonitor(mMonitor);
@ -135,7 +149,7 @@ public:
}
protected:
PLEventQueue* mEventQueue;
nsIEventQueue* mEventQueue;
PRIntervalTime mStartTime;
nsIThread* mThread;

Просмотреть файл

@ -46,10 +46,11 @@
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_IID(kEventQueueCID, NS_EVENTQUEUE_CID);
static PRTime gElapsedTime;
static int gKeepRunning = 1;
static PLEventQueue* gEventQ = nsnull;
static nsIEventQueue* gEventQ = nsnull;
class InputTestConsumer : public nsIStreamListener
{
@ -208,6 +209,7 @@ main(int argc, char* argv[])
// XXX why do I have to do this?!
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
nsComponentManager::RegisterComponent(kEventQueueCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup,
"components");
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -151,7 +151,7 @@ main(int argc, char* argv[])
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
PLEventQueue* eventQ;
nsIEventQueue* eventQ;
rv = eventQService->CreateThreadEventQueue();
if (NS_FAILED(rv)) return rv;

Просмотреть файл

@ -24,7 +24,7 @@
#endif
#include "plstr.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "nsIProtocolConnection.h"
#include "nsIStreamListener.h"