Revising nsIChannel to allow for overlapped i/o. This consists of three parts:

1. Factoring nsIChannel into a protocol specific part, the nsIChannel, and a socket specific, the nsITransport.
2. Derive the nsIChannel from a nsIRequest.
2. Changes the notification system from necko and the URILoader to pass the nsIRequest interface instead of nsIChannel interface.

This goal stems from wanting to be able to have active AsyncRead and AsyncWrite operations on nsSocketTransport.
This is desired because it would greatly simplify the task of maintaining persistent/reusable socket connections
for FTP, HTTP, and Imap (and potentially other protocols).  The problem with the existing nsIChannel interface is
that it does not allow one to selectively suspend just one of the read or write operations while keeping the other active.

The full details of the change on written up in the netlib newsgroup.

r=darin@netscape.com
sr=rpotts@netscape.com
This commit is contained in:
dougt@netscape.com
2001-02-10 00:16:26 +00:00
parent b762af79b0
commit a70fce6f87
218 changed files with 5596 additions and 6769 deletions

View File

@@ -65,6 +65,8 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static int gKeepRunning = 0;
static PRBool gVerbose = PR_FALSE;
static nsIEventQueue* gEventQ = nsnull;
static PRBool gAskUserForInput = PR_FALSE;
class URLLoadInfo : public nsISupports
{
@@ -164,7 +166,7 @@ TestHTTPEventSink::OnHeadersAvailable(nsISupports* context)
header->GetField(getter_AddRefs(key));
key->ToString(field);
nsCAutoString theField;
theField.AssignWithConversion(field);
theField.AssignWithConversion(field);
printf("\t%s: ", theField.GetBuffer());
header->GetValue(getter_Copies(value));
@@ -192,7 +194,7 @@ TestHTTPEventSink::OnHeadersAvailable(nsISupports* context)
header->GetField(getter_AddRefs(key));
key->ToString(field);
nsCAutoString theField;
theField.AssignWithConversion(field);
theField.AssignWithConversion(field);
printf("\t%s: ", theField.GetBuffer());
header->GetValue(getter_Copies(value));
@@ -262,16 +264,17 @@ protected:
NS_IMPL_ISUPPORTS1(OpenObserver, nsIStreamObserver);
NS_IMETHODIMP
OpenObserver::OnStartRequest(nsIChannel* channel, nsISupports* context)
OpenObserver::OnStartRequest(nsIRequest *request, nsISupports* context)
{
printf("\n+++ OpenObserver::OnStartRequest +++. Context = %p\n", context);
printf("\n+++ OpenObserver::OnStartRequest +++. Context = %p\n", (void*)context);
char* type;
PRInt32 length = -1;
nsresult rv;
rv = channel->GetContentType(&type);
nsCOMPtr<nsIChannel> pChan(do_QueryInterface(context));
rv = pChan->GetContentType(&type);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetContentType failed");
rv = channel->GetContentLength(&length);
rv = pChan->GetContentLength(&length);
NS_ASSERTION(NS_SUCCEEDED(rv), "GetContentLength failed");
printf(" contentType = %s length = %d\n", type, length);
nsCRT::free(type);
@@ -280,12 +283,12 @@ OpenObserver::OnStartRequest(nsIChannel* channel, nsISupports* context)
}
NS_IMETHODIMP
OpenObserver::OnStopRequest(nsIChannel* channel, nsISupports* context,
OpenObserver::OnStopRequest(nsIRequest *request, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg)
{
printf("\n+++ OpenObserver::OnStopRequest (status = %x) +++."
"\tContext = %p\n",
aStatus, context);
aStatus, (void*)context);
return NS_OK;
}
@@ -305,7 +308,7 @@ NS_IMPL_ISUPPORTS(InputTestConsumer,NS_GET_IID(nsIStreamListener));
NS_IMETHODIMP
InputTestConsumer::OnStartRequest(nsIChannel* channel, nsISupports* context)
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
{
URLLoadInfo* info = (URLLoadInfo*)context;
if (info) {
@@ -333,7 +336,7 @@ InputTestConsumer::OnStartRequest(nsIChannel* channel, nsISupports* context)
NS_IMETHODIMP
InputTestConsumer::OnDataAvailable(nsIChannel* channel,
InputTestConsumer::OnDataAvailable(nsIRequest *request,
nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aSourceOffset,
@@ -367,9 +370,31 @@ InputTestConsumer::OnDataAvailable(nsIChannel* channel,
return NS_OK;
}
static void DecrementDestroyHandler(PLEvent *self)
{
PR_DELETE(self);
}
static void* DecrementEventHandler(PLEvent *self)
{
gKeepRunning--;
return nsnull;
}
void FireDecrement()
{
PLEvent *event = PR_NEW(PLEvent);
PL_InitEvent(event,
nsnull,
DecrementEventHandler,
DecrementDestroyHandler);
gEventQ->PostEvent(event);
}
NS_IMETHODIMP
InputTestConsumer::OnStopRequest(nsIChannel* channel, nsISupports* context,
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
nsresult aStatus, const PRUnichar* aStatusArg)
{
URLLoadInfo* info = (URLLoadInfo*)context;
@@ -385,7 +410,7 @@ InputTestConsumer::OnStopRequest(nsIChannel* channel, nsISupports* context,
connectTime = (info->mConnectTime/1000.0)/1000.0;
readTime = ((info->mTotalTime-info->mConnectTime)/1000.0)/1000.0;
nsCOMPtr<nsIHTTPChannel> pHTTPCon(do_QueryInterface(channel));
nsCOMPtr<nsIHTTPChannel> pHTTPCon(do_QueryInterface(request));
if (pHTTPCon) {
pHTTPCon->GetResponseStatus(&httpStatus);
bHTTPURL = PR_TRUE;
@@ -422,7 +447,8 @@ InputTestConsumer::OnStopRequest(nsIChannel* channel, nsISupports* context,
nsCRT::free(location);
}
*/
gKeepRunning -= 1;
FireDecrement();
return NS_OK;
}
@@ -521,9 +547,8 @@ nsresult StartLoadingURL(const char* aUrlString)
return NS_ERROR_OUT_OF_MEMORY;
}
rv = pChannel->AsyncRead(listener, // IStreamListener consumer
info); // ISupports context
rv = pChannel->AsyncOpen(listener, // IStreamListener consumer
info);
if (NS_SUCCEEDED(rv)) {
gKeepRunning += 1;
@@ -580,6 +605,19 @@ nsresult LoadURLsFromFile(char *aFileName)
return NS_OK;
}
nsresult LoadURLFromConsole()
{
char buffer[1024];
printf("Enter URL (\"q\" to start): ");
scanf("%s", buffer);
if (buffer[0]=='q')
gAskUserForInput = PR_FALSE;
else
StartLoadingURL(buffer);
return NS_OK;
}
int
main(int argc, char* argv[])
{
@@ -616,6 +654,7 @@ main(int argc, char* argv[])
if (NS_FAILED(rv)) return rv;
#endif // NECKO
int i;
printf("\nTrying to load:\n");
for (i=1; i<argc; i++) {
@@ -630,11 +669,15 @@ main(int argc, char* argv[])
LoadURLsFromFile(argv[++i]);
continue;
}
if (PL_strcasecmp(argv[i], "-console") == 0) {
gAskUserForInput = PR_TRUE;
continue;
}
printf("\t%s\n", argv[i]);
rv = StartLoadingURL(argv[i]);
}
// Enter the message pump to allow the URL load to proceed.
while ( gKeepRunning ) {
#ifdef WIN32
@@ -656,7 +699,6 @@ main(int argc, char* argv[])
#endif /* XP_UNIX */
#endif /* !WIN32 */
}
NS_ShutdownXPCOM(nsnull);
return rv;
}