diff --git a/netwerk/base/public/nsIProtocolHandler.h b/netwerk/base/public/nsIProtocolHandler.h index a91b2c3b811..c836a94df5b 100644 --- a/netwerk/base/public/nsIProtocolHandler.h +++ b/netwerk/base/public/nsIProtocolHandler.h @@ -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; }; diff --git a/netwerk/base/public/nsIStreamListener.h b/netwerk/base/public/nsIStreamListener.h index 1e0188a6a07..3177baa1455 100644 --- a/netwerk/base/public/nsIStreamListener.h +++ b/netwerk/base/public/nsIStreamListener.h @@ -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___ */ diff --git a/netwerk/base/public/nsIStreamObserver.h b/netwerk/base/public/nsIStreamObserver.h index 7ec8903b867..e69de29bb2d 100644 --- a/netwerk/base/public/nsIStreamObserver.h +++ b/netwerk/base/public/nsIStreamObserver.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.

- * - * @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.

- * - * This method is called regardless of whether the URL loaded successfully.

- * - * @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___ */ diff --git a/netwerk/base/public/nsITransport.h b/netwerk/base/public/nsITransport.h index 4b370dd4685..e69de29bb2d 100644 --- a/netwerk/base/public/nsITransport.h +++ b/netwerk/base/public/nsITransport.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___ */ diff --git a/netwerk/base/src/Makefile.in b/netwerk/base/src/Makefile.in index 91bd9bb03c1..5d329212dcc 100644 --- a/netwerk/base/src/Makefile.in +++ b/netwerk/base/src/Makefile.in @@ -27,6 +27,7 @@ CPPSRCS = \ nsConnectionGroup.cpp \ nsAsyncStreamListener.cpp \ nsSyncStreamListener.cpp \ + nsSyncOutStreamListener.cpp \ nsFileTransport.cpp \ nsFileTransportService.cpp \ nsSocketTransport.cpp \ diff --git a/netwerk/base/src/makefile.win b/netwerk/base/src/makefile.win index 10439558064..500c211f40e 100644 --- a/netwerk/base/src/makefile.win +++ b/netwerk/base/src/makefile.win @@ -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 \ diff --git a/netwerk/base/src/nsAsyncStreamListener.cpp b/netwerk/base/src/nsAsyncStreamListener.cpp index b2959c580ec..5679b53c073 100644 --- a/netwerk/base/src/nsAsyncStreamListener.cpp +++ b/netwerk/base/src/nsAsyncStreamListener.cpp @@ -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 = diff --git a/netwerk/base/src/nsFileTransport.cpp b/netwerk/base/src/nsFileTransport.cpp index 67bd7fe5851..bc02bbd2eb0 100644 --- a/netwerk/base/src/nsFileTransport.cpp +++ b/netwerk/base/src/nsFileTransport.cpp @@ -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; diff --git a/netwerk/base/src/nsFileTransport.h b/netwerk/base/src/nsFileTransport.h index 929053a01a5..64fe5c10d81 100644 --- a/netwerk/base/src/nsFileTransport.h +++ b/netwerk/base/src/nsFileTransport.h @@ -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); diff --git a/netwerk/base/src/nsFileTransportService.h b/netwerk/base/src/nsFileTransportService.h index 4e17f1e31f5..803815c886e 100644 --- a/netwerk/base/src/nsFileTransportService.h +++ b/netwerk/base/src/nsFileTransportService.h @@ -23,7 +23,7 @@ #include "nsISupportsArray.h" #include "nsIThread.h" #include "nscore.h" -#include "plevent.h" +#include "nsIEventQueue.h" class nsFileTransport; diff --git a/netwerk/base/src/nsNetService.cpp b/netwerk/base/src/nsNetService.cpp index e2ba03b0b73..75c68505df2 100644 --- a/netwerk/base/src/nsNetService.cpp +++ b/netwerk/base/src/nsNetService.cpp @@ -30,7 +30,7 @@ #include // 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); diff --git a/netwerk/base/src/nsSocketTransport.cpp b/netwerk/base/src/nsSocketTransport.cpp index 0d19fa44e7a..42cc9917eef 100644 --- a/netwerk/base/src/nsSocketTransport.cpp +++ b/netwerk/base/src/nsSocketTransport.cpp @@ -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; } diff --git a/netwerk/base/src/nsSocketTransport.h b/netwerk/base/src/nsSocketTransport.h index 4e430513602..aebaa591385 100644 --- a/netwerk/base/src/nsSocketTransport.h +++ b/netwerk/base/src/nsSocketTransport.h @@ -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); diff --git a/netwerk/base/tests/urltest.cpp b/netwerk/base/tests/urltest.cpp index 51af67730f5..e61ab61b89e 100644 --- a/netwerk/base/tests/urltest.cpp +++ b/netwerk/base/tests/urltest.cpp @@ -28,7 +28,7 @@ #endif #include "plstr.h" -#include "plevent.h" +#include "nsIEventQueue.h" #include "nsIComponentManager.h" diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index 9b487391e96..ff55772a0a5 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -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); } diff --git a/netwerk/protocol/ftp/src/nsFtpConnectionThread.h b/netwerk/protocol/ftp/src/nsFtpConnectionThread.h index 42bd203b460..1f0099f57e7 100644 --- a/netwerk/protocol/ftp/src/nsFtpConnectionThread.h +++ b/netwerk/protocol/ftp/src/nsFtpConnectionThread.h @@ -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 diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolConnection.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolConnection.cpp index 369b70b9ba0..93756aa0751 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolConnection.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolConnection.cpp @@ -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; } diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolConnection.h b/netwerk/protocol/ftp/src/nsFtpProtocolConnection.h index e5ad90995c4..e69de29bb2d 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolConnection.h +++ b/netwerk/protocol/ftp/src/nsFtpProtocolConnection.h @@ -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___ */ diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index 0fd6ae3bdc5..886ce0bceb5 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -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; diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h index 57ddfbf8b9c..b2802f78056 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.h @@ -41,7 +41,7 @@ public: nsIUrl* *result); NS_IMETHOD NewConnection(nsIUrl* url, nsISupports* eventSink, - PLEventQueue* eventQueue, + nsIEventQueue* eventQueue, nsIProtocolConnection* *result); // nsFtpProtocolHandler methods: diff --git a/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.cpp b/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.cpp index 755fef69991..7a6e341458b 100644 --- a/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.cpp +++ b/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.cpp @@ -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; } diff --git a/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.h b/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.h index c2acb1f5187..4a8775cc94a 100644 --- a/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.h +++ b/netwerk/protocol/ftp/src/nsFtpStreamListenerEvent.h @@ -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; diff --git a/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp b/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp index 5f35f682887..26009fb1558 100644 --- a/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp +++ b/netwerk/protocol/http/src/nsHttpProtocolConnection.cpp @@ -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; } diff --git a/netwerk/protocol/http/src/nsHttpProtocolConnection.h b/netwerk/protocol/http/src/nsHttpProtocolConnection.h index 89498687cb7..e69de29bb2d 100644 --- a/netwerk/protocol/http/src/nsHttpProtocolConnection.h +++ b/netwerk/protocol/http/src/nsHttpProtocolConnection.h @@ -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___ */ diff --git a/netwerk/protocol/http/src/nsHttpProtocolHandler.cpp b/netwerk/protocol/http/src/nsHttpProtocolHandler.cpp index ef3949497ab..095cc213ca1 100644 --- a/netwerk/protocol/http/src/nsHttpProtocolHandler.cpp +++ b/netwerk/protocol/http/src/nsHttpProtocolHandler.cpp @@ -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; diff --git a/netwerk/protocol/http/src/nsHttpProtocolHandler.h b/netwerk/protocol/http/src/nsHttpProtocolHandler.h index b926ed44a7d..99226591138 100644 --- a/netwerk/protocol/http/src/nsHttpProtocolHandler.h +++ b/netwerk/protocol/http/src/nsHttpProtocolHandler.h @@ -49,7 +49,7 @@ public: nsIUrl* *result); NS_IMETHOD NewConnection(nsIUrl* url, nsISupports* eventSink, - PLEventQueue* eventQueue, + nsIEventQueue* eventQueue, nsIProtocolConnection* *result); // nsHttpProtocolHandler methods: diff --git a/netwerk/test/TestFileInput.cpp b/netwerk/test/TestFileInput.cpp index 1208943cb84..352cf16fdc9 100644 --- a/netwerk/test/TestFileInput.cpp +++ b/netwerk/test/TestFileInput.cpp @@ -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; diff --git a/netwerk/test/TestSocketIO.cpp b/netwerk/test/TestSocketIO.cpp index 5b34d4e1476..b785e19bce6 100644 --- a/netwerk/test/TestSocketIO.cpp +++ b/netwerk/test/TestSocketIO.cpp @@ -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; diff --git a/netwerk/test/TestSocketInput.cpp b/netwerk/test/TestSocketInput.cpp index 17a20773fbd..d3060b00478 100644 --- a/netwerk/test/TestSocketInput.cpp +++ b/netwerk/test/TestSocketInput.cpp @@ -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; diff --git a/netwerk/test/nettest.cpp b/netwerk/test/nettest.cpp index 56d04e36523..8254fcf795f 100644 --- a/netwerk/test/nettest.cpp +++ b/netwerk/test/nettest.cpp @@ -24,7 +24,7 @@ #endif #include "plstr.h" -#include "plevent.h" +#include "nsIEventQueue.h" #include "nsIProtocolConnection.h" #include "nsIStreamListener.h"