Bug 545869 - Remove small buffer #defines and use preferences. r=honza
This commit is contained in:
Родитель
82325e59f5
Коммит
d56442f0d2
|
@ -210,7 +210,6 @@ MOZ_RDF = @MOZ_RDF@
|
|||
|
||||
NECKO_PROTOCOLS = @NECKO_PROTOCOLS@
|
||||
NECKO_DISK_CACHE = @NECKO_DISK_CACHE@
|
||||
NECKO_SMALL_BUFFERS = @NECKO_SMALL_BUFFERS@
|
||||
NECKO_COOKIES = @NECKO_COOKIES@
|
||||
NECKO_WIFI = @NECKO_WIFI@
|
||||
MOZ_AUTH_EXTENSION = @MOZ_AUTH_EXTENSION@
|
||||
|
|
14
configure.in
14
configure.in
|
@ -4816,7 +4816,6 @@ NECKO_WIFI=1
|
|||
NECKO_COOKIES=1
|
||||
NECKO_DISK_CACHE=1
|
||||
NECKO_PROTOCOLS_DEFAULT="about data file ftp gopher http res viewsource"
|
||||
NECKO_SMALL_BUFFERS=
|
||||
BUILD_CTYPES=1
|
||||
XPC_IDISPATCH_SUPPORT=
|
||||
|
||||
|
@ -8146,19 +8145,6 @@ if test "$NECKO_WIFI"; then
|
|||
fi
|
||||
AC_SUBST(NECKO_WIFI)
|
||||
|
||||
dnl
|
||||
dnl option to minimize size of necko's i/o buffers
|
||||
dnl
|
||||
MOZ_ARG_ENABLE_BOOL(necko-small-buffers,
|
||||
[ --enable-necko-small-buffers
|
||||
Minimize size of necko's i/o buffers],
|
||||
NECKO_SMALL_BUFFERS=1,
|
||||
NECKO_SMALL_BUFFERS=)
|
||||
AC_SUBST(NECKO_SMALL_BUFFERS)
|
||||
if test "$NECKO_SMALL_BUFFERS"; then
|
||||
AC_DEFINE(NECKO_SMALL_BUFFERS)
|
||||
fi
|
||||
|
||||
dnl
|
||||
dnl option to disable cookies
|
||||
dnl
|
||||
|
|
|
@ -2888,3 +2888,6 @@ pref("browser.history.allowPushState", true);
|
|||
pref("browser.history.allowReplaceState", true);
|
||||
pref("browser.history.allowPopState", true);
|
||||
pref("browser.history.maxStateObjectSize", 655360);
|
||||
|
||||
pref("network.buffer.cache.count", 24);
|
||||
pref("network.buffer.cache.size", 4096);
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsAsyncStreamCopier.h"
|
||||
#include "nsIEventTarget.h"
|
||||
#include "nsStreamUtils.h"
|
||||
|
@ -56,7 +57,7 @@ static PRLogModuleInfo *gStreamCopierLog = nsnull;
|
|||
nsAsyncStreamCopier::nsAsyncStreamCopier()
|
||||
: mLock(nsnull)
|
||||
, mMode(NS_ASYNCCOPY_VIA_READSEGMENTS)
|
||||
, mChunkSize(NET_DEFAULT_SEGMENT_SIZE)
|
||||
, mChunkSize(nsIOService::gDefaultSegmentSize)
|
||||
, mStatus(NS_OK)
|
||||
, mIsPending(PR_FALSE)
|
||||
{
|
||||
|
@ -234,7 +235,7 @@ nsAsyncStreamCopier::Init(nsIInputStream *source,
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (chunkSize == 0)
|
||||
chunkSize = NET_DEFAULT_SEGMENT_SIZE;
|
||||
chunkSize = nsIOService::gDefaultSegmentSize;
|
||||
mChunkSize = chunkSize;
|
||||
|
||||
mSource = source;
|
||||
|
|
|
@ -84,6 +84,9 @@
|
|||
#define AUTODIAL_PREF "network.autodial-helper.enabled"
|
||||
#define MANAGE_OFFLINE_STATUS_PREF "network.manage-offline-status"
|
||||
|
||||
#define NECKO_BUFFER_CACHE_COUNT_PREF "network.buffer.cache.count"
|
||||
#define NECKO_BUFFER_CACHE_SIZE_PREF "network.buffer.cache.size"
|
||||
|
||||
#define MAX_RECURSION_COUNT 50
|
||||
|
||||
nsIOService* gIOService = nsnull;
|
||||
|
@ -162,6 +165,8 @@ static const char kProfileChangeNetRestoreTopic[] = "profile-change-net-restore"
|
|||
|
||||
// Necko buffer cache
|
||||
nsIMemory* nsIOService::gBufferCache = nsnull;
|
||||
PRUint32 nsIOService::gDefaultSegmentSize = 4096;
|
||||
PRUint32 nsIOService::gDefaultSegmentCount = 24;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -175,23 +180,6 @@ nsIOService::nsIOService()
|
|||
, mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
|
||||
, mContentSniffers(NS_CONTENT_SNIFFER_CATEGORY)
|
||||
{
|
||||
// Get the allocator ready
|
||||
if (!gBufferCache)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIRecyclingAllocator> recyclingAllocator =
|
||||
do_CreateInstance(NS_RECYCLINGALLOCATOR_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
rv = recyclingAllocator->Init(NS_NECKO_BUFFER_CACHE_COUNT,
|
||||
NS_NECKO_15_MINS, "necko");
|
||||
if (NS_FAILED(rv))
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIMemory> eyeMemory = do_QueryInterface(recyclingAllocator);
|
||||
gBufferCache = eyeMemory.get();
|
||||
NS_IF_ADDREF(gBufferCache);
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
@ -251,6 +239,22 @@ nsIOService::Init()
|
|||
else
|
||||
NS_WARNING("failed to get observer service");
|
||||
|
||||
// Get the allocator ready
|
||||
if (!gBufferCache) {
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIRecyclingAllocator> recyclingAllocator =
|
||||
do_CreateInstance(NS_RECYCLINGALLOCATOR_CONTRACTID, &rv);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = recyclingAllocator->Init(gDefaultSegmentCount,
|
||||
(15 * 60), // 15 minutes
|
||||
"necko");
|
||||
|
||||
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Was unable to allocate. No gBufferCache.");
|
||||
CallQueryInterface(recyclingAllocator, &gBufferCache);
|
||||
}
|
||||
|
||||
gIOService = this;
|
||||
|
||||
// go into managed mode if we can
|
||||
|
@ -791,6 +795,29 @@ nsIOService::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
|||
&manage)))
|
||||
SetManageOfflineStatus(manage);
|
||||
}
|
||||
|
||||
if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_COUNT_PREF) == 0) {
|
||||
PRInt32 count;
|
||||
if (NS_SUCCEEDED(prefs->GetIntPref(NECKO_BUFFER_CACHE_COUNT_PREF,
|
||||
&count)))
|
||||
/* check for bogus values and default if we find such a value */
|
||||
if (count > 0)
|
||||
gDefaultSegmentCount = count;
|
||||
}
|
||||
|
||||
if (!pref || strcmp(pref, NECKO_BUFFER_CACHE_SIZE_PREF) == 0) {
|
||||
PRInt32 size;
|
||||
if (NS_SUCCEEDED(prefs->GetIntPref(NECKO_BUFFER_CACHE_SIZE_PREF,
|
||||
&size)))
|
||||
/* check for bogus values and default if we find such a value
|
||||
* the upper limit here is arbitrary. having a 1mb segment size
|
||||
* is pretty crazy. if you remove this, consider adding some
|
||||
* integer rollover test.
|
||||
*/
|
||||
if (size > 0 && size < 1024*1024)
|
||||
gDefaultSegmentSize = size;
|
||||
NS_WARN_IF_FALSE( (!(size & (size - 1))) , "network buffer cache size is not a power of 2!");
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -60,13 +60,6 @@
|
|||
|
||||
#define NS_N(x) (sizeof(x)/sizeof(*x))
|
||||
|
||||
#ifdef NECKO_SMALL_BUFFERS
|
||||
#define NS_NECKO_BUFFER_CACHE_COUNT (10) // Max holdings: 10 * 2k = 20k
|
||||
#else
|
||||
#define NS_NECKO_BUFFER_CACHE_COUNT (24) // Max holdings: 24 * 4k = 96k
|
||||
#endif
|
||||
#define NS_NECKO_15_MINS (15 * 60)
|
||||
|
||||
static const char gScheme[][sizeof("resource")] =
|
||||
{"chrome", "file", "http", "jar", "resource"};
|
||||
|
||||
|
@ -159,6 +152,8 @@ public:
|
|||
// Necko buffer cache. Used for all default buffer sizes that necko
|
||||
// allocates.
|
||||
static nsIMemory *gBufferCache;
|
||||
static PRUint32 gDefaultSegmentSize;
|
||||
static PRUint32 gDefaultSegmentCount;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsInputStreamPump.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIStreamTransportService.h"
|
||||
|
@ -44,7 +45,6 @@
|
|||
#include "nsITransport.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsThreadUtils.h"
|
||||
#include "nsNetSegmentUtils.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "prlog.h"
|
||||
|
||||
|
@ -138,8 +138,10 @@ nsInputStreamPump::PeekStream(PeekSegmentFun callback, void* closure)
|
|||
return rv;
|
||||
|
||||
PeekData data(callback, closure);
|
||||
return mAsyncStream->ReadSegments(CallPeekFunc, &data,
|
||||
NET_DEFAULT_SEGMENT_SIZE, &dummy);
|
||||
return mAsyncStream->ReadSegments(CallPeekFunc,
|
||||
&data,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
&dummy);
|
||||
}
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -38,27 +38,18 @@
|
|||
#ifndef nsNetSegmentUtils_h__
|
||||
#define nsNetSegmentUtils_h__
|
||||
|
||||
#include "necko-config.h"
|
||||
#include "nsIOService.h"
|
||||
|
||||
#ifdef NECKO_SMALL_BUFFERS
|
||||
#define NET_DEFAULT_SEGMENT_SIZE 2048
|
||||
#define NET_DEFAULT_SEGMENT_COUNT 4
|
||||
#else
|
||||
#define NET_DEFAULT_SEGMENT_SIZE 4096
|
||||
#define NET_DEFAULT_SEGMENT_COUNT 16
|
||||
#endif
|
||||
|
||||
/**
|
||||
* returns preferred allocator for given segment size. NULL implies
|
||||
* system allocator. this result can be used when allocating a pipe.
|
||||
*/
|
||||
|
||||
static inline nsIMemory *
|
||||
net_GetSegmentAlloc(PRUint32 segsize)
|
||||
{
|
||||
return (segsize == NET_DEFAULT_SEGMENT_SIZE)
|
||||
? nsIOService::gBufferCache
|
||||
: nsnull;
|
||||
return (segsize == nsIOService::gDefaultSegmentSize)
|
||||
? nsIOService::gBufferCache : nsnull;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,9 +59,10 @@ static inline void
|
|||
net_ResolveSegmentParams(PRUint32 &segsize, PRUint32 &segcount)
|
||||
{
|
||||
if (!segsize)
|
||||
segsize = NET_DEFAULT_SEGMENT_SIZE;
|
||||
segsize = nsIOService::gDefaultSegmentSize;
|
||||
|
||||
if (!segcount)
|
||||
segcount = NET_DEFAULT_SEGMENT_COUNT;
|
||||
segcount = nsIOService::gDefaultSegmentCount;
|
||||
}
|
||||
|
||||
#endif // !nsNetSegmentUtils_h__
|
||||
|
|
|
@ -34,16 +34,16 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsSyncStreamListener.h"
|
||||
#include "nsIPipe.h"
|
||||
#include "nsNetSegmentUtils.h"
|
||||
|
||||
nsresult
|
||||
nsSyncStreamListener::Init()
|
||||
{
|
||||
return NS_NewPipe(getter_AddRefs(mPipeIn),
|
||||
getter_AddRefs(mPipeOut),
|
||||
NET_DEFAULT_SEGMENT_SIZE,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
PR_UINT32_MAX, // no size limit
|
||||
PR_FALSE,
|
||||
PR_FALSE);
|
||||
|
|
|
@ -39,8 +39,6 @@
|
|||
|
||||
#undef NECKO_DISK_CACHE
|
||||
|
||||
#undef NECKO_SMALL_BUFFERS
|
||||
|
||||
#undef NECKO_COOKIES
|
||||
|
||||
#undef NECKO_WIFI
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
// data implementation
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsDataChannel.h"
|
||||
#include "nsDataHandler.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -44,7 +45,6 @@
|
|||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsNetSegmentUtils.h"
|
||||
#include "nsEscape.h"
|
||||
#include "plbase64.h"
|
||||
#include "plstr.h"
|
||||
|
@ -82,7 +82,8 @@ nsDataChannel::OpenContentStream(PRBool async, nsIInputStream **result,
|
|||
// create an unbounded pipe.
|
||||
rv = NS_NewPipe(getter_AddRefs(bufInStream),
|
||||
getter_AddRefs(bufOutStream),
|
||||
NET_DEFAULT_SEGMENT_SIZE, PR_UINT32_MAX,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
PR_UINT32_MAX,
|
||||
async, PR_TRUE);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsFileChannel.h"
|
||||
#include "nsBaseContentStream.h"
|
||||
#include "nsDirectoryIndexStream.h"
|
||||
|
@ -46,7 +47,6 @@
|
|||
#include "nsURLHelper.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsNetSegmentUtils.h"
|
||||
#include "nsProxyRelease.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsStandardURL.h"
|
||||
|
@ -107,7 +107,7 @@ nsFileCopyEvent::DoCopy()
|
|||
{
|
||||
// We'll copy in chunks this large by default. This size affects how
|
||||
// frequently we'll check for interrupts.
|
||||
const PRInt32 chunk = NET_DEFAULT_SEGMENT_SIZE * NET_DEFAULT_SEGMENT_COUNT;
|
||||
const PRInt32 chunk = nsIOService::gDefaultSegmentSize * nsIOService::gDefaultSegmentCount;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
|
|
@ -63,12 +63,6 @@
|
|||
#include "nsIResumableChannel.h"
|
||||
#include "nsHashPropertyBag.h"
|
||||
|
||||
#define FTP_COMMAND_CHANNEL_SEG_SIZE 64
|
||||
#define FTP_COMMAND_CHANNEL_SEG_COUNT 8
|
||||
|
||||
#define FTP_DATA_CHANNEL_SEG_SIZE (4*1024)
|
||||
#define FTP_DATA_CHANNEL_SEG_COUNT 8
|
||||
|
||||
class nsFtpChannel : public nsBaseChannel,
|
||||
public nsIFTPChannel,
|
||||
public nsIUploadChannel,
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "prlog.h"
|
||||
#include "prtime.h"
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsFTPChannel.h"
|
||||
#include "nsFtpConnectionThread.h"
|
||||
#include "nsFtpControlConnection.h"
|
||||
|
@ -1528,8 +1529,8 @@ nsFtpState::R_pasv() {
|
|||
// open a buffered, asynchronous socket input stream
|
||||
nsCOMPtr<nsIInputStream> input;
|
||||
rv = mDataTransport->OpenInputStream(0,
|
||||
FTP_DATA_CHANNEL_SEG_SIZE,
|
||||
FTP_DATA_CHANNEL_SEG_COUNT,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
nsIOService::gDefaultSegmentCount,
|
||||
getter_AddRefs(input));
|
||||
NS_ENSURE_SUCCESS(rv, FTP_ERROR);
|
||||
mDataStream = do_QueryInterface(input);
|
||||
|
@ -1655,8 +1656,9 @@ nsFtpState::OpenCacheDataStream()
|
|||
|
||||
// Open a non-blocking, buffered input stream...
|
||||
nsCOMPtr<nsIInputStream> transportInput;
|
||||
transport->OpenInputStream(0, FTP_DATA_CHANNEL_SEG_SIZE,
|
||||
FTP_DATA_CHANNEL_SEG_COUNT,
|
||||
transport->OpenInputStream(0,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
nsIOService::gDefaultSegmentCount,
|
||||
getter_AddRefs(transportInput));
|
||||
NS_ENSURE_STATE(transportInput);
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsFTPChannel.h"
|
||||
#include "nsFtpControlConnection.h"
|
||||
#include "nsFtpProtocolHandler.h"
|
||||
|
@ -153,8 +153,8 @@ nsFtpControlConnection::Connect(nsIProxyInfo* proxyInfo,
|
|||
// open buffered, non-blocking/asynchronous input stream to socket.
|
||||
nsCOMPtr<nsIInputStream> inStream;
|
||||
rv = mSocket->OpenInputStream(0,
|
||||
FTP_COMMAND_CHANNEL_SEG_SIZE,
|
||||
FTP_COMMAND_CHANNEL_SEG_COUNT,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
nsIOService::gDefaultSegmentCount,
|
||||
getter_AddRefs(inStream));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mSocketInput = do_QueryInterface(inStream);
|
||||
|
|
|
@ -80,11 +80,6 @@ extern PRLogModuleInfo *gHttpLog;
|
|||
#define LOG4_ENABLED() PR_LOG_TEST(gHttpLog, 4)
|
||||
#define LOG_ENABLED() LOG4_ENABLED()
|
||||
|
||||
// http default buffer geometry
|
||||
#define NS_HTTP_SEGMENT_SIZE 4096
|
||||
#define NS_HTTP_SEGMENT_COUNT 16 // 64k maximum
|
||||
#define NS_HTTP_MAX_ODA_SIZE (NS_HTTP_SEGMENT_SIZE * 4) // 16k
|
||||
|
||||
// http version codes
|
||||
#define NS_HTTP_VERSION_UNKNOWN 0
|
||||
#define NS_HTTP_VERSION_0_9 9
|
||||
|
|
|
@ -83,7 +83,6 @@
|
|||
#include "nsAuthInformationHolder.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsDNSPrefetch.h"
|
||||
#include "nsNetSegmentUtils.h"
|
||||
|
||||
// True if the local cache should be bypassed when processing a request.
|
||||
#define BYPASS_LOCAL_CACHE(loadFlags) \
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "nsHttpRequestHead.h"
|
||||
#include "nsHttpResponseHead.h"
|
||||
#include "nsHttpHandler.h"
|
||||
#include "nsIOService.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsISocketTransport.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
@ -567,11 +568,12 @@ nsHttpConnection::OnSocketWritable()
|
|||
if (mSSLProxyConnectStream) {
|
||||
LOG((" writing CONNECT request stream\n"));
|
||||
rv = mSSLProxyConnectStream->ReadSegments(ReadFromStream, this,
|
||||
NS_HTTP_SEGMENT_SIZE, &n);
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
&n);
|
||||
}
|
||||
else {
|
||||
LOG((" writing transaction request stream\n"));
|
||||
rv = mTransaction->ReadSegments(this, NS_HTTP_SEGMENT_SIZE, &n);
|
||||
rv = mTransaction->ReadSegments(this, nsIOService::gDefaultSegmentSize, &n);
|
||||
}
|
||||
|
||||
LOG((" ReadSegments returned [rv=%x read=%u sock-cond=%x]\n",
|
||||
|
@ -661,7 +663,7 @@ nsHttpConnection::OnSocketReadable()
|
|||
PRBool again = PR_TRUE;
|
||||
|
||||
do {
|
||||
rv = mTransaction->WriteSegments(this, NS_HTTP_SEGMENT_SIZE, &n);
|
||||
rv = mTransaction->WriteSegments(this, nsIOService::gDefaultSegmentSize, &n);
|
||||
if (NS_FAILED(rv)) {
|
||||
// if the transaction didn't want to take any more data, then
|
||||
// wait for the transaction to call ResumeRecv.
|
||||
|
|
|
@ -277,7 +277,7 @@ nsHttpPipeline::PushBack(const char *data, PRUint32 length)
|
|||
}
|
||||
else if (length > mPushBackMax) {
|
||||
// grow push back buffer as necessary.
|
||||
NS_ASSERTION(length <= NS_HTTP_SEGMENT_SIZE, "too big");
|
||||
NS_ASSERTION(length <= nsIOService::gDefaultSegmentSize, "too big");
|
||||
mPushBackMax = length;
|
||||
mPushBackBuf = (char *) realloc(mPushBackBuf, mPushBackMax);
|
||||
if (!mPushBackBuf)
|
||||
|
@ -558,8 +558,8 @@ nsHttpPipeline::FillSendBuf()
|
|||
// allocate a single-segment pipe
|
||||
rv = NS_NewPipe(getter_AddRefs(mSendBufIn),
|
||||
getter_AddRefs(mSendBufOut),
|
||||
NS_HTTP_SEGMENT_SIZE,
|
||||
NS_HTTP_SEGMENT_SIZE,
|
||||
nsIOService::gDefaultSegmentSize, /* segment size */
|
||||
nsIOService::gDefaultSegmentSize, /* max size */
|
||||
PR_TRUE, PR_TRUE,
|
||||
nsIOService::gBufferCache);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
|
|
@ -107,7 +107,7 @@ private:
|
|||
nsCOMPtr<nsIInputStream> mSendBufIn;
|
||||
nsCOMPtr<nsIOutputStream> mSendBufOut;
|
||||
|
||||
// the push back buffer. not exceeding NS_HTTP_SEGMENT_SIZE bytes.
|
||||
// the push back buffer. not exceeding nsIOService::gDefaultSegmentSize bytes.
|
||||
char *mPushBackBuf;
|
||||
PRUint32 mPushBackLen;
|
||||
PRUint32 mPushBackMax;
|
||||
|
|
|
@ -38,13 +38,13 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsHttpHandler.h"
|
||||
#include "nsHttpTransaction.h"
|
||||
#include "nsHttpConnection.h"
|
||||
#include "nsHttpRequestHead.h"
|
||||
#include "nsHttpResponseHead.h"
|
||||
#include "nsHttpChunkedDecoder.h"
|
||||
#include "nsNetSegmentUtils.h"
|
||||
#include "nsTransportUtils.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsProxyRelease.h"
|
||||
|
@ -291,7 +291,7 @@ nsHttpTransaction::Init(PRUint8 caps,
|
|||
// that we write data in the largest chunks possible. this is actually
|
||||
// necessary to workaround some common server bugs (see bug 137155).
|
||||
rv = NS_NewBufferedInputStream(getter_AddRefs(mRequestStream), multi,
|
||||
NET_DEFAULT_SEGMENT_SIZE);
|
||||
nsIOService::gDefaultSegmentSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
else
|
||||
|
@ -304,8 +304,8 @@ nsHttpTransaction::Init(PRUint8 caps,
|
|||
rv = NS_NewPipe2(getter_AddRefs(mPipeIn),
|
||||
getter_AddRefs(mPipeOut),
|
||||
PR_TRUE, PR_TRUE,
|
||||
NS_HTTP_SEGMENT_SIZE,
|
||||
NS_HTTP_SEGMENT_COUNT,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
nsIOService::gDefaultSegmentCount,
|
||||
nsIOService::gBufferCache);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include "nsIOService.h"
|
||||
#include "nsBinHexDecoder.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIStreamConverterService.h"
|
||||
|
@ -52,11 +53,6 @@
|
|||
#include "nsMimeTypes.h"
|
||||
|
||||
|
||||
#define DATA_BUFFER_SIZE (4096*2)
|
||||
|
||||
#define NS_STREAM_CONVERTER_SEGMENT_SIZE (4*1024)
|
||||
#define NS_STREAM_CONVERTER_BUFFER_SIZE (32*1024)
|
||||
|
||||
// sadly I couldn't find char defintions for CR LF elsehwere in the code (they are defined as strings in nsCRT.h)
|
||||
#define CR '\015'
|
||||
#define LF '\012'
|
||||
|
@ -167,7 +163,7 @@ nsBinHexDecoder::OnDataAvailable(nsIRequest* request,
|
|||
PRUint32 numBytesRead = 0;
|
||||
while (aCount > 0) // while we still have bytes to copy...
|
||||
{
|
||||
aStream->Read(mDataBuffer, PR_MIN(aCount, DATA_BUFFER_SIZE - 1), &numBytesRead);
|
||||
aStream->Read(mDataBuffer, PR_MIN(aCount, nsIOService::gDefaultSegmentSize - 1), &numBytesRead);
|
||||
if (aCount >= numBytesRead)
|
||||
aCount -= numBytesRead; // subtract off the number of bytes we just read
|
||||
else
|
||||
|
@ -276,7 +272,7 @@ nsresult nsBinHexDecoder::ProcessNextState(nsIRequest * aRequest, nsISupports *
|
|||
|
||||
mInCRC = 1;
|
||||
}
|
||||
else if (mPosOutputBuff >= DATA_BUFFER_SIZE)
|
||||
else if (mPosOutputBuff >= (PRInt32) nsIOService::gDefaultSegmentSize)
|
||||
{
|
||||
if (mState == BINHEX_STATE_DFORK)
|
||||
{
|
||||
|
@ -483,14 +479,14 @@ nsBinHexDecoder::OnStartRequest(nsIRequest* request, nsISupports *aCtxt)
|
|||
|
||||
NS_ENSURE_TRUE(mNextListener, NS_ERROR_FAILURE);
|
||||
|
||||
mDataBuffer = (char *) nsMemory::Alloc((sizeof(char) * DATA_BUFFER_SIZE));
|
||||
mOutgoingBuffer = (char *) nsMemory::Alloc((sizeof(char) * DATA_BUFFER_SIZE));
|
||||
mDataBuffer = (char *) nsMemory::Alloc((sizeof(char) * nsIOService::gDefaultSegmentSize));
|
||||
mOutgoingBuffer = (char *) nsMemory::Alloc((sizeof(char) * nsIOService::gDefaultSegmentSize));
|
||||
if (!mDataBuffer || !mOutgoingBuffer) return NS_ERROR_FAILURE; // out of memory;
|
||||
|
||||
// now we want to create a pipe which we'll use to write our converted data...
|
||||
rv = NS_NewPipe(getter_AddRefs(mInputStream), getter_AddRefs(mOutputStream),
|
||||
NS_STREAM_CONVERTER_SEGMENT_SIZE,
|
||||
NS_STREAM_CONVERTER_BUFFER_SIZE,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
nsIOService::gDefaultSegmentSize,
|
||||
PR_TRUE, PR_TRUE);
|
||||
|
||||
// don't propagate the on start request to mNextListener until we have determined the content type.
|
||||
|
|
|
@ -1110,6 +1110,7 @@ nsExternalAppHandler::nsExternalAppHandler(nsIMIMEInfo * aMIMEInfo,
|
|||
, mContentLength(-1)
|
||||
, mProgress(0)
|
||||
, mRequest(nsnull)
|
||||
, mDataBuffer(nsnull)
|
||||
{
|
||||
|
||||
// make sure the extention includes the '.'
|
||||
|
@ -1138,12 +1139,30 @@ nsExternalAppHandler::nsExternalAppHandler(nsIMIMEInfo * aMIMEInfo,
|
|||
EnsureSuggestedFileName();
|
||||
|
||||
gExtProtSvc->AddRef();
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
|
||||
if (!prefs)
|
||||
return;
|
||||
|
||||
mBufferSize = 8192;
|
||||
PRInt32 size;
|
||||
nsresult rv = prefs->GetIntPref("network.buffer.cache.size", &size);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mBufferSize = size;
|
||||
}
|
||||
|
||||
mDataBuffer = (char*) malloc(mBufferSize);
|
||||
if (!mDataBuffer)
|
||||
return;
|
||||
}
|
||||
|
||||
nsExternalAppHandler::~nsExternalAppHandler()
|
||||
{
|
||||
// Not using NS_RELEASE, since we don't want to set gExtProtSvc to NULL
|
||||
gExtProtSvc->Release();
|
||||
|
||||
if (mDataBuffer)
|
||||
free(mDataBuffer);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsExternalAppHandler::SetWebProgressListener(nsIWebProgressListener2 * aWebProgressListener)
|
||||
|
@ -1758,7 +1777,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIRequest *request, nsISupp
|
|||
{
|
||||
nsresult rv = NS_OK;
|
||||
// first, check to see if we've been canceled....
|
||||
if (mCanceled) // then go cancel our underlying channel too
|
||||
if (mCanceled || !mDataBuffer) // then go cancel our underlying channel too
|
||||
return request->Cancel(NS_BINDING_ABORTED);
|
||||
|
||||
// read the data out of the stream and write it to the temp file.
|
||||
|
@ -1771,7 +1790,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnDataAvailable(nsIRequest *request, nsISupp
|
|||
while (NS_SUCCEEDED(rv) && count > 0) // while we still have bytes to copy...
|
||||
{
|
||||
readError = PR_TRUE;
|
||||
rv = inStr->Read(mDataBuffer, PR_MIN(count, DATA_BUFFER_SIZE - 1), &numBytesRead);
|
||||
rv = inStr->Read(mDataBuffer, PR_MIN(count, mBufferSize - 1), &numBytesRead);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (count >= numBytesRead)
|
||||
|
|
|
@ -237,13 +237,6 @@ protected:
|
|||
PRBool mInPrivateBrowsing;
|
||||
};
|
||||
|
||||
/**
|
||||
* We need to read the data out of the incoming stream into a buffer which we
|
||||
* can then use to write the data into the output stream representing the
|
||||
* temp file.
|
||||
*/
|
||||
#define DATA_BUFFER_SIZE (4096*2)
|
||||
|
||||
/**
|
||||
* An external app handler is just a small little class that presents itself as
|
||||
* a nsIStreamListener. It saves the incoming data into a temp file. The handler
|
||||
|
@ -359,7 +352,8 @@ protected:
|
|||
*/
|
||||
nsCOMPtr<nsIFile> mFinalFileDestination;
|
||||
|
||||
char mDataBuffer[DATA_BUFFER_SIZE];
|
||||
PRUint32 mBufferSize;
|
||||
char *mDataBuffer;
|
||||
|
||||
/**
|
||||
* Creates the temporary file for the download and an output stream for it.
|
||||
|
|
Загрузка…
Ссылка в новой задаче