mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 20:47:44 +00:00
bug 378637 part 5 - move Spdy*::EnsureBuffer to nsHttp r=hurley
--HG-- extra : rebase_source : 015e1e73261153a747dc5430f377ed29858903d1
This commit is contained in:
parent
668ffd4224
commit
33cd538fd5
@ -233,10 +233,8 @@ Http2PushTransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer,
|
||||
uint32_t count, uint32_t *countWritten)
|
||||
{
|
||||
if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) {
|
||||
Http2Session::EnsureBuffer(mBufferedHTTP1,
|
||||
mBufferedHTTP1Size + kDefaultBufferSize,
|
||||
mBufferedHTTP1Used,
|
||||
mBufferedHTTP1Size);
|
||||
EnsureBuffer(mBufferedHTTP1,mBufferedHTTP1Size + kDefaultBufferSize,
|
||||
mBufferedHTTP1Used, mBufferedHTTP1Size);
|
||||
}
|
||||
|
||||
count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used);
|
||||
|
@ -562,34 +562,6 @@ Http2Session::ResetDownstreamState()
|
||||
mInputFrameDataStream = nullptr;
|
||||
}
|
||||
|
||||
template<typename T> void
|
||||
Http2Session::EnsureBuffer(nsAutoArrayPtr<T> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize)
|
||||
{
|
||||
if (objSize >= newSize)
|
||||
return;
|
||||
|
||||
// Leave a little slop on the new allocation - add 2KB to
|
||||
// what we need and then round the result up to a 4KB (page)
|
||||
// boundary.
|
||||
|
||||
objSize = (newSize + 2048 + 4095) & ~4095;
|
||||
|
||||
static_assert(sizeof(T) == 1, "sizeof(T) must be 1");
|
||||
nsAutoArrayPtr<T> tmp(new T[objSize]);
|
||||
memcpy(tmp, buf, preserve);
|
||||
buf = tmp;
|
||||
}
|
||||
|
||||
// Instantiate supported templates explicitly.
|
||||
template void
|
||||
Http2Session::EnsureBuffer(nsAutoArrayPtr<char> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize);
|
||||
|
||||
template void
|
||||
Http2Session::EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize);
|
||||
|
||||
// call with data length (i.e. 0 for 0 data bytes - ignore 8 byte header)
|
||||
// dest must have 8 bytes of allocated space
|
||||
template<typename charType> void
|
||||
|
@ -166,9 +166,6 @@ public:
|
||||
static nsresult RecvAltSvc(Http2Session *);
|
||||
static nsresult RecvBlocked(Http2Session *);
|
||||
|
||||
template<typename T>
|
||||
static void EnsureBuffer(nsAutoArrayPtr<T> &,
|
||||
uint32_t, uint32_t, uint32_t &);
|
||||
char *EnsureOutputBuffer(uint32_t needed);
|
||||
|
||||
template<typename charType>
|
||||
|
@ -421,10 +421,8 @@ Http2Stream::ParseHttpRequestHeaders(const char *buf,
|
||||
messageSize += 13; // frame header + priority overhead in HEADERS frame
|
||||
messageSize += (numFrames - 1) * 8; // frame header overhead in CONTINUATION frames
|
||||
|
||||
Http2Session::EnsureBuffer(mTxInlineFrame,
|
||||
dataLength + messageSize,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, dataLength + messageSize,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
|
||||
mTxInlineFrameUsed += messageSize;
|
||||
LOG3(("%p Generating %d bytes of HEADERS for stream 0x%X with priority weight %u frames %u\n",
|
||||
@ -546,10 +544,8 @@ Http2Stream::AdjustInitialWindow()
|
||||
}
|
||||
|
||||
uint8_t *packet = mTxInlineFrame.get() + mTxInlineFrameUsed;
|
||||
Http2Session::EnsureBuffer(mTxInlineFrame,
|
||||
mTxInlineFrameUsed + 12,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 12,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
mTxInlineFrameUsed += 12;
|
||||
|
||||
mSession->CreateFrameHeader(packet, 4,
|
||||
@ -582,10 +578,8 @@ Http2Stream::AdjustPushedPriority()
|
||||
return;
|
||||
|
||||
uint8_t *packet = mTxInlineFrame.get() + mTxInlineFrameUsed;
|
||||
Http2Session::EnsureBuffer(mTxInlineFrame,
|
||||
mTxInlineFrameUsed + 13,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 13,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
mTxInlineFrameUsed += 13;
|
||||
|
||||
mSession->CreateFrameHeader(packet, 5,
|
||||
|
@ -257,10 +257,8 @@ SpdyPush3TransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer,
|
||||
uint32_t count, uint32_t *countWritten)
|
||||
{
|
||||
if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) {
|
||||
SpdySession3::EnsureBuffer(mBufferedHTTP1,
|
||||
mBufferedHTTP1Size + kDefaultBufferSize,
|
||||
mBufferedHTTP1Used,
|
||||
mBufferedHTTP1Size);
|
||||
EnsureBuffer(mBufferedHTTP1, mBufferedHTTP1Size + kDefaultBufferSize,
|
||||
mBufferedHTTP1Used, mBufferedHTTP1Size);
|
||||
}
|
||||
|
||||
count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used);
|
||||
|
@ -255,10 +255,8 @@ SpdyPush31TransactionBuffer::WriteSegments(nsAHttpSegmentWriter *writer,
|
||||
uint32_t count, uint32_t *countWritten)
|
||||
{
|
||||
if ((mBufferedHTTP1Size - mBufferedHTTP1Used) < 20480) {
|
||||
SpdySession31::EnsureBuffer(mBufferedHTTP1,
|
||||
mBufferedHTTP1Size + kDefaultBufferSize,
|
||||
mBufferedHTTP1Used,
|
||||
mBufferedHTTP1Size);
|
||||
EnsureBuffer(mBufferedHTTP1, mBufferedHTTP1Size + kDefaultBufferSize,
|
||||
mBufferedHTTP1Used, mBufferedHTTP1Size);
|
||||
}
|
||||
|
||||
count = std::min(count, mBufferedHTTP1Size - mBufferedHTTP1Used);
|
||||
|
@ -535,40 +535,6 @@ SpdySession3::ResetDownstreamState()
|
||||
mInputFrameDataStream = nullptr;
|
||||
}
|
||||
|
||||
template<typename T> void
|
||||
SpdySession3::EnsureBuffer(nsAutoArrayPtr<T> &buf,
|
||||
uint32_t newSize,
|
||||
uint32_t preserve,
|
||||
uint32_t &objSize)
|
||||
{
|
||||
if (objSize >= newSize)
|
||||
return;
|
||||
|
||||
// Leave a little slop on the new allocation - add 2KB to
|
||||
// what we need and then round the result up to a 4KB (page)
|
||||
// boundary.
|
||||
|
||||
objSize = (newSize + 2048 + 4095) & ~4095;
|
||||
|
||||
static_assert(sizeof(T) == 1, "sizeof(T) must be 1");
|
||||
nsAutoArrayPtr<T> tmp(new T[objSize]);
|
||||
memcpy(tmp, buf, preserve);
|
||||
buf = tmp;
|
||||
}
|
||||
|
||||
// Instantiate supported templates explicitly.
|
||||
template void
|
||||
SpdySession3::EnsureBuffer(nsAutoArrayPtr<char> &buf,
|
||||
uint32_t newSize,
|
||||
uint32_t preserve,
|
||||
uint32_t &objSize);
|
||||
|
||||
template void
|
||||
SpdySession3::EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf,
|
||||
uint32_t newSize,
|
||||
uint32_t preserve,
|
||||
uint32_t &objSize);
|
||||
|
||||
void
|
||||
SpdySession3::DecrementConcurrent(SpdyStream3 *aStream)
|
||||
{
|
||||
|
@ -158,10 +158,6 @@ public:
|
||||
static nsresult HandleWindowUpdate(SpdySession3 *);
|
||||
static nsresult HandleCredential(SpdySession3 *);
|
||||
|
||||
template<typename T>
|
||||
static void EnsureBuffer(nsAutoArrayPtr<T> &,
|
||||
uint32_t, uint32_t, uint32_t &);
|
||||
|
||||
// For writing the SPDY data stream to LOG4
|
||||
static void LogIO(SpdySession3 *, SpdyStream3 *, const char *,
|
||||
const char *, uint32_t);
|
||||
|
@ -540,40 +540,6 @@ SpdySession31::ResetDownstreamState()
|
||||
mInputFrameDataStream = nullptr;
|
||||
}
|
||||
|
||||
template<typename T> void
|
||||
SpdySession31::EnsureBuffer(nsAutoArrayPtr<T> &buf,
|
||||
uint32_t newSize,
|
||||
uint32_t preserve,
|
||||
uint32_t &objSize)
|
||||
{
|
||||
if (objSize >= newSize)
|
||||
return;
|
||||
|
||||
// Leave a little slop on the new allocation - add 2KB to
|
||||
// what we need and then round the result up to a 4KB (page)
|
||||
// boundary.
|
||||
|
||||
objSize = (newSize + 2048 + 4095) & ~4095;
|
||||
|
||||
static_assert(sizeof(T) == 1, "sizeof(T) must be 1");
|
||||
nsAutoArrayPtr<T> tmp(new T[objSize]);
|
||||
memcpy(tmp, buf, preserve);
|
||||
buf = tmp;
|
||||
}
|
||||
|
||||
// Instantiate supported templates explicitly.
|
||||
template void
|
||||
SpdySession31::EnsureBuffer(nsAutoArrayPtr<char> &buf,
|
||||
uint32_t newSize,
|
||||
uint32_t preserve,
|
||||
uint32_t &objSize);
|
||||
|
||||
template void
|
||||
SpdySession31::EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf,
|
||||
uint32_t newSize,
|
||||
uint32_t preserve,
|
||||
uint32_t &objSize);
|
||||
|
||||
void
|
||||
SpdySession31::DecrementConcurrent(SpdyStream31 *aStream)
|
||||
{
|
||||
|
@ -157,10 +157,6 @@ public:
|
||||
static nsresult HandleWindowUpdate(SpdySession31 *);
|
||||
static nsresult HandleCredential(SpdySession31 *);
|
||||
|
||||
template<typename T>
|
||||
static void EnsureBuffer(nsAutoArrayPtr<T> &,
|
||||
uint32_t, uint32_t, uint32_t &);
|
||||
|
||||
// For writing the SPDY data stream to LOG4
|
||||
static void LogIO(SpdySession31 *, SpdyStream31 *, const char *,
|
||||
const char *, uint32_t);
|
||||
|
@ -569,10 +569,8 @@ SpdyStream3::AdjustInitialWindow()
|
||||
return;
|
||||
toack = PR_htonl(toack);
|
||||
|
||||
SpdySession3::EnsureBuffer(mTxInlineFrame,
|
||||
mTxInlineFrameUsed + 16,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 16,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
|
||||
unsigned char *packet = mTxInlineFrame.get() + mTxInlineFrameUsed;
|
||||
mTxInlineFrameUsed += 16;
|
||||
@ -1039,10 +1037,8 @@ SpdyStream3::Uncompress(z_stream *context,
|
||||
!context->avail_out && context->avail_in) {
|
||||
LOG3(("SpdyStream3::Uncompress %p Large Headers - so far %d",
|
||||
this, mDecompressBufferSize));
|
||||
SpdySession3::EnsureBuffer(mDecompressBuffer,
|
||||
mDecompressBufferSize + 4096,
|
||||
mDecompressBufferUsed,
|
||||
mDecompressBufferSize);
|
||||
EnsureBuffer(mDecompressBuffer, mDecompressBufferSize + 4096,
|
||||
mDecompressBufferUsed, mDecompressBufferSize);
|
||||
}
|
||||
}
|
||||
while (context->avail_in);
|
||||
@ -1263,10 +1259,8 @@ SpdyStream3::ExecuteCompress(uint32_t flushMode)
|
||||
{
|
||||
uint32_t avail = mTxInlineFrameSize - mTxInlineFrameUsed;
|
||||
if (avail < 1) {
|
||||
SpdySession3::EnsureBuffer(mTxInlineFrame,
|
||||
mTxInlineFrameSize + 2000,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, mTxInlineFrameSize + 2000,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
avail = mTxInlineFrameSize - mTxInlineFrameUsed;
|
||||
}
|
||||
|
||||
|
@ -575,10 +575,8 @@ SpdyStream31::AdjustInitialWindow()
|
||||
return;
|
||||
toack = PR_htonl(toack);
|
||||
|
||||
SpdySession31::EnsureBuffer(mTxInlineFrame,
|
||||
mTxInlineFrameUsed + 16,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, mTxInlineFrameUsed + 16,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
|
||||
unsigned char *packet = mTxInlineFrame.get() + mTxInlineFrameUsed;
|
||||
mTxInlineFrameUsed += 16;
|
||||
@ -1055,10 +1053,8 @@ SpdyStream31::Uncompress(z_stream *context,
|
||||
!context->avail_out && context->avail_in) {
|
||||
LOG3(("SpdyStream31::Uncompress %p Large Headers - so far %d",
|
||||
this, mDecompressBufferSize));
|
||||
SpdySession31::EnsureBuffer(mDecompressBuffer,
|
||||
mDecompressBufferSize + 4096,
|
||||
mDecompressBufferUsed,
|
||||
mDecompressBufferSize);
|
||||
EnsureBuffer(mDecompressBuffer, mDecompressBufferSize + 4096,
|
||||
mDecompressBufferUsed, mDecompressBufferSize);
|
||||
}
|
||||
}
|
||||
while (context->avail_in);
|
||||
@ -1279,10 +1275,8 @@ SpdyStream31::ExecuteCompress(uint32_t flushMode)
|
||||
{
|
||||
uint32_t avail = mTxInlineFrameSize - mTxInlineFrameUsed;
|
||||
if (avail < 1) {
|
||||
SpdySession31::EnsureBuffer(mTxInlineFrame,
|
||||
mTxInlineFrameSize + 2000,
|
||||
mTxInlineFrameUsed,
|
||||
mTxInlineFrameSize);
|
||||
EnsureBuffer(mTxInlineFrame, mTxInlineFrameSize + 2000,
|
||||
mTxInlineFrameUsed, mTxInlineFrameSize);
|
||||
avail = mTxInlineFrameSize - mTxInlineFrameUsed;
|
||||
}
|
||||
|
||||
|
@ -295,5 +295,39 @@ nsHttp::IsPermanentRedirect(uint32_t httpStatus)
|
||||
return httpStatus == 301 || httpStatus == 308;
|
||||
}
|
||||
|
||||
|
||||
template<typename T> void
|
||||
localEnsureBuffer(nsAutoArrayPtr<T> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize)
|
||||
{
|
||||
if (objSize >= newSize)
|
||||
return;
|
||||
|
||||
// Leave a little slop on the new allocation - add 2KB to
|
||||
// what we need and then round the result up to a 4KB (page)
|
||||
// boundary.
|
||||
|
||||
objSize = (newSize + 2048 + 4095) & ~4095;
|
||||
|
||||
static_assert(sizeof(T) == 1, "sizeof(T) must be 1");
|
||||
nsAutoArrayPtr<T> tmp(new T[objSize]);
|
||||
if (preserve) {
|
||||
memcpy(tmp, buf, preserve);
|
||||
}
|
||||
buf = tmp;
|
||||
}
|
||||
|
||||
void EnsureBuffer(nsAutoArrayPtr<char> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize)
|
||||
{
|
||||
localEnsureBuffer<char> (buf, newSize, preserve, objSize);
|
||||
}
|
||||
|
||||
void EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize)
|
||||
{
|
||||
localEnsureBuffer<uint8_t> (buf, newSize, preserve, objSize);
|
||||
}
|
||||
|
||||
} // namespace mozilla::net
|
||||
} // namespace mozilla
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include "prtime.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsError.h"
|
||||
|
||||
@ -190,6 +191,11 @@ PRTimeToSeconds(PRTime t_usec)
|
||||
#define HTTP_LWS " \t"
|
||||
#define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
|
||||
|
||||
void EnsureBuffer(nsAutoArrayPtr<char> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize);
|
||||
void EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf, uint32_t newSize,
|
||||
uint32_t preserve, uint32_t &objSize);
|
||||
|
||||
} // namespace mozilla::net
|
||||
} // namespace mozilla
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user