зеркало из https://github.com/mozilla/pjs.git
Fixed bug#14863 Network buffer size too large
This commit is contained in:
Родитель
28d0d333b5
Коммит
24931754b0
|
@ -99,7 +99,7 @@ protected:
|
|||
char* mBuffer;
|
||||
};
|
||||
|
||||
#define NS_FILE_TRANSPORT_SEGMENT_SIZE (4*1024)
|
||||
#define NS_FILE_TRANSPORT_BUFFER_SIZE (32*1024)
|
||||
#define NS_FILE_TRANSPORT_SEGMENT_SIZE (2*1024)
|
||||
#define NS_FILE_TRANSPORT_BUFFER_SIZE (8*1024)
|
||||
|
||||
#endif // nsFileTransport_h__
|
||||
|
|
|
@ -189,23 +189,13 @@ nsSocketTransport::~nsSocketTransport()
|
|||
//
|
||||
mReadListener = null_nsCOMPtr();
|
||||
mReadContext = null_nsCOMPtr();
|
||||
#ifndef NSPIPE2
|
||||
mReadStream = null_nsCOMPtr();
|
||||
mReadBuffer = null_nsCOMPtr();
|
||||
#else
|
||||
mReadPipeIn = null_nsCOMPtr();
|
||||
mReadPipeOut = null_nsCOMPtr();
|
||||
#endif
|
||||
|
||||
mWriteObserver = null_nsCOMPtr();
|
||||
mWriteContext = null_nsCOMPtr();
|
||||
#ifndef NSPIPE2
|
||||
mWriteStream = null_nsCOMPtr();
|
||||
mWriteBuffer = null_nsCOMPtr();
|
||||
#else
|
||||
mWritePipeIn = null_nsCOMPtr();
|
||||
mWritePipeOut = null_nsCOMPtr();
|
||||
#endif
|
||||
//
|
||||
// Cancel any pending DNS request...
|
||||
//
|
||||
|
@ -400,14 +390,8 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
|
|||
mReadListener = null_nsCOMPtr();
|
||||
mReadContext = null_nsCOMPtr();
|
||||
}
|
||||
#ifndef NSPIPE2
|
||||
mReadStream = null_nsCOMPtr();
|
||||
// XXX: The buffer should be reused...
|
||||
mReadBuffer = null_nsCOMPtr();
|
||||
#else
|
||||
mReadPipeIn = null_nsCOMPtr();
|
||||
mReadPipeOut = null_nsCOMPtr();
|
||||
#endif
|
||||
SetReadType(eSocketRead_None);
|
||||
ClearFlag(eSocketRead_Done);
|
||||
}
|
||||
|
@ -419,13 +403,8 @@ nsresult nsSocketTransport::Process(PRInt16 aSelectFlags)
|
|||
mWriteObserver = null_nsCOMPtr();
|
||||
mWriteContext = null_nsCOMPtr();
|
||||
}
|
||||
#ifndef NSPIPE2
|
||||
mWriteStream = null_nsCOMPtr();
|
||||
mWriteBuffer = null_nsCOMPtr();
|
||||
#else
|
||||
mWritePipeIn = null_nsCOMPtr();
|
||||
mWritePipeOut = null_nsCOMPtr();
|
||||
#endif
|
||||
SetWriteType(eSocketWrite_None);
|
||||
ClearFlag(eSocketWrite_Done);
|
||||
}
|
||||
|
@ -878,13 +857,8 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
|
|||
// thread
|
||||
//
|
||||
PR_Unlock(mLock);
|
||||
#ifndef NSPIPE2
|
||||
rv = mReadBuffer->WriteSegments(nsReadFromSocket, (void*)mSocketFD,
|
||||
MAX_IO_TRANSFER_SIZE, &totalBytesWritten);
|
||||
#else
|
||||
rv = mReadPipeOut->WriteSegments(nsReadFromSocket, (void*)mSocketFD,
|
||||
MAX_IO_TRANSFER_SIZE, &totalBytesWritten);
|
||||
#endif
|
||||
PR_Lock(mLock);
|
||||
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
|
@ -912,15 +886,9 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
|
|||
if (mReadListener) {
|
||||
nsresult rv1;
|
||||
|
||||
#ifndef NSPIPE2
|
||||
rv1 = mReadListener->OnDataAvailable(this, mReadContext, mReadStream,
|
||||
mSourceOffset,
|
||||
totalBytesWritten);
|
||||
#else
|
||||
rv1 = mReadListener->OnDataAvailable(this, mReadContext, mReadPipeIn,
|
||||
mSourceOffset,
|
||||
totalBytesWritten);
|
||||
#endif
|
||||
//
|
||||
// If the consumer returns failure, then cancel the operation...
|
||||
//
|
||||
|
@ -928,12 +896,6 @@ nsresult nsSocketTransport::doRead(PRInt16 aSelectFlags)
|
|||
rv = rv1;
|
||||
}
|
||||
}
|
||||
#ifndef NSPIPE2
|
||||
else if (GetReadType() == eSocketRead_Sync) {
|
||||
nsAutoCMonitor mon(mReadBuffer);
|
||||
mon.Notify();
|
||||
}
|
||||
#endif
|
||||
mSourceOffset += totalBytesWritten;
|
||||
}
|
||||
|
||||
|
@ -976,11 +938,7 @@ nsresult nsSocketTransport::doWrite(PRInt16 aSelectFlags)
|
|||
|
||||
totalBytesRead = 0;
|
||||
|
||||
#ifndef NSPIPE2
|
||||
if (mWriteBuffer)
|
||||
#else
|
||||
if (mWritePipeIn)
|
||||
#endif
|
||||
{
|
||||
rv = doWriteFromBuffer(&totalBytesRead);
|
||||
}
|
||||
|
@ -1009,14 +967,9 @@ nsresult nsSocketTransport::doWriteFromBuffer(PRUint32 *aCount)
|
|||
// thread
|
||||
//
|
||||
PR_Unlock(mLock);
|
||||
#ifndef NSPIPE2
|
||||
rv = mWriteBuffer->ReadSegments(nsWriteToSocket, (void*)mSocketFD,
|
||||
MAX_IO_TRANSFER_SIZE, aCount);
|
||||
#else
|
||||
PRUint32 transferCount = mWriteCount > 0 ? PR_MIN(mWriteCount, MAX_IO_TRANSFER_SIZE) : MAX_IO_TRANSFER_SIZE;
|
||||
rv = mWritePipeIn->ReadSegments(nsWriteToSocket, (void*)mSocketFD,
|
||||
transferCount, aCount);
|
||||
#endif
|
||||
PR_Lock(mLock);
|
||||
|
||||
if (mWriteCount > 0) {
|
||||
|
@ -1044,15 +997,6 @@ nsresult nsSocketTransport::doWriteFromBuffer(PRUint32 *aCount)
|
|||
if (mWriteCount == 0) {
|
||||
SetFlag(eSocketWrite_Wait);
|
||||
mSelectFlags &= (~PR_POLL_WRITE);
|
||||
|
||||
#ifndef NSPIPE2
|
||||
PR_Unlock(mLock);
|
||||
{
|
||||
nsAutoCMonitor mon(mWriteBuffer);
|
||||
mon.Notify();
|
||||
}
|
||||
PR_Lock(mLock);
|
||||
#endif
|
||||
}
|
||||
|
||||
// continue to return WOULD_BLOCK until we've completely finished
|
||||
|
@ -1081,11 +1025,7 @@ nsresult nsSocketTransport::doWriteFromStream(PRUint32 *aCount)
|
|||
}
|
||||
|
||||
bytesRead = 0;
|
||||
#ifndef NSPIPE2
|
||||
rv = mWriteStream->Read(gIOBuffer, maxBytesToRead, &bytesRead);
|
||||
#else
|
||||
rv = mWriteFromStream->Read(gIOBuffer, maxBytesToRead, &bytesRead);
|
||||
#endif
|
||||
if ((NS_SUCCEEDED(rv) || rv == NS_BASE_STREAM_WOULD_BLOCK) && bytesRead) {
|
||||
// Update the counters...
|
||||
*aCount += bytesRead;
|
||||
|
@ -1175,19 +1115,11 @@ nsSocketTransport::QueryInterface(const nsIID& aIID, void* *aInstancePtr)
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
#ifndef NSPIPE2
|
||||
if (aIID.Equals(NS_GET_IID(nsIBufferObserver))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIBufferObserver*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
#else
|
||||
if (aIID.Equals(NS_GET_IID(nsIPipeObserver))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIPipeObserver*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
@ -1292,29 +1224,15 @@ nsSocketTransport::Resume(void)
|
|||
// --------------------------------------------------------------------------
|
||||
//
|
||||
NS_IMETHODIMP
|
||||
#ifndef NSPIPE2
|
||||
nsSocketTransport::OnFull(nsIBuffer* aBuffer)
|
||||
#else
|
||||
nsSocketTransport::OnFull(nsIPipe* aPipe)
|
||||
#endif
|
||||
{
|
||||
#ifndef NSPIPE2
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
("nsSocketTransport::OnFull() [this=%x] nsIBuffer=%x.\n",
|
||||
this, aBuffer));
|
||||
#else
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
("nsSocketTransport::OnFull() [this=%x] nsIPipe=%x.\n",
|
||||
this, aPipe));
|
||||
#endif
|
||||
|
||||
#ifndef NSPIPE2
|
||||
if (aBuffer == mReadBuffer.get())
|
||||
#else
|
||||
nsCOMPtr<nsIBufferInputStream> in;
|
||||
nsresult rv = aPipe->GetInputStream(getter_AddRefs(in));
|
||||
if (NS_SUCCEEDED(rv) && in == mReadPipeIn)
|
||||
#endif
|
||||
{
|
||||
NS_ASSERTION(!GetFlag(eSocketRead_Wait), "Already waiting!");
|
||||
|
||||
|
@ -1327,31 +1245,17 @@ nsSocketTransport::OnFull(nsIPipe* aPipe)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
#ifndef NSPIPE2
|
||||
nsSocketTransport::OnWrite(nsIBuffer* aBuffer, PRUint32 aCount)
|
||||
#else
|
||||
nsSocketTransport::OnWrite(nsIPipe* aPipe, PRUint32 aCount)
|
||||
#endif
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifndef NSPIPE2
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
("nsSocketTransport::OnWrite() [this=%x]. nsIBuffer=%x Count=%d\n",
|
||||
this, aBuffer, aCount));
|
||||
#else
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
("nsSocketTransport::OnWrite() [this=%x]. nsIPipe=%x Count=%d\n",
|
||||
this, aPipe, aCount));
|
||||
#endif
|
||||
|
||||
#ifndef NSPIPE2
|
||||
if (aBuffer == mWriteBuffer.get())
|
||||
#else
|
||||
nsCOMPtr<nsIBufferOutputStream> out;
|
||||
rv = aPipe->GetOutputStream(getter_AddRefs(out));
|
||||
if (NS_SUCCEEDED(rv) && out == mWritePipeOut)
|
||||
#endif
|
||||
{
|
||||
// Enter the socket transport lock...
|
||||
nsAutoLock aLock(mLock);
|
||||
|
@ -1374,31 +1278,17 @@ nsSocketTransport::OnWrite(nsIPipe* aPipe, PRUint32 aCount)
|
|||
|
||||
|
||||
NS_IMETHODIMP
|
||||
#ifndef NSPIPE2
|
||||
nsSocketTransport::OnEmpty(nsIBuffer* aBuffer)
|
||||
#else
|
||||
nsSocketTransport::OnEmpty(nsIPipe* aPipe)
|
||||
#endif
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
#ifndef NSPIPE2
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
("nsSocketTransport::OnEmpty() [this=%x] nsIBuffer=%x.\n",
|
||||
this, aBuffer));
|
||||
#else
|
||||
PR_LOG(gSocketLog, PR_LOG_DEBUG,
|
||||
("nsSocketTransport::OnEmpty() [this=%x] nsIPipe=%x.\n",
|
||||
this, aPipe));
|
||||
#endif
|
||||
|
||||
#ifndef NSPIPE2
|
||||
if (aBuffer == mReadBuffer.get())
|
||||
#else
|
||||
nsCOMPtr<nsIBufferInputStream> in;
|
||||
rv = aPipe->GetInputStream(getter_AddRefs(in));
|
||||
if (NS_SUCCEEDED(rv) && in == mReadPipeIn)
|
||||
#endif
|
||||
{
|
||||
// Enter the socket transport lock...
|
||||
nsAutoLock aLock(mLock);
|
||||
|
@ -1527,20 +1417,6 @@ nsSocketTransport::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
|||
}
|
||||
|
||||
// Create a new non-blocking input stream for reading data into...
|
||||
#ifndef NSPIPE2
|
||||
if (NS_SUCCEEDED(rv) && !mReadStream) {
|
||||
rv = NS_NewBuffer(getter_AddRefs(mReadBuffer), MAX_IO_BUFFER_SIZE/2,
|
||||
2*MAX_IO_BUFFER_SIZE, this);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIBufferInputStream> newStream;
|
||||
|
||||
rv = NS_NewBufferInputStream(getter_AddRefs(newStream),
|
||||
mReadBuffer, PR_FALSE);
|
||||
mReadStream = newStream;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (NS_SUCCEEDED(rv) && !mReadPipeIn) {
|
||||
// XXXbe calling out of module with a lock held...
|
||||
rv = NS_NewPipe(getter_AddRefs(mReadPipeIn),
|
||||
|
@ -1555,7 +1431,6 @@ nsSocketTransport::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
|||
rv = mReadPipeOut->SetNonBlocking(PR_TRUE);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Create a marshalling stream listener to receive notifications...
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -1614,19 +1489,7 @@ nsSocketTransport::AsyncWrite(nsIInputStream* aFromStream,
|
|||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
#ifndef NSPIPE2
|
||||
mWriteStream = aFromStream;
|
||||
#else
|
||||
mWriteFromStream = aFromStream;
|
||||
#if 0
|
||||
// Note that the following assignment can fail, but we'll deal with
|
||||
// it in doWrite:
|
||||
mWritePipeIn = do_QueryInterface(aFromStream);
|
||||
if (mWritePipeIn) {
|
||||
rv = mWritePipeIn->SetNonBlocking(PR_TRUE);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
mWriteContext = aContext;
|
||||
|
||||
// Create a marshalling stream observer to receive notifications...
|
||||
|
@ -1687,20 +1550,6 @@ nsSocketTransport::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
|||
mReadListener = null_nsCOMPtr();
|
||||
mReadContext = null_nsCOMPtr();
|
||||
|
||||
#ifndef NSPIPE2
|
||||
rv = NS_NewBuffer(getter_AddRefs(mReadBuffer), MAX_IO_BUFFER_SIZE/2,
|
||||
2*MAX_IO_BUFFER_SIZE, this);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIBufferInputStream> newStream;
|
||||
|
||||
rv = NS_NewBufferInputStream(getter_AddRefs(newStream),
|
||||
mReadBuffer, PR_TRUE);
|
||||
mReadStream = newStream;
|
||||
*result = newStream;
|
||||
NS_IF_ADDREF(*result);
|
||||
}
|
||||
#else
|
||||
// XXXbe calling out of module with a lock held...
|
||||
rv = NS_NewPipe(getter_AddRefs(mReadPipeIn),
|
||||
getter_AddRefs(mReadPipeOut),
|
||||
|
@ -1712,7 +1561,6 @@ nsSocketTransport::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
|||
*result = mReadPipeIn;
|
||||
NS_IF_ADDREF(*result);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -1762,10 +1610,6 @@ nsSocketTransport::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *re
|
|||
|
||||
nsCOMPtr<nsIBufferOutputStream> out;
|
||||
nsCOMPtr<nsIBufferInputStream> in;
|
||||
#ifndef NSPIPE2
|
||||
rv = NS_NewPipe(getter_AddRefs(in), getter_AddRefs(out),
|
||||
MAX_IO_BUFFER_SIZE, MAX_IO_BUFFER_SIZE, PR_TRUE, this);
|
||||
#else
|
||||
// XXXbe calling out of module with a lock held...
|
||||
rv = NS_NewPipe(getter_AddRefs(in), getter_AddRefs(out),
|
||||
this, // nsIPipeObserver
|
||||
|
@ -1774,22 +1618,13 @@ nsSocketTransport::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *re
|
|||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = in->SetNonBlocking(PR_TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
#ifndef NSPIPE2
|
||||
mWriteStream = in;
|
||||
#else
|
||||
mWritePipeIn = in;
|
||||
#endif
|
||||
*result = out;
|
||||
NS_IF_ADDREF(*result);
|
||||
|
||||
#ifndef NSPIPE2
|
||||
out->GetBuffer(getter_AddRefs(mWriteBuffer));
|
||||
#else
|
||||
mWritePipeOut = out;
|
||||
#endif
|
||||
}
|
||||
|
||||
SetWriteType(eSocketWrite_Sync);
|
||||
|
|
|
@ -19,8 +19,6 @@
|
|||
#ifndef nsSocketTransport_h___
|
||||
#define nsSocketTransport_h___
|
||||
|
||||
#define NSPIPE2
|
||||
|
||||
#include "prclist.h"
|
||||
#include "prio.h"
|
||||
#include "prnetdb.h"
|
||||
|
@ -33,14 +31,10 @@
|
|||
#include "nsIEventQueueService.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIDNSListener.h"
|
||||
#ifndef NSPIPE2
|
||||
#include "nsIBuffer.h"
|
||||
#else
|
||||
#include "nsIPipe.h"
|
||||
#endif
|
||||
|
||||
#define NS_SOCKET_TRANSPORT_SEGMENT_SIZE (4*1024)
|
||||
#define NS_SOCKET_TRANSPORT_BUFFER_SIZE (64*1024)
|
||||
#define NS_SOCKET_TRANSPORT_SEGMENT_SIZE (2*1024)
|
||||
#define NS_SOCKET_TRANSPORT_BUFFER_SIZE (8*1024)
|
||||
|
||||
//
|
||||
// This is the size of the global buffer used by all nsSocketTransport
|
||||
|
@ -116,26 +110,15 @@ class nsSocketTransportService;
|
|||
|
||||
class nsSocketTransport : public nsIChannel,
|
||||
public nsIDNSListener,
|
||||
#ifndef NSPIPE2
|
||||
public nsIBufferObserver
|
||||
#else
|
||||
public nsIPipeObserver
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUEST
|
||||
NS_DECL_NSICHANNEL
|
||||
|
||||
#ifndef NSPIPE2
|
||||
// nsIBufferObserver methods:
|
||||
NS_IMETHOD OnFull (nsIBuffer* aBuffer);
|
||||
NS_IMETHOD OnWrite(nsIBuffer* aBuffer, PRUint32 aCount);
|
||||
NS_IMETHOD OnEmpty(nsIBuffer* aBuffer);
|
||||
#else
|
||||
// nsIPipeObserver methods:
|
||||
NS_DECL_NSIPIPEOBSERVER
|
||||
#endif
|
||||
|
||||
// nsIDNSListener methods:
|
||||
NS_DECL_NSIDNSLISTENER
|
||||
|
@ -215,25 +198,15 @@ protected:
|
|||
|
||||
nsCOMPtr<nsISupports> mReadContext;
|
||||
nsCOMPtr<nsIStreamListener> mReadListener;
|
||||
#ifndef NSPIPE2
|
||||
nsCOMPtr<nsIInputStream> mReadStream;
|
||||
nsCOMPtr<nsIBuffer> mReadBuffer;
|
||||
#else
|
||||
nsCOMPtr<nsIBufferInputStream> mReadPipeIn;
|
||||
nsCOMPtr<nsIBufferOutputStream> mReadPipeOut;
|
||||
#endif
|
||||
|
||||
PRInt32 mWriteCount;
|
||||
nsCOMPtr<nsISupports> mWriteContext;
|
||||
nsCOMPtr<nsIStreamObserver> mWriteObserver;
|
||||
#ifndef NSPIPE2
|
||||
nsCOMPtr<nsIInputStream> mWriteStream;
|
||||
nsCOMPtr<nsIBuffer> mWriteBuffer;
|
||||
#else
|
||||
nsCOMPtr<nsIInputStream> mWriteFromStream;
|
||||
nsCOMPtr<nsIBufferInputStream> mWritePipeIn;
|
||||
nsCOMPtr<nsIBufferOutputStream> mWritePipeOut;
|
||||
#endif
|
||||
PRUint32 mSourceOffset;
|
||||
nsSocketTransportService* mService;
|
||||
PRUint32 mLoadAttributes;
|
||||
|
|
|
@ -89,7 +89,7 @@ nsHTTPChannel::nsHTTPChannel(nsIURI* i_URL,
|
|||
nsIHTTPEventSink *sink = nsnull;
|
||||
|
||||
(void) i_EventSinkGetter->GetEventSink(i_Verb, NS_GET_IID(nsIHTTPEventSink),
|
||||
(nsISupports**)&sink);
|
||||
(nsISupports**)&sink);
|
||||
mEventSink = sink;
|
||||
NS_IF_RELEASE(sink);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче