Ported to the new nsPipe2 implementation.

This commit is contained in:
warren%netscape.com 1999-08-27 10:33:37 +00:00
Родитель 8cfa3fd4d4
Коммит 184fdb8f91
12 изменённых файлов: 201 добавлений и 61 удалений

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

@ -31,6 +31,7 @@
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIPipe.h" #include "nsIPipe.h"
#define NSPIPE2
// //
// This is the size of the global buffer used by all nsSocketTransport // This is the size of the global buffer used by all nsSocketTransport

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

@ -20,7 +20,7 @@
#include "nsCRT.h" #include "nsCRT.h"
#include "nsIBufferInputStream.h" #include "nsIBufferInputStream.h"
#include "nsIBufferOutputStream.h" #include "nsIBufferOutputStream.h"
#include "nsIBuffer.h" #include "nsIPipe.h"
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -61,8 +61,9 @@ nsSyncStreamListener::Init(nsIInputStream* *result)
nsresult rv; nsresult rv;
nsIBufferInputStream* in; nsIBufferInputStream* in;
rv = NS_NewPipe(&in, &mOutputStream, NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE, rv = NS_NewPipe(&in, &mOutputStream, nsnull,
NS_SYNC_STREAM_LISTENER_BUFFER_SIZE, PR_TRUE, nsnull); NS_SYNC_STREAM_LISTENER_SEGMENT_SIZE,
NS_SYNC_STREAM_LISTENER_BUFFER_SIZE);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*result = in; *result = in;

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

@ -110,7 +110,7 @@ nsFileChannel::Init(nsFileProtocolHandler* handler,
return NS_ERROR_OUT_OF_MEMORY; return NS_ERROR_OUT_OF_MEMORY;
if (getter) { if (getter) {
rv = getter->GetEventSink(verb, nsCOMTypeInfo<nsIStreamListener>::GetIID(), (nsISupports**)&mListener); (void)getter->GetEventSink(verb, nsCOMTypeInfo<nsIStreamListener>::GetIID(), (nsISupports**)&mListener);
// ignore the failure -- we can live without having an event sink // ignore the failure -- we can live without having an event sink
} }
@ -303,8 +303,9 @@ nsFileChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
return NS_ERROR_FAILURE; // XXX probably need NS_BASE_STREAM_FILE_NOT_FOUND or something return NS_ERROR_FAILURE; // XXX probably need NS_BASE_STREAM_FILE_NOT_FOUND or something
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream, rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
this, // nsIPipeObserver
NS_FILE_TRANSPORT_SEGMENT_SIZE, NS_FILE_TRANSPORT_SEGMENT_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE, PR_TRUE, this); NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
#if 0 #if 0
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv); NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
@ -431,8 +432,9 @@ nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream, rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
this, // nsIPipeObserver
NS_FILE_TRANSPORT_SEGMENT_SIZE, NS_FILE_TRANSPORT_SEGMENT_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE, PR_TRUE, this); NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = mBufferOutputStream->SetNonBlocking(PR_TRUE); rv = mBufferOutputStream->SetNonBlocking(PR_TRUE);
@ -649,7 +651,7 @@ nsFileChannel::Process(void)
mAmount -= amt; // subtract off the amount we just read from mAmount. mAmount -= amt; // subtract off the amount we just read from mAmount.
if (NS_FAILED(mStatus)) goto error; if (NS_FAILED(mStatus)) goto error;
if (mStatus == NS_BASE_STREAM_WOULD_BLOCK || amt == 0) { if (mStatus == NS_BASE_STREAM_WOULD_BLOCK || amt == 0) {
// Our nsIBufferObserver will have been called from WriteFrom // Our nsIPipeObserver will have been called from WriteFrom
// which in turn calls Suspend, so we should end up suspending // which in turn calls Suspend, so we should end up suspending
// this file channel. // this file channel.
Suspend(); Suspend();
@ -753,23 +755,23 @@ nsFileChannel::Process(void)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// nsIBufferObserver methods: // nsIPipeObserver methods:
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP NS_IMETHODIMP
nsFileChannel::OnFull(nsIBuffer* buffer) nsFileChannel::OnFull(nsIPipe* pipe)
{ {
return Suspend(); return Suspend();
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFileChannel::OnWrite(nsIBuffer* aBuffer, PRUint32 aCount) nsFileChannel::OnWrite(nsIPipe* pipe, PRUint32 aCount)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsFileChannel::OnEmpty(nsIBuffer* buffer) nsFileChannel::OnEmpty(nsIPipe* pipe)
{ {
return Resume(); return Resume();
} }
@ -1094,6 +1096,7 @@ nsFileChannel::Execute(const char *args)
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
nsresult nsresult
nsFileChannel::CreateFileChannelFromFileSpec(nsFileSpec& spec, nsIFileChannel **result) nsFileChannel::CreateFileChannelFromFileSpec(nsFileSpec& spec, nsIFileChannel **result)
{ {

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

@ -33,7 +33,7 @@
#include "nsFileSpec.h" #include "nsFileSpec.h"
#include "prlock.h" #include "prlock.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
#include "nsIBuffer.h" #include "nsIPipe.h"
#include "nsILoadGroup.h" #include "nsILoadGroup.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
@ -47,60 +47,28 @@ class nsIEventSinkGetter;
class nsIStreamListener; class nsIStreamListener;
class nsFileProtocolHandler; class nsFileProtocolHandler;
class nsIBaseStream; class nsIBaseStream;
class nsIBuffer;
class nsIBufferInputStream; class nsIBufferInputStream;
class nsIBufferOutputStream; class nsIBufferOutputStream;
class nsFileChannel : public nsIFileChannel, class nsFileChannel : public nsIFileChannel,
public nsIRunnable, public nsIRunnable,
public nsIBufferObserver, public nsIPipeObserver,
public nsIStreamListener public nsIStreamListener
{ {
public: public:
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////
// from nsIRequest:
NS_DECL_NSIREQUEST NS_DECL_NSIREQUEST
////////////////////////////////////////////////////////////////////////////
// from nsIChannel:
NS_DECL_NSICHANNEL NS_DECL_NSICHANNEL
////////////////////////////////////////////////////////////////////////////
// from nsIFileChannel:
NS_DECL_NSIFILECHANNEL NS_DECL_NSIFILECHANNEL
NS_DECL_NSIPIPEOBSERVER
NS_DECL_NSISTREAMOBSERVER
NS_DECL_NSISTREAMLISTENER
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// nsIRunnable methods: // nsIRunnable methods:
NS_IMETHOD Run(void); NS_IMETHOD Run(void);
////////////////////////////////////////////////////////////////////////////
// nsIBufferObserver:
NS_IMETHOD OnFull(nsIBuffer* buffer);
NS_IMETHOD OnWrite(nsIBuffer* aBuffer, PRUint32 aCount);
NS_IMETHOD OnEmpty(nsIBuffer* buffer);
////////////////////////////////////////////////////////////////////////////
// nsIStreamListener:
NS_IMETHOD OnDataAvailable(nsIChannel* channel, nsISupports* context,
nsIInputStream *aIStream,
PRUint32 aSourceOffset,
PRUint32 aLength);
NS_IMETHOD OnStartRequest(nsIChannel* channel, nsISupports* context);
NS_IMETHOD OnStopRequest(nsIChannel* channel, nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg);
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
// nsFileChannel: // nsFileChannel:

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

@ -27,7 +27,7 @@
#include "nsIProgressEventSink.h" #include "nsIProgressEventSink.h"
#include "nsIEventSinkGetter.h" #include "nsIEventSinkGetter.h"
#include "nsIIOService.h" #include "nsIIOService.h"
#include "nsIBuffer.h" #include "nsIPipe.h"
#include "nsILoadGroup.h" #include "nsILoadGroup.h"
#include "nsIFTPContext.h" #include "nsIFTPContext.h"
#include "nsIMIMEService.h" #include "nsIMIMEService.h"
@ -270,9 +270,8 @@ nsFTPChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream, rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
NS_FTP_SEGMENT_SIZE, nsnull/*this*/, // XXX need channel to implement nsIPipeObserver
NS_FTP_BUFFER_SIZE, PR_TRUE, nsnull/*this*/); // XXX need channel to implement NS_FTP_SEGMENT_SIZE, NS_FTP_BUFFER_SIZE);
// nsIBufferObserver
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
rv = mBufferOutputStream->SetNonBlocking(PR_TRUE); rv = mBufferOutputStream->SetNonBlocking(PR_TRUE);

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

@ -22,7 +22,6 @@
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsISocketTransportService.h" #include "nsISocketTransportService.h"
#include "nsIURI.h" #include "nsIURI.h"
#include "nsIBuffer.h"
#include "nsIBufferInputStream.h" // for our internal stream state #include "nsIBufferInputStream.h" // for our internal stream state
#include "nsIInputStream.h" #include "nsIInputStream.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"

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

@ -16,13 +16,20 @@
* Reserved. * Reserved.
*/ */
#define NSPIPE2
#include "nspr.h" #include "nspr.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsHTTPRequest.h" #include "nsHTTPRequest.h"
#include "nsHTTPAtoms.h" #include "nsHTTPAtoms.h"
#include "nsHTTPEnums.h" #include "nsHTTPEnums.h"
#ifndef NSPIPE2
#include "nsIBuffer.h" #include "nsIBuffer.h"
#else
#include "nsIPipe.h"
#endif
#include "nsIBufferInputStream.h" #include "nsIBufferInputStream.h"
#include "nsIBufferOutputStream.h"
#include "nsString.h" #include "nsString.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIChannel.h" #include "nsIChannel.h"
@ -167,6 +174,7 @@ nsHTTPRequest::Build()
} }
// Create the Input Stream for writing the request... // Create the Input Stream for writing the request...
#ifndef NSPIPE2
nsCOMPtr<nsIBuffer> buf; nsCOMPtr<nsIBuffer> buf;
rv = NS_NewBuffer(getter_AddRefs(buf), NS_HTTP_REQUEST_SEGMENT_SIZE, rv = NS_NewBuffer(getter_AddRefs(buf), NS_HTTP_REQUEST_SEGMENT_SIZE,
NS_HTTP_REQUEST_BUFFER_SIZE, nsnull); NS_HTTP_REQUEST_BUFFER_SIZE, nsnull);
@ -174,6 +182,12 @@ nsHTTPRequest::Build()
rv = NS_NewBufferInputStream(&mRequest, buf); rv = NS_NewBufferInputStream(&mRequest, buf);
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
#else
nsCOMPtr<nsIBufferOutputStream> out;
rv = NS_NewPipe(&mRequest, getter_AddRefs(out), nsnull,
NS_HTTP_REQUEST_SEGMENT_SIZE, NS_HTTP_REQUEST_BUFFER_SIZE);
if (NS_FAILED(rv)) return rv;
#endif
// //
// Write the request into the stream... // Write the request into the stream...
@ -202,8 +216,8 @@ nsHTTPRequest::Build()
PR_LOG(gHTTPLog, PR_LOG_DEBUG, PR_LOG(gHTTPLog, PR_LOG_DEBUG,
("\tnsHTTPRequest.\tFirst line: %s", lineBuffer.GetBuffer())); ("\tnsHTTPRequest.\tFirst line: %s", lineBuffer.GetBuffer()));
rv = buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(), rv = out->Write(lineBuffer.GetBuffer(), lineBuffer.Length(),
&bytesWritten); &bytesWritten);
#ifdef DEBUG_gagan #ifdef DEBUG_gagan
printf(lineBuffer.GetBuffer()); printf(lineBuffer.GetBuffer());
#endif #endif
@ -263,7 +277,7 @@ nsHTTPRequest::Build()
("\tnsHTTPRequest [this=%x].\t\t%s\n", ("\tnsHTTPRequest [this=%x].\t\t%s\n",
this, lineBuffer.GetBuffer())); this, lineBuffer.GetBuffer()));
buf->Write(lineBuffer.GetBuffer(), lineBuffer.Length(), out->Write(lineBuffer.GetBuffer(), lineBuffer.Length(),
&bytesWritten); &bytesWritten);
} }
enumerator->HasMoreElements(&bMoreHeaders); enumerator->HasMoreElements(&bMoreHeaders);
@ -300,7 +314,7 @@ nsHTTPRequest::Build()
{ {
tempBuff[length] = '\0'; tempBuff[length] = '\0';
PRUint32 writtenLength; PRUint32 writtenLength;
buf->Write(tempBuff, length, &writtenLength); out->Write(tempBuff, length, &writtenLength);
#ifdef DEBUG_gagan #ifdef DEBUG_gagan
printf(tempBuff); printf(tempBuff);
#endif #endif
@ -313,7 +327,7 @@ nsHTTPRequest::Build()
{ {
// Write the final \r\n // Write the final \r\n
rv = buf->Write(CRLF, PL_strlen(CRLF), &bytesWritten); rv = out->Write(CRLF, PL_strlen(CRLF), &bytesWritten);
#ifdef DEBUG_gagan #ifdef DEBUG_gagan
printf(CRLF); printf(CRLF);
#endif #endif

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

@ -33,7 +33,11 @@
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsINetModuleMgr.h" #include "nsINetModuleMgr.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
#ifndef NSPIPE2
#include "nsIBuffer.h" #include "nsIBuffer.h"
#else
#include "nsIPipe.h"
#endif
#include "nsIIOService.h" #include "nsIIOService.h"
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
@ -118,16 +122,22 @@ nsHTTPResponseListener::OnDataAvailable(nsIChannel* channel,
// Parse the status line and the response headers from the server // Parse the status line and the response headers from the server
// //
if (!mHeadersDone) { if (!mHeadersDone) {
#ifndef NSPIPE2
nsCOMPtr<nsIBuffer> pBuffer; nsCOMPtr<nsIBuffer> pBuffer;
rv = bufferInStream->GetBuffer(getter_AddRefs(pBuffer)); rv = bufferInStream->GetBuffer(getter_AddRefs(pBuffer));
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
#endif
// //
// Parse the status line from the server. This is always the // Parse the status line from the server. This is always the
// first line of the response... // first line of the response...
// //
if (!mFirstLineParsed) { if (!mFirstLineParsed) {
#ifndef NSPIPE2
rv = ParseStatusLine(pBuffer, i_Length, &actualBytesRead); rv = ParseStatusLine(pBuffer, i_Length, &actualBytesRead);
#else
rv = ParseStatusLine(bufferInStream, i_Length, &actualBytesRead);
#endif
i_Length -= actualBytesRead; i_Length -= actualBytesRead;
} }
@ -138,7 +148,11 @@ nsHTTPResponseListener::OnDataAvailable(nsIChannel* channel,
// the headers are not done... // the headers are not done...
// //
while (NS_SUCCEEDED(rv) && i_Length && !mHeadersDone) { while (NS_SUCCEEDED(rv) && i_Length && !mHeadersDone) {
#ifndef NSPIPE2
rv = ParseHTTPHeader(pBuffer, i_Length, &actualBytesRead); rv = ParseHTTPHeader(pBuffer, i_Length, &actualBytesRead);
#else
rv = ParseHTTPHeader(bufferInStream, i_Length, &actualBytesRead);
#endif
NS_ASSERTION(i_Length - actualBytesRead <= i_Length, "wrap around"); NS_ASSERTION(i_Length - actualBytesRead <= i_Length, "wrap around");
i_Length -= actualBytesRead; i_Length -= actualBytesRead;
} }
@ -316,9 +330,15 @@ nsWriteToString(void* closure,
} }
#ifndef NSPIPE2
nsresult nsHTTPResponseListener::ParseStatusLine(nsIBuffer* aBuffer, nsresult nsHTTPResponseListener::ParseStatusLine(nsIBuffer* aBuffer,
PRUint32 aLength, PRUint32 aLength,
PRUint32 *aBytesRead) PRUint32 *aBytesRead)
#else
nsresult nsHTTPResponseListener::ParseStatusLine(nsIBufferInputStream* in,
PRUint32 aLength,
PRUint32 *aBytesRead)
#endif
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
@ -337,7 +357,11 @@ nsresult nsHTTPResponseListener::ParseStatusLine(nsIBuffer* aBuffer,
} }
// Look for the LF which ends the Status-Line. // Look for the LF which ends the Status-Line.
#ifndef NSPIPE2
rv = aBuffer->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd); rv = aBuffer->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd);
#else
rv = in->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd);
#endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (!bFoundString) { if (!bFoundString) {
@ -351,10 +375,17 @@ nsresult nsHTTPResponseListener::ParseStatusLine(nsIBuffer* aBuffer,
totalBytesToRead = offsetOfEnd+1; totalBytesToRead = offsetOfEnd+1;
} }
#ifndef NSPIPE2
rv = aBuffer->ReadSegments(nsWriteToString, rv = aBuffer->ReadSegments(nsWriteToString,
(void*)&mHeaderBuffer, (void*)&mHeaderBuffer,
totalBytesToRead, totalBytesToRead,
&actualBytesRead); &actualBytesRead);
#else
rv = in->ReadSegments(nsWriteToString,
(void*)&mHeaderBuffer,
totalBytesToRead,
&actualBytesRead);
#endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aBytesRead += actualBytesRead; *aBytesRead += actualBytesRead;
@ -442,13 +473,21 @@ nsresult nsHTTPResponseListener::ParseStatusLine(nsIBuffer* aBuffer,
#ifndef NSPIPE2
nsresult nsHTTPResponseListener::ParseHTTPHeader(nsIBuffer* aBuffer, nsresult nsHTTPResponseListener::ParseHTTPHeader(nsIBuffer* aBuffer,
PRUint32 aLength, PRUint32 aLength,
PRUint32 *aBytesRead) PRUint32 *aBytesRead)
#else
nsresult nsHTTPResponseListener::ParseHTTPHeader(nsIBufferInputStream* in,
PRUint32 aLength,
PRUint32 *aBytesRead)
#endif
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
#ifndef NSPIPE2
const char *buf; const char *buf;
#endif
PRBool bFoundString; PRBool bFoundString;
PRUint32 offsetOfEnd, totalBytesToRead, actualBytesRead; PRUint32 offsetOfEnd, totalBytesToRead, actualBytesRead;
@ -470,6 +509,7 @@ nsresult nsHTTPResponseListener::ParseHTTPHeader(nsIBuffer* aBuffer,
// may be complete... // may be complete...
// //
if (mHeaderBuffer.Last() == '\n' ) { if (mHeaderBuffer.Last() == '\n' ) {
#ifndef NSPIPE2
rv = aBuffer->GetReadSegment(0, &buf, &actualBytesRead); rv = aBuffer->GetReadSegment(0, &buf, &actualBytesRead);
// Need to wait for more data to see if the header is complete. // Need to wait for more data to see if the header is complete.
if (0 == actualBytesRead) { if (0 == actualBytesRead) {
@ -480,14 +520,41 @@ nsresult nsHTTPResponseListener::ParseHTTPHeader(nsIBuffer* aBuffer,
if (mHeaderBuffer.Length() <= 2) { if (mHeaderBuffer.Length() <= 2) {
break; break;
} }
// Not LWS - The header is complete... // Not LWS - The header is complete...
if ((*buf != ' ') && (*buf != '\t')) { if ((*buf != ' ') && (*buf != '\t')) {
break; break;
} }
#else
// This line is either LF or CRLF so the header is complete...
if (mHeaderBuffer.Length() <= 2) {
break;
}
rv = in->Search(" ", PR_FALSE, &bFoundString, &offsetOfEnd);
if (NS_FAILED(rv)) return rv;
if (!bFoundString && offsetOfEnd == 0)
return NS_OK; // Need to wait for more data to see if the header is complete
if (!bFoundString || offsetOfEnd != 0) {
// then check for tab too
rv = in->Search("\t", PR_FALSE, &bFoundString, &offsetOfEnd);
if (NS_FAILED(rv)) return rv;
NS_ASSERTION(!(!bFoundString && offsetOfEnd == 0), "should have been checked above");
if (!bFoundString || offsetOfEnd != 0) {
break; // neither space nor tab, so jump out of the loop
}
}
// else, go around the loop again and accumulate the rest of the header...
#endif
} }
// Look for the next LF in the buffer... // Look for the next LF in the buffer...
#ifndef NSPIPE2
rv = aBuffer->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd); rv = aBuffer->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd);
#else
rv = in->Search("\n", PR_FALSE, &bFoundString, &offsetOfEnd);
#endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
if (!bFoundString) { if (!bFoundString) {
@ -502,10 +569,17 @@ nsresult nsHTTPResponseListener::ParseHTTPHeader(nsIBuffer* aBuffer,
} }
// Append the buffer into the header string... // Append the buffer into the header string...
#ifndef NSPIPE2
rv = aBuffer->ReadSegments(nsWriteToString, rv = aBuffer->ReadSegments(nsWriteToString,
(void*)&mHeaderBuffer, (void*)&mHeaderBuffer,
totalBytesToRead, totalBytesToRead,
&actualBytesRead); &actualBytesRead);
#else
rv = in->ReadSegments(nsWriteToString,
(void*)&mHeaderBuffer,
totalBytesToRead,
&actualBytesRead);
#endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
*aBytesRead += actualBytesRead; *aBytesRead += actualBytesRead;

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

@ -19,12 +19,18 @@
#ifndef _nsHTTPResponseListener_h_ #ifndef _nsHTTPResponseListener_h_
#define _nsHTTPResponseListener_h_ #define _nsHTTPResponseListener_h_
#define NSPIPE2
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsString.h" #include "nsString.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#ifndef NSPIPE2
class nsIBuffer; class nsIBuffer;
#else
class nsIBufferInputStream;
#endif
class nsHTTPResponse; class nsHTTPResponse;
class nsHTTPChannel; class nsHTTPChannel;
@ -72,11 +78,19 @@ protected:
// nsHTTPResponseListener methods... // nsHTTPResponseListener methods...
nsresult FireOnHeadersAvailable(); nsresult FireOnHeadersAvailable();
#ifndef NSPIPE2
nsresult ParseStatusLine(nsIBuffer* aBuffer, PRUint32 aLength, nsresult ParseStatusLine(nsIBuffer* aBuffer, PRUint32 aLength,
PRUint32 *aBytesRead); PRUint32 *aBytesRead);
nsresult ParseHTTPHeader(nsIBuffer* aBuffer, PRUint32 aLength, nsresult ParseHTTPHeader(nsIBuffer* aBuffer, PRUint32 aLength,
PRUint32* aBytesRead); PRUint32* aBytesRead);
#else
nsresult ParseStatusLine(nsIBufferInputStream* in, PRUint32 aLength,
PRUint32 *aBytesRead);
nsresult ParseHTTPHeader(nsIBufferInputStream* in, PRUint32 aLength,
PRUint32* aBytesRead);
#endif
nsresult FinishedResponseHeaders(); nsresult FinishedResponseHeaders();

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

@ -16,6 +16,8 @@
* Reserved. * Reserved.
*/ */
#define NSPIPE2
#include "nsIFileTransportService.h" #include "nsIFileTransportService.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
@ -29,11 +31,17 @@
#include "prio.h" #include "prio.h"
#include "nsIFileStream.h" #include "nsIFileStream.h"
#include "nsFileSpec.h" #include "nsFileSpec.h"
#ifndef NSPIPE2
#include "nsIBuffer.h" #include "nsIBuffer.h"
#else
#include "nsIPipe.h"
#include "nsIBufferOutputStream.h"
#endif
#include "nsIBufferInputStream.h" #include "nsIBufferInputStream.h"
#include "nsIThread.h" #include "nsIThread.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsCOMPtr.h"
#include <stdio.h> #include <stdio.h>
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
@ -194,6 +202,11 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
nsIBufferInputStream* bufStr = nsnull; nsIBufferInputStream* bufStr = nsnull;
nsFileSpec spec(path); nsFileSpec spec(path);
PRUint32 sourceOffset = 0; PRUint32 sourceOffset = 0;
#ifndef NSPIPE2
nsCOMPtr<nsIBuffer> buf;
#else
nsCOMPtr<nsIBufferOutputStream> out;
#endif
rv = reader->OnStartRequest(nsnull, nsnull); rv = reader->OnStartRequest(nsnull, nsnull);
if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer? if (NS_FAILED(rv)) goto done; // XXX should this abort the transfer?
@ -205,11 +218,17 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
NS_RELEASE(fs); NS_RELEASE(fs);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
nsIBuffer* buf; #ifndef NSPIPE2
rv = NS_NewBuffer(&buf, NS_FILE_TRANSPORT_BUFFER_SIZE, rv = NS_NewBuffer(getter_AddRefs(buf), NS_FILE_TRANSPORT_BUFFER_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE, nsnull); NS_FILE_TRANSPORT_BUFFER_SIZE, nsnull);
rv = NS_NewBufferInputStream(&bufStr, buf); rv = NS_NewBufferInputStream(&bufStr, buf);
if (NS_FAILED(rv)) goto done; if (NS_FAILED(rv)) goto done;
#else
rv = NS_NewPipe(&bufStr, getter_AddRefs(out), nsnull,
NS_FILE_TRANSPORT_BUFFER_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(rv)) goto done;
#endif
/* /*
if ( spec.GetFileSize() == 0) goto done; if ( spec.GetFileSize() == 0) goto done;
@ -221,7 +240,11 @@ Simulated_nsFileTransport_Run(nsReader* reader, const char* path)
#if 0 #if 0
rv = bufStr->FillFrom(fileStr, spec.GetFileSize(), &amt); rv = bufStr->FillFrom(fileStr, spec.GetFileSize(), &amt);
#else #else
#ifndef NSPIPE2
rv = buf->WriteFrom(fileStr, spec.GetFileSize(), &amt); rv = buf->WriteFrom(fileStr, spec.GetFileSize(), &amt);
#else
rv = out->WriteFrom(fileStr, spec.GetFileSize(), &amt);
#endif
#endif #endif
if (rv == NS_BASE_STREAM_EOF) { if (rv == NS_BASE_STREAM_EOF) {
rv = NS_OK; rv = NS_OK;

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

@ -21,6 +21,8 @@
#include <windows.h> #include <windows.h>
#endif #endif
#define NSPIPE2
#include "nspr.h" #include "nspr.h"
#include "nscore.h" #include "nscore.h"
#include "nsISocketTransportService.h" #include "nsISocketTransportService.h"
@ -29,9 +31,15 @@
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIStreamObserver.h" #include "nsIStreamObserver.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#ifndef NSPIPE2
#include "nsIBuffer.h" #include "nsIBuffer.h"
#else
#include "nsIPipe.h"
#include "nsIBufferOutputStream.h"
#endif
#include "nsIBufferInputStream.h" #include "nsIBufferInputStream.h"
#include "nsCRT.h" #include "nsCRT.h"
#include "nsCOMPtr.h"
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);
@ -223,16 +231,26 @@ main(int argc, char* argv[])
nsIBufferInputStream* stream; nsIBufferInputStream* stream;
PRUint32 bytesWritten; PRUint32 bytesWritten;
nsIBuffer* buf; #ifndef NSPIPE2
nsCOMPtr<nsIBuffer> buf;
rv = NS_NewBuffer(&buf, 1024, 4096, nsnull); rv = NS_NewBuffer(&buf, 1024, 4096, nsnull);
rv = NS_NewBufferInputStream(&stream, buf); rv = NS_NewBufferInputStream(&stream, buf);
#else
nsCOMPtr<nsIBufferOutputStream> out;
rv = NS_NewPipe(&stream, getter_AddRefs(out), nsnull,
1024, 4096);
#endif
if (NS_FAILED(rv)) return rv; if (NS_FAILED(rv)) return rv;
char *buffer = PR_smprintf("GET %s HTML/1.0%s%s", fileName, CRLF, CRLF); char *buffer = PR_smprintf("GET %s HTML/1.0%s%s", fileName, CRLF, CRLF);
#if 0 #if 0
stream->Fill(buffer, strlen(buffer), &bytesWritten); stream->Fill(buffer, strlen(buffer), &bytesWritten);
#else #else
#ifndef NSPIPE2
buf->Write(buffer, strlen(buffer), &bytesWritten); buf->Write(buffer, strlen(buffer), &bytesWritten);
#else
out->Write(buffer, strlen(buffer), &bytesWritten);
#endif
#endif #endif
printf("\n+++ Request is: %s\n", buffer); printf("\n+++ Request is: %s\n", buffer);

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

@ -24,13 +24,19 @@
#include "nspr.h" #include "nspr.h"
#define NSPIPE2
#include "nsISocketTransportService.h" #include "nsISocketTransportService.h"
#include "nsIEventQueueService.h" #include "nsIEventQueueService.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIChannel.h" #include "nsIChannel.h"
#include "nsIStreamObserver.h" #include "nsIStreamObserver.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#ifndef NSPIPE2
#include "nsIBuffer.h" #include "nsIBuffer.h"
#else
#include "nsIPipe.h"
#endif
#include "nsIBufferInputStream.h" #include "nsIBufferInputStream.h"
#include "nsIBufferOutputStream.h" #include "nsIBufferOutputStream.h"
#include "nsIThread.h" #include "nsIThread.h"
@ -131,7 +137,11 @@ public:
nsresult Resume(void); nsresult Resume(void);
protected: protected:
#ifndef NSPIPE2
nsIBuffer* mBuffer; nsIBuffer* mBuffer;
#else
nsIBufferOutputStream* mOut;
#endif
nsIBufferInputStream* mStream; nsIBufferInputStream* mStream;
nsIInputStream* mInStream; nsIInputStream* mInStream;
@ -209,7 +219,11 @@ TestConnection::TestConnection(const char* aHostName, PRInt32 aPort, PRBool aAsy
mBytesRead = 0; mBytesRead = 0;
mTransport = nsnull; mTransport = nsnull;
#ifndef NSPIPE2
mBuffer = nsnull; mBuffer = nsnull;
#else
mOut = nsnull;
#endif
mStream = nsnull; mStream = nsnull;
mInStream = nsnull; mInStream = nsnull;
@ -226,8 +240,12 @@ TestConnection::TestConnection(const char* aHostName, PRInt32 aPort, PRBool aAsy
if (mIsAsync) { if (mIsAsync) {
// Create a stream for the data being written to the server... // Create a stream for the data being written to the server...
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
#ifndef NSPIPE2
rv = NS_NewBuffer(&mBuffer, 1024, 4096, nsnull); rv = NS_NewBuffer(&mBuffer, 1024, 4096, nsnull);
rv = NS_NewBufferInputStream(&mStream, mBuffer); rv = NS_NewBufferInputStream(&mStream, mBuffer);
#else
rv = NS_NewPipe(&mStream, &mOut, nsnull, 1024, 4096);
#endif
} }
} }
// Synchronous transport... // Synchronous transport...
@ -244,7 +262,11 @@ TestConnection::~TestConnection()
NS_IF_RELEASE(mTransport); NS_IF_RELEASE(mTransport);
// Async resources... // Async resources...
NS_IF_RELEASE(mStream); NS_IF_RELEASE(mStream);
#ifndef NSPIPE2
NS_IF_RELEASE(mBuffer); NS_IF_RELEASE(mBuffer);
#else
NS_IF_RELEASE(mOut);
#endif
// Sync resources... // Sync resources...
NS_IF_RELEASE(mInStream); NS_IF_RELEASE(mInStream);
@ -361,7 +383,11 @@ nsresult TestConnection::WriteBuffer(void)
#if 0 #if 0
rv = mStream->Fill(buffer, size, &bytesWritten); rv = mStream->Fill(buffer, size, &bytesWritten);
#else #else
#ifndef NSPIPE2
rv = mBuffer->Write(buffer, size, &bytesWritten); rv = mBuffer->Write(buffer, size, &bytesWritten);
#else
rv = mOut->Write(buffer, size, &bytesWritten);
#endif
#endif #endif
// Write the buffer to the server... // Write the buffer to the server...