Added event queue argument for connection creation. Started http state machine.

This commit is contained in:
warren%netscape.com 1999-04-16 18:00:17 +00:00
Родитель cd87fdd113
Коммит fa42476fae
5 изменённых файлов: 63 добавлений и 15 удалений

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

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

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

@ -26,6 +26,7 @@
#include "nsIFileTransportService.h" // XXX temporary
#include "nsHttpProtocolHandler.h"
#include "nsITransport.h"
#include "nsIByteBufferInputStream.h"
//static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); // XXX temporary
@ -35,7 +36,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
nsHttpProtocolConnection::nsHttpProtocolConnection()
: mHandler(nsnull), mUrl(nsnull), mEventSink(nsnull), mState(UNCONNECTED)
: mHandler(nsnull), mUrl(nsnull), mEventSink(nsnull), mState(UNCONNECTED),
mEventQueue(nsnull)
{
}
@ -71,7 +73,8 @@ nsHttpProtocolConnection::QueryInterface(const nsIID& aIID, void** aInstancePtr)
nsresult
nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
nsHttpProtocolHandler* handler)
nsHttpProtocolHandler* handler,
PLEventQueue* eventQueue)
{
nsresult rv;
@ -82,6 +85,10 @@ nsHttpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink,
NS_ADDREF(mUrl);
rv = eventSink->QueryInterface(nsIHttpEventSink::GetIID(), (void**)&mEventSink);
if (NS_FAILED(rv)) return rv;
mEventQueue = eventQueue;
return rv;
}
@ -147,6 +154,7 @@ nsHttpProtocolConnection::Open(void)
if (NS_FAILED(rv)) return rv;
rv = mHandler->GetTransport(host, port, &mTransport);
mState = CONNECTED;
return rv;
}
@ -199,17 +207,26 @@ NS_IMETHODIMP
nsHttpProtocolConnection::Get(void)
{
nsresult rv;
// NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
// if (NS_FAILED(rv)) return rv;
// XXX temporary:
NS_WITH_SERVICE(nsIFileTransportService, sts, kFileTransportServiceCID, &rv);
if (mState != CONNECTED)
return NS_ERROR_NOT_CONNECTED;
// write the http request to the server:
nsIByteBufferInputStream* in;
rv = NS_NewByteBufferInputStream(&in);
if (NS_FAILED(rv)) return rv;
const char* path = "y:/temp/foo.html";
// rv = sts->AsyncWrite();
// nsITransport* trans;
// rv = sts->AsyncRead(path, context, appEventQueue, this, &trans);
PRUint32 writeCnt;
PRUint32 requestLen = 3;
rv = in->Fill("GET", requestLen, &writeCnt);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(writeCnt == requestLen, "nsIByteBufferInputStream failed");
rv = mTransport->AsyncWrite(in,
NS_STATIC_CAST(nsIProtocolConnection*, this),
mEventQueue, this);
NS_RELEASE(in);
if (NS_FAILED(rv)) return rv;
return rv;
@ -247,8 +264,32 @@ nsHttpProtocolConnection::OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg)
{
// XXX switch from POSTING to GETTING state here, etc.
return NS_ERROR_NOT_IMPLEMENTED;
nsresult rv = NS_OK;
switch (mState) {
case CONNECTED:
if (NS_SUCCEEDED(aStatus)) {
// read the reply
mState = WAITING_REPLY;
rv = mTransport->AsyncRead(NS_STATIC_CAST(nsIProtocolConnection*, this),
mEventQueue, this);
if (NS_FAILED(rv)) return rv;
}
break;
case WAITING_REPLY:
// reply finished
// rv = mHandler->ReleaseTransport(mTransport);
// if (NS_FAILED(rv)) return rv;
mState = UNCONNECTED;
break;
default:
NS_NOTREACHED("bad state");
break;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////

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

@ -70,14 +70,16 @@ public:
virtual ~nsHttpProtocolConnection();
nsresult Init(nsIUrl* url, nsISupports* eventSink,
nsHttpProtocolHandler* handler);
nsHttpProtocolHandler* handler,
PLEventQueue* eventQueue);
nsresult GetExistingTransport(const char* host, PRInt32 port,
nsITransport* *result);
enum State {
UNCONNECTED,
POSTING,
CONNECTED
CONNECTED,
WAITING_REPLY
};
protected:
@ -86,6 +88,7 @@ protected:
nsIHttpEventSink* mEventSink;
State mState;
nsITransport* mTransport;
PLEventQueue* mEventQueue;
};
#endif /* nsHttpProtocolConnection_h___ */

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

@ -110,13 +110,14 @@ nsHttpProtocolHandler::NewUrl(const char* aSpec,
NS_IMETHODIMP
nsHttpProtocolHandler::NewConnection(nsIUrl* url,
nsISupports* eventSink,
PLEventQueue* eventQueue,
nsIProtocolConnection* *result)
{
nsresult rv;
nsHttpProtocolConnection* connection = new nsHttpProtocolConnection();
if (connection == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
rv = connection->Init(url, eventSink, this);
rv = connection->Init(url, eventSink, this, eventQueue);
if (NS_FAILED(rv)) {
delete connection;
return rv;

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

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