Ported to the new nsPipe2 implementation.

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

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

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

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

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

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

@ -110,7 +110,7 @@ nsFileChannel::Init(nsFileProtocolHandler* handler,
return NS_ERROR_OUT_OF_MEMORY;
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
}
@ -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
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
this, // nsIPipeObserver
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 0
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
@ -431,8 +432,9 @@ nsFileChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
if (NS_FAILED(rv)) return rv;
rv = NS_NewPipe(&mBufferInputStream, &mBufferOutputStream,
this, // nsIPipeObserver
NS_FILE_TRANSPORT_SEGMENT_SIZE,
NS_FILE_TRANSPORT_BUFFER_SIZE, PR_TRUE, this);
NS_FILE_TRANSPORT_BUFFER_SIZE);
if (NS_FAILED(rv)) return rv;
rv = mBufferOutputStream->SetNonBlocking(PR_TRUE);
@ -649,7 +651,7 @@ nsFileChannel::Process(void)
mAmount -= amt; // subtract off the amount we just read from mAmount.
if (NS_FAILED(mStatus)) goto error;
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
// this file channel.
Suspend();
@ -753,23 +755,23 @@ nsFileChannel::Process(void)
}
////////////////////////////////////////////////////////////////////////////////
// nsIBufferObserver methods:
// nsIPipeObserver methods:
////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsFileChannel::OnFull(nsIBuffer* buffer)
nsFileChannel::OnFull(nsIPipe* pipe)
{
return Suspend();
}
NS_IMETHODIMP
nsFileChannel::OnWrite(nsIBuffer* aBuffer, PRUint32 aCount)
nsFileChannel::OnWrite(nsIPipe* pipe, PRUint32 aCount)
{
return NS_OK;
}
NS_IMETHODIMP
nsFileChannel::OnEmpty(nsIBuffer* buffer)
nsFileChannel::OnEmpty(nsIPipe* pipe)
{
return Resume();
}
@ -1094,6 +1096,7 @@ nsFileChannel::Execute(const char *args)
}
////////////////////////////////////////////////////////////////////////////////
nsresult
nsFileChannel::CreateFileChannelFromFileSpec(nsFileSpec& spec, nsIFileChannel **result)
{

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

@ -33,7 +33,7 @@
#include "nsFileSpec.h"
#include "prlock.h"
#include "nsIEventQueueService.h"
#include "nsIBuffer.h"
#include "nsIPipe.h"
#include "nsILoadGroup.h"
#include "nsIStreamListener.h"
#include "nsCOMPtr.h"
@ -47,60 +47,28 @@ class nsIEventSinkGetter;
class nsIStreamListener;
class nsFileProtocolHandler;
class nsIBaseStream;
class nsIBuffer;
class nsIBufferInputStream;
class nsIBufferOutputStream;
class nsFileChannel : public nsIFileChannel,
public nsIRunnable,
public nsIBufferObserver,
public nsIPipeObserver,
public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////////
// from nsIRequest:
NS_DECL_NSIREQUEST
////////////////////////////////////////////////////////////////////////////
// from nsIChannel:
NS_DECL_NSICHANNEL
////////////////////////////////////////////////////////////////////////////
// from nsIFileChannel:
NS_DECL_NSIFILECHANNEL
NS_DECL_NSIPIPEOBSERVER
NS_DECL_NSISTREAMOBSERVER
NS_DECL_NSISTREAMLISTENER
////////////////////////////////////////////////////////////////////////////
// nsIRunnable methods:
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:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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