зеркало из https://github.com/mozilla/pjs.git
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:
Родитель
fd79ce63e6
Коммит
943c469643
|
@ -20,7 +20,7 @@
|
||||||
#define nsIProtocolHandler_h___
|
#define nsIProtocolHandler_h___
|
||||||
|
|
||||||
#include "nsISupports.h"
|
#include "nsISupports.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
|
|
||||||
class nsIConnectionGroup;
|
class nsIConnectionGroup;
|
||||||
class nsIUrl;
|
class nsIUrl;
|
||||||
|
@ -59,7 +59,7 @@ public:
|
||||||
|
|
||||||
NS_IMETHOD NewConnection(nsIUrl* url,
|
NS_IMETHOD NewConnection(nsIUrl* url,
|
||||||
nsISupports* eventSink,
|
nsISupports* eventSink,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIProtocolConnection* *result) = 0;
|
nsIProtocolConnection* *result) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,8 @@
|
||||||
#define nsIStreamListener_h___
|
#define nsIStreamListener_h___
|
||||||
|
|
||||||
#include "nsIStreamObserver.h"
|
#include "nsIStreamObserver.h"
|
||||||
#include "plevent.h"
|
#include "nsIOutputStream.h"
|
||||||
|
#include "nsIEventQueue.h"
|
||||||
|
|
||||||
class nsIInputStream;
|
class nsIInputStream;
|
||||||
|
|
||||||
|
@ -59,7 +60,7 @@ public:
|
||||||
// the data on the other thread.
|
// the data on the other thread.
|
||||||
extern nsresult
|
extern nsresult
|
||||||
NS_NewAsyncStreamListener(nsIStreamListener* *result,
|
NS_NewAsyncStreamListener(nsIStreamListener* *result,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIStreamListener* receiver);
|
nsIStreamListener* receiver);
|
||||||
|
|
||||||
// A synchronous stream listener pushes data through a pipe that ends up
|
// A synchronous stream listener pushes data through a pipe that ends up
|
||||||
|
@ -68,4 +69,8 @@ extern nsresult
|
||||||
NS_NewSyncStreamListener(nsIStreamListener* *listener,
|
NS_NewSyncStreamListener(nsIStreamListener* *listener,
|
||||||
nsIInputStream* *inStream);
|
nsIInputStream* *inStream);
|
||||||
|
|
||||||
|
extern nsresult
|
||||||
|
NS_NewSyncOutStreamListener(nsIStreamListener* *listener,
|
||||||
|
nsIOutputStream* *outStream);
|
||||||
|
|
||||||
#endif /* nsIIStreamListener_h___ */
|
#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 \
|
nsConnectionGroup.cpp \
|
||||||
nsAsyncStreamListener.cpp \
|
nsAsyncStreamListener.cpp \
|
||||||
nsSyncStreamListener.cpp \
|
nsSyncStreamListener.cpp \
|
||||||
|
nsSyncOutStreamListener.cpp \
|
||||||
nsFileTransport.cpp \
|
nsFileTransport.cpp \
|
||||||
nsFileTransportService.cpp \
|
nsFileTransportService.cpp \
|
||||||
nsSocketTransport.cpp \
|
nsSocketTransport.cpp \
|
||||||
|
|
|
@ -33,6 +33,7 @@ CPP_OBJS = \
|
||||||
.\$(OBJDIR)\nsConnectionGroup.obj \
|
.\$(OBJDIR)\nsConnectionGroup.obj \
|
||||||
.\$(OBJDIR)\nsAsyncStreamListener.obj \
|
.\$(OBJDIR)\nsAsyncStreamListener.obj \
|
||||||
.\$(OBJDIR)\nsSyncStreamListener.obj \
|
.\$(OBJDIR)\nsSyncStreamListener.obj \
|
||||||
|
.\$(OBJDIR)\nsSyncOutStreamListener.obj \
|
||||||
.\$(OBJDIR)\nsFileTransport.obj \
|
.\$(OBJDIR)\nsFileTransport.obj \
|
||||||
.\$(OBJDIR)\nsFileTransportService.obj \
|
.\$(OBJDIR)\nsFileTransportService.obj \
|
||||||
.\$(OBJDIR)\nsSocketTransport.obj \
|
.\$(OBJDIR)\nsSocketTransport.obj \
|
||||||
|
|
|
@ -34,10 +34,12 @@ public:
|
||||||
nsIString* aMsg);
|
nsIString* aMsg);
|
||||||
|
|
||||||
// nsAsyncStreamObserver methods:
|
// nsAsyncStreamObserver methods:
|
||||||
nsAsyncStreamObserver(PLEventQueue* aEventQ)
|
nsAsyncStreamObserver(nsIEventQueue* aEventQ)
|
||||||
: mEventQueue(aEventQ), mReceiver(nsnull), mStatus(NS_OK)
|
: mReceiver(nsnull), mStatus(NS_OK)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
mEventQueue = aEventQ;
|
||||||
|
NS_IF_ADDREF(mEventQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~nsAsyncStreamObserver();
|
virtual ~nsAsyncStreamObserver();
|
||||||
|
@ -52,7 +54,7 @@ public:
|
||||||
void SetStatus(nsresult value) { mStatus = value; }
|
void SetStatus(nsresult value) { mStatus = value; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PLEventQueue* mEventQueue;
|
nsIEventQueue* mEventQueue;
|
||||||
nsIStreamObserver* mReceiver;
|
nsIStreamObserver* mReceiver;
|
||||||
nsresult mStatus;
|
nsresult mStatus;
|
||||||
};
|
};
|
||||||
|
@ -83,7 +85,7 @@ public:
|
||||||
PRUint32 aLength);
|
PRUint32 aLength);
|
||||||
|
|
||||||
// nsAsyncStreamListener methods:
|
// nsAsyncStreamListener methods:
|
||||||
nsAsyncStreamListener(PLEventQueue* aEventQ)
|
nsAsyncStreamListener(nsIEventQueue* aEventQ)
|
||||||
: nsAsyncStreamObserver(aEventQ) {}
|
: nsAsyncStreamObserver(aEventQ) {}
|
||||||
|
|
||||||
void Init(nsIStreamListener* aListener) {
|
void Init(nsIStreamListener* aListener) {
|
||||||
|
@ -101,7 +103,7 @@ public:
|
||||||
nsISupports* context);
|
nsISupports* context);
|
||||||
virtual ~nsStreamListenerEvent();
|
virtual ~nsStreamListenerEvent();
|
||||||
|
|
||||||
nsresult Fire(PLEventQueue* aEventQ);
|
nsresult Fire(nsIEventQueue* aEventQ);
|
||||||
|
|
||||||
NS_IMETHOD HandleEvent() = 0;
|
NS_IMETHOD HandleEvent() = 0;
|
||||||
|
|
||||||
|
@ -149,15 +151,15 @@ void PR_CALLBACK nsStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
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,
|
PL_InitEvent(this, nsnull,
|
||||||
(PLHandleEventProc) nsStreamListenerEvent::HandlePLEvent,
|
(PLHandleEventProc) nsStreamListenerEvent::HandlePLEvent,
|
||||||
(PLDestroyEventProc) nsStreamListenerEvent::DestroyPLEvent);
|
(PLDestroyEventProc) nsStreamListenerEvent::DestroyPLEvent);
|
||||||
|
|
||||||
PRStatus status = PL_PostEvent(aEventQueue, this);
|
PRStatus status = aEventQueue->PostEvent(this);
|
||||||
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +168,7 @@ nsStreamListenerEvent::Fire(PLEventQueue* aEventQueue)
|
||||||
nsAsyncStreamObserver::~nsAsyncStreamObserver()
|
nsAsyncStreamObserver::~nsAsyncStreamObserver()
|
||||||
{
|
{
|
||||||
NS_RELEASE(mReceiver);
|
NS_RELEASE(mReceiver);
|
||||||
|
NS_IF_RELEASE(mEventQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsAsyncStreamObserver, nsIStreamObserver::GetIID());
|
NS_IMPL_ISUPPORTS(nsAsyncStreamObserver, nsIStreamObserver::GetIID());
|
||||||
|
@ -372,7 +375,7 @@ nsAsyncStreamObserver::OnStopBinding(nsISupports* context,
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
|
NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIStreamObserver* receiver)
|
nsIStreamObserver* receiver)
|
||||||
{
|
{
|
||||||
nsAsyncStreamObserver* l =
|
nsAsyncStreamObserver* l =
|
||||||
|
@ -387,7 +390,7 @@ NS_NewAsyncStreamObserver(nsIStreamObserver* *result,
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
NS_NewAsyncStreamListener(nsIStreamListener* *result,
|
NS_NewAsyncStreamListener(nsIStreamListener* *result,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIStreamListener* receiver)
|
nsIStreamListener* receiver)
|
||||||
{
|
{
|
||||||
nsAsyncStreamListener* l =
|
nsAsyncStreamListener* l =
|
||||||
|
|
|
@ -170,7 +170,7 @@ nsFileTransport::Resume(void)
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsFileTransport::AsyncRead(nsISupports* context,
|
nsFileTransport::AsyncRead(nsISupports* context,
|
||||||
PLEventQueue* appEventQueue,
|
nsIEventQueue* appEventQueue,
|
||||||
nsIStreamListener* listener)
|
nsIStreamListener* listener)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
@ -191,7 +191,7 @@ nsFileTransport::AsyncRead(nsISupports* context,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsFileTransport::AsyncWrite(nsIInputStream* fromStream,
|
nsFileTransport::AsyncWrite(nsIInputStream* fromStream,
|
||||||
nsISupports* context,
|
nsISupports* context,
|
||||||
PLEventQueue* appEventQueue,
|
nsIEventQueue* appEventQueue,
|
||||||
nsIStreamObserver* observer)
|
nsIStreamObserver* observer)
|
||||||
{
|
{
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "nsITransport.h"
|
#include "nsITransport.h"
|
||||||
#include "nsIThread.h"
|
#include "nsIThread.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
#include "prmon.h"
|
#include "prmon.h"
|
||||||
|
|
||||||
class nsFileTransportService;
|
class nsFileTransportService;
|
||||||
|
@ -42,11 +42,11 @@ public:
|
||||||
|
|
||||||
// nsITransport methods:
|
// nsITransport methods:
|
||||||
NS_IMETHOD AsyncRead(nsISupports* context,
|
NS_IMETHOD AsyncRead(nsISupports* context,
|
||||||
PLEventQueue* appEventQueue,
|
nsIEventQueue* appEventQueue,
|
||||||
nsIStreamListener* listener);
|
nsIStreamListener* listener);
|
||||||
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
|
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
|
||||||
nsISupports* context,
|
nsISupports* context,
|
||||||
PLEventQueue* appEventQueue,
|
nsIEventQueue* appEventQueue,
|
||||||
nsIStreamObserver* observer);
|
nsIStreamObserver* observer);
|
||||||
NS_IMETHOD OpenInputStream(nsIInputStream* *result);
|
NS_IMETHOD OpenInputStream(nsIInputStream* *result);
|
||||||
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result);
|
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result);
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
#include "nsISupportsArray.h"
|
#include "nsISupportsArray.h"
|
||||||
#include "nsIThread.h"
|
#include "nsIThread.h"
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
|
|
||||||
class nsFileTransport;
|
class nsFileTransport;
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
#include <ctype.h> // for isalpha
|
#include <ctype.h> // for isalpha
|
||||||
|
|
||||||
static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
|
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);
|
rv = GetProtocolHandler(scheme, &handler);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
PLEventQueue* eventQ;
|
nsIEventQueue* eventQ;
|
||||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &eventQ);
|
||||||
|
|
|
@ -651,7 +651,7 @@ nsSocketTransport::Resume(void)
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSocketTransport::AsyncRead(nsISupports* aContext,
|
nsSocketTransport::AsyncRead(nsISupports* aContext,
|
||||||
PLEventQueue* aAppEventQueue,
|
nsIEventQueue* aAppEventQueue,
|
||||||
nsIStreamListener* aListener)
|
nsIStreamListener* aListener)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
@ -688,7 +688,7 @@ nsSocketTransport::AsyncRead(nsISupports* aContext,
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSocketTransport::AsyncWrite(nsIInputStream* aFromStream,
|
nsSocketTransport::AsyncWrite(nsIInputStream* aFromStream,
|
||||||
nsISupports* aContext,
|
nsISupports* aContext,
|
||||||
PLEventQueue* aAppEventQueue,
|
nsIEventQueue* aAppEventQueue,
|
||||||
nsIStreamObserver* aObserver)
|
nsIStreamObserver* aObserver)
|
||||||
{
|
{
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
@ -756,10 +756,11 @@ nsSocketTransport::OpenInputStream(nsIInputStream* *result)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
|
nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
|
||||||
{
|
{
|
||||||
#if 0
|
|
||||||
nsresult rv = NS_OK;
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
if (eSocketOperation_None != mOperation) {
|
if (eSocketOperation_None != mOperation) {
|
||||||
|
@ -767,15 +768,26 @@ nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
|
||||||
rv = NS_ERROR_FAILURE;
|
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)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
NS_IF_RELEASE(mWriteStream);
|
//NS_IF_RELEASE(mWriteStream);
|
||||||
mWriteStream = nsnull;
|
//mWriteStream = nsnull;
|
||||||
|
|
||||||
NS_IF_RELEASE(mContext);
|
NS_IF_RELEASE(mContext);
|
||||||
mContext = nsnull;
|
mContext = nsnull;
|
||||||
|
|
||||||
NS_IF_RELEASE(mListener);
|
NS_IF_RELEASE(mListener);
|
||||||
rv = NS_NewSyncStreamObserver(&mListener, result);
|
rv = NS_NewSyncOutStreamListener(&mListener, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
@ -784,8 +796,6 @@ nsSocketTransport::OpenOutputStream(nsIOutputStream* *result)
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
#endif
|
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,11 +66,11 @@ public:
|
||||||
|
|
||||||
// nsITransport methods:
|
// nsITransport methods:
|
||||||
NS_IMETHOD AsyncRead(nsISupports* context,
|
NS_IMETHOD AsyncRead(nsISupports* context,
|
||||||
PLEventQueue* appEventQueue,
|
nsIEventQueue* appEventQueue,
|
||||||
nsIStreamListener* listener);
|
nsIStreamListener* listener);
|
||||||
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
|
NS_IMETHOD AsyncWrite(nsIInputStream* fromStream,
|
||||||
nsISupports* context,
|
nsISupports* context,
|
||||||
PLEventQueue* appEventQueue,
|
nsIEventQueue* appEventQueue,
|
||||||
nsIStreamObserver* observer);
|
nsIStreamObserver* observer);
|
||||||
NS_IMETHOD OpenInputStream(nsIInputStream* *result);
|
NS_IMETHOD OpenInputStream(nsIInputStream* *result);
|
||||||
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result);
|
NS_IMETHOD OpenOutputStream(nsIOutputStream* *result);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
|
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
|
|
@ -55,11 +55,12 @@ nsFtpConnectionThread::QueryInterface(const nsIID& aIID, void** aInstancePtr) {
|
||||||
return NS_NOINTERFACE;
|
return NS_NOINTERFACE;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsFtpConnectionThread::nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamListener* aListener) {
|
nsFtpConnectionThread::nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamListener* aListener) {
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
mEventQueue = aEventQ; // whoever creates us must provide an event queue
|
mEventQueue = aEventQ; // whoever creates us must provide an event queue
|
||||||
// so we can post events back to them.
|
// so we can post events back to them.
|
||||||
|
NS_IF_ADDREF(mEventQueue);
|
||||||
mListener = aListener;
|
mListener = aListener;
|
||||||
NS_IF_ADDREF(mListener);
|
NS_IF_ADDREF(mListener);
|
||||||
mAction = GET;
|
mAction = GET;
|
||||||
|
@ -72,6 +73,7 @@ nsFtpConnectionThread::nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamLis
|
||||||
|
|
||||||
nsFtpConnectionThread::~nsFtpConnectionThread() {
|
nsFtpConnectionThread::~nsFtpConnectionThread() {
|
||||||
NS_IF_RELEASE(mListener);
|
NS_IF_RELEASE(mListener);
|
||||||
|
NS_IF_RELEASE(mEventQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include "nsIString.h"
|
#include "nsIString.h"
|
||||||
|
|
||||||
#include "nsString2.h"
|
#include "nsString2.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
|
|
||||||
#include "time.h" // XXX should probably be using PRTime stuff
|
#include "time.h" // XXX should probably be using PRTime stuff
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ class nsFtpConnectionThread : public nsIRunnable {
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamListener *aListener);
|
nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamListener *aListener);
|
||||||
virtual ~nsFtpConnectionThread();
|
virtual ~nsFtpConnectionThread();
|
||||||
|
|
||||||
// nsIRunnable method
|
// nsIRunnable method
|
||||||
|
@ -132,7 +132,7 @@ private:
|
||||||
|
|
||||||
// Private members
|
// Private members
|
||||||
|
|
||||||
PLEventQueue* mEventQueue; // used to communicate outside this thread
|
nsIEventQueue* mEventQueue; // used to communicate outside this thread
|
||||||
nsIUrl* mUrl;
|
nsIUrl* mUrl;
|
||||||
|
|
||||||
FTP_STATE mState; // the current state
|
FTP_STATE mState; // the current state
|
||||||
|
|
|
@ -23,10 +23,12 @@
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIByteBufferInputStream.h"
|
#include "nsIByteBufferInputStream.h"
|
||||||
#include "nsFtpConnectionThread.h"
|
#include "nsFtpConnectionThread.h"
|
||||||
|
#include "nsIEventQueueService.h"
|
||||||
|
|
||||||
#include "prprf.h" // PR_sscanf
|
#include "prprf.h" // PR_sscanf
|
||||||
|
|
||||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
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
|
// There are actually two transport connections established for an
|
||||||
// ftp connection. One is used for the command channel , and
|
// ftp connection. One is used for the command channel , and
|
||||||
|
@ -39,13 +41,22 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
nsFtpProtocolConnection::nsFtpProtocolConnection()
|
nsFtpProtocolConnection::nsFtpProtocolConnection()
|
||||||
: mUrl(nsnull), mConnected(PR_FALSE), mListener(nsnull) {
|
: 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();
|
NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsFtpProtocolConnection::~nsFtpProtocolConnection() {
|
nsFtpProtocolConnection::~nsFtpProtocolConnection() {
|
||||||
NS_IF_RELEASE(mUrl);
|
NS_IF_RELEASE(mUrl);
|
||||||
NS_IF_RELEASE(mListener);
|
NS_IF_RELEASE(mListener);
|
||||||
|
NS_IF_RELEASE(mEventQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsFtpProtocolConnection);
|
NS_IMPL_ADDREF(nsFtpProtocolConnection);
|
||||||
|
@ -71,7 +82,7 @@ nsFtpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsFtpProtocolConnection::Init(nsIUrl* aUrl, nsISupports* aEventSink, PLEventQueue* aEventQueue) {
|
nsFtpProtocolConnection::Init(nsIUrl* aUrl, nsISupports* aEventSink, nsIEventQueue* aEventQueue) {
|
||||||
|
|
||||||
if (mConnected)
|
if (mConnected)
|
||||||
return NS_ERROR_NOT_IMPLEMENTED;
|
return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
@ -80,6 +91,7 @@ nsFtpProtocolConnection::Init(nsIUrl* aUrl, nsISupports* aEventSink, PLEventQueu
|
||||||
NS_ADDREF(mUrl);
|
NS_ADDREF(mUrl);
|
||||||
|
|
||||||
mEventQueue = aEventQueue;
|
mEventQueue = aEventQueue;
|
||||||
|
NS_IF_ADDREF(mEventQueue);
|
||||||
|
|
||||||
return NS_OK;
|
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
|
NS_IMETHODIMP
|
||||||
nsFtpProtocolHandler::NewConnection(nsIUrl* url,
|
nsFtpProtocolHandler::NewConnection(nsIUrl* url,
|
||||||
nsISupports* eventSink,
|
nsISupports* eventSink,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIProtocolConnection* *result)
|
nsIProtocolConnection* *result)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
nsIUrl* *result);
|
nsIUrl* *result);
|
||||||
NS_IMETHOD NewConnection(nsIUrl* url,
|
NS_IMETHOD NewConnection(nsIUrl* url,
|
||||||
nsISupports* eventSink,
|
nsISupports* eventSink,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIProtocolConnection* *result);
|
nsIProtocolConnection* *result);
|
||||||
|
|
||||||
// nsFtpProtocolHandler methods:
|
// nsFtpProtocolHandler methods:
|
||||||
|
|
|
@ -57,15 +57,15 @@ void PR_CALLBACK nsFtpStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
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,
|
PL_InitEvent(this, nsnull,
|
||||||
(PLHandleEventProc) nsFtpStreamListenerEvent::HandlePLEvent,
|
(PLHandleEventProc) nsFtpStreamListenerEvent::HandlePLEvent,
|
||||||
(PLDestroyEventProc) nsFtpStreamListenerEvent::DestroyPLEvent);
|
(PLDestroyEventProc) nsFtpStreamListenerEvent::DestroyPLEvent);
|
||||||
|
|
||||||
PRStatus status = PL_PostEvent(aEventQueue, this);
|
PRStatus status = aEventQueue->PostEvent(this);
|
||||||
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
|
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
#include "nscore.h"
|
#include "nscore.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ public:
|
||||||
nsFtpStreamListenerEvent(nsIStreamListener* listener, nsISupports* context);
|
nsFtpStreamListenerEvent(nsIStreamListener* listener, nsISupports* context);
|
||||||
virtual ~nsFtpStreamListenerEvent();
|
virtual ~nsFtpStreamListenerEvent();
|
||||||
|
|
||||||
nsresult Fire(PLEventQueue* aEventQ);
|
nsresult Fire(nsIEventQueue* aEventQ);
|
||||||
|
|
||||||
NS_IMETHOD HandleEvent() = 0;
|
NS_IMETHOD HandleEvent() = 0;
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ nsHttpProtocolConnection::~nsHttpProtocolConnection()
|
||||||
NS_IF_RELEASE(mHandler);
|
NS_IF_RELEASE(mHandler);
|
||||||
NS_IF_RELEASE(mUrl);
|
NS_IF_RELEASE(mUrl);
|
||||||
NS_IF_RELEASE(mEventSink);
|
NS_IF_RELEASE(mEventSink);
|
||||||
|
NS_IF_RELEASE(mEventQueue);
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ADDREF(nsHttpProtocolConnection);
|
NS_IMPL_ADDREF(nsHttpProtocolConnection);
|
||||||
|
@ -73,7 +74,7 @@ nsHttpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
nsresult
|
nsresult
|
||||||
nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
|
nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
|
||||||
nsHttpProtocolHandler* handler,
|
nsHttpProtocolHandler* handler,
|
||||||
PLEventQueue* eventQueue)
|
nsIEventQueue* eventQueue)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
||||||
|
@ -87,6 +88,7 @@ nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
mEventQueue = eventQueue;
|
mEventQueue = eventQueue;
|
||||||
|
NS_IF_ADDREF(mEventQueue);
|
||||||
|
|
||||||
return rv;
|
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
|
NS_IMETHODIMP
|
||||||
nsHttpProtocolHandler::NewConnection(nsIUrl* url,
|
nsHttpProtocolHandler::NewConnection(nsIUrl* url,
|
||||||
nsISupports* eventSink,
|
nsISupports* eventSink,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIProtocolConnection* *result)
|
nsIProtocolConnection* *result)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
nsIUrl* *result);
|
nsIUrl* *result);
|
||||||
NS_IMETHOD NewConnection(nsIUrl* url,
|
NS_IMETHOD NewConnection(nsIUrl* url,
|
||||||
nsISupports* eventSink,
|
nsISupports* eventSink,
|
||||||
PLEventQueue* eventQueue,
|
nsIEventQueue* eventQueue,
|
||||||
nsIProtocolConnection* *result);
|
nsIProtocolConnection* *result);
|
||||||
|
|
||||||
// nsHttpProtocolHandler methods:
|
// nsHttpProtocolHandler methods:
|
||||||
|
|
|
@ -21,7 +21,8 @@
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
#include "nsIThread.h"
|
#include "nsIThread.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
|
#include "nsIEventQueueService.h"
|
||||||
#include "prinrval.h"
|
#include "prinrval.h"
|
||||||
#include "prmon.h"
|
#include "prmon.h"
|
||||||
#include "prio.h"
|
#include "prio.h"
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
|
|
||||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||||
|
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUE_CID);
|
||||||
|
|
||||||
PRIntervalTime gDuration = 0;
|
PRIntervalTime gDuration = 0;
|
||||||
PRUint32 gVolume = 0;
|
PRUint32 gVolume = 0;
|
||||||
|
@ -53,7 +55,13 @@ public:
|
||||||
PR_ExitMonitor(mMonitor);
|
PR_ExitMonitor(mMonitor);
|
||||||
|
|
||||||
// printf("running\n");
|
// printf("running\n");
|
||||||
PL_EventLoop(mEventQueue);
|
|
||||||
|
// event loop
|
||||||
|
mEventQueue->ProcessPendingEvents();
|
||||||
|
|
||||||
|
while (PR_TRUE) {
|
||||||
|
|
||||||
|
}
|
||||||
// printf("quitting\n");
|
// printf("quitting\n");
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
@ -67,17 +75,23 @@ public:
|
||||||
|
|
||||||
virtual ~nsReader() {
|
virtual ~nsReader() {
|
||||||
NS_IF_RELEASE(mThread);
|
NS_IF_RELEASE(mThread);
|
||||||
|
NS_IF_RELEASE(mEventQueue);
|
||||||
PR_DestroyMonitor(mMonitor);
|
PR_DestroyMonitor(mMonitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult Init(nsIThread* thread) {
|
nsresult Init(nsIThread* thread) {
|
||||||
|
nsresult rv;
|
||||||
mThread = thread;
|
mThread = thread;
|
||||||
NS_ADDREF(mThread);
|
NS_ADDREF(mThread);
|
||||||
PRThread* prthread;
|
PRThread* prthread;
|
||||||
thread->GetPRThread(&prthread);
|
thread->GetPRThread(&prthread);
|
||||||
PR_EnterMonitor(mMonitor);
|
PR_EnterMonitor(mMonitor);
|
||||||
mEventQueue = PL_CreateEventQueue("runner event loop",
|
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
||||||
prthread);
|
if (NS_SUCCEEDED(rv)) {
|
||||||
|
rv = eventQService->GetThreadEventQueue(PR_CurrentThread(), &mEventQueue);
|
||||||
|
}
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
// wake up event loop
|
// wake up event loop
|
||||||
PR_Notify(mMonitor);
|
PR_Notify(mMonitor);
|
||||||
PR_ExitMonitor(mMonitor);
|
PR_ExitMonitor(mMonitor);
|
||||||
|
@ -85,7 +99,7 @@ public:
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
PLEventQueue* GetEventQueue() { return mEventQueue; }
|
nsIEventQueue* GetEventQueue() { return mEventQueue; }
|
||||||
|
|
||||||
NS_IMETHOD OnStartBinding(nsISupports* context) {
|
NS_IMETHOD OnStartBinding(nsISupports* context) {
|
||||||
PR_EnterMonitor(mMonitor);
|
PR_EnterMonitor(mMonitor);
|
||||||
|
@ -135,7 +149,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PLEventQueue* mEventQueue;
|
nsIEventQueue* mEventQueue;
|
||||||
PRIntervalTime mStartTime;
|
PRIntervalTime mStartTime;
|
||||||
nsIThread* mThread;
|
nsIThread* mThread;
|
||||||
|
|
||||||
|
|
|
@ -46,10 +46,11 @@
|
||||||
|
|
||||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||||
|
static NS_DEFINE_IID(kEventQueueCID, NS_EVENTQUEUE_CID);
|
||||||
|
|
||||||
static PRTime gElapsedTime;
|
static PRTime gElapsedTime;
|
||||||
static int gKeepRunning = 1;
|
static int gKeepRunning = 1;
|
||||||
static PLEventQueue* gEventQ = nsnull;
|
static nsIEventQueue* gEventQ = nsnull;
|
||||||
|
|
||||||
class InputTestConsumer : public nsIStreamListener
|
class InputTestConsumer : public nsIStreamListener
|
||||||
{
|
{
|
||||||
|
@ -208,6 +209,7 @@ main(int argc, char* argv[])
|
||||||
|
|
||||||
// XXX why do I have to do this?!
|
// XXX why do I have to do this?!
|
||||||
nsComponentManager::RegisterComponent(kEventQueueServiceCID, NULL, NULL, XPCOM_DLL, PR_FALSE, PR_FALSE);
|
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,
|
rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup,
|
||||||
"components");
|
"components");
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
|
@ -151,7 +151,7 @@ main(int argc, char* argv[])
|
||||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
|
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueServiceCID, &rv);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
PLEventQueue* eventQ;
|
nsIEventQueue* eventQ;
|
||||||
rv = eventQService->CreateThreadEventQueue();
|
rv = eventQService->CreateThreadEventQueue();
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "plstr.h"
|
#include "plstr.h"
|
||||||
#include "plevent.h"
|
#include "nsIEventQueue.h"
|
||||||
|
|
||||||
#include "nsIProtocolConnection.h"
|
#include "nsIProtocolConnection.h"
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
|
|
Загрузка…
Ссылка в новой задаче