bug 378637 part 7 - new spdysession() no longer takes first transaction r=hurley

--HG--
extra : rebase_source : af83fcffa83f1da4250b0a9528e148619f9e3838
This commit is contained in:
Patrick McManus 2014-05-16 11:46:11 -04:00
parent 9b59ad684a
commit aac29549b6
9 changed files with 78 additions and 70 deletions

View File

@ -30,9 +30,7 @@ namespace net {
ASpdySession *
ASpdySession::NewSpdySession(uint32_t version,
nsAHttpTransaction *aTransaction,
nsISocketTransport *aTransport,
int32_t aPriority)
nsISocketTransport *aTransport)
{
// This is a necko only interface, so we can enforce version
// requests as a precondition
@ -48,14 +46,13 @@ ASpdySession::NewSpdySession(uint32_t version,
Telemetry::Accumulate(Telemetry::SPDY_VERSION2, version);
if (version == SPDY_VERSION_3)
return new SpdySession3(aTransaction, aTransport, aPriority);
if (version == SPDY_VERSION_31)
return new SpdySession31(aTransaction, aTransport, aPriority);
if (version == NS_HTTP2_DRAFT_VERSION)
return new Http2Session(aTransaction, aTransport, aPriority);
if (version == SPDY_VERSION_3) {
return new SpdySession3(aTransport);
} else if (version == SPDY_VERSION_31) {
return new SpdySession31(aTransport);
} else if (version == NS_HTTP2_DRAFT_VERSION) {
return new Http2Session(aTransport);
}
return nullptr;
}

View File

@ -25,10 +25,7 @@ public:
virtual uint32_t ReadTimeoutTick(PRIntervalTime now) = 0;
virtual void DontReuse() = 0;
static ASpdySession *NewSpdySession(uint32_t version,
nsAHttpTransaction *,
nsISocketTransport *,
int32_t);
static ASpdySession *NewSpdySession(uint32_t version, nsISocketTransport *);
virtual void PrintDiagnostics (nsCString &log) = 0;

View File

@ -63,9 +63,7 @@ do { \
return NS_ERROR_ILLEGAL_VALUE; \
} while (0)
Http2Session::Http2Session(nsAHttpTransaction *aHttpTransaction,
nsISocketTransport *aSocketTransport,
int32_t firstPriority)
Http2Session::Http2Session(nsISocketTransport *aSocketTransport)
: mSocketTransport(aSocketTransport)
, mSegmentReader(nullptr)
, mSegmentWriter(nullptr)
@ -100,30 +98,26 @@ Http2Session::Http2Session(nsAHttpTransaction *aHttpTransaction,
, mLastReadEpoch(PR_IntervalNow())
, mPingSentEpoch(0)
{
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
MOZ_ASSERT(PR_GetCurrentThread() == gSocketThread);
static uint64_t sSerial;
mSerial = ++sSerial;
static uint64_t sSerial;
mSerial = ++sSerial;
LOG3(("Http2Session::Http2Session %p transaction 1 = %p serial=0x%X\n",
this, aHttpTransaction, mSerial));
LOG3(("Http2Session::Http2Session %p serial=0x%X\n", this, mSerial));
mConnection = aHttpTransaction->Connection();
mInputFrameBuffer = new char[mInputFrameBufferSize];
mOutputQueueBuffer = new char[mOutputQueueSize];
mDecompressBuffer.SetCapacity(kDefaultBufferSize);
mDecompressor.SetCompressor(&mCompressor);
mInputFrameBuffer = new char[mInputFrameBufferSize];
mOutputQueueBuffer = new char[mOutputQueueSize];
mDecompressBuffer.SetCapacity(kDefaultBufferSize);
mDecompressor.SetCompressor(&mCompressor);
mPushAllowance = gHttpHandler->SpdyPushAllowance();
mPushAllowance = gHttpHandler->SpdyPushAllowance();
mSendingChunkSize = gHttpHandler->SpdySendingChunkSize();
SendHello();
mSendingChunkSize = gHttpHandler->SpdySendingChunkSize();
SendHello();
if (!aHttpTransaction->IsNullTransaction())
AddStream(aHttpTransaction, firstPriority);
mLastDataReadEpoch = mLastReadEpoch;
mLastDataReadEpoch = mLastReadEpoch;
mPingThreshold = gHttpHandler->SpdyPingThreshold();
mPingThreshold = gHttpHandler->SpdyPingThreshold();
}
// Copy the 32 bit number into the destination, using network byte order
@ -390,6 +384,18 @@ Http2Session::AddStream(nsAHttpTransaction *aHttpTransaction,
return false;
}
// assert that
// a] in the case we have a connection, that the new transaction connection
// is either undefined or on the same connection
// b] in the case we don't have a connection, that the new transaction
// connection is defined so we can adopt it
MOZ_ASSERT((mConnection && (!aHttpTransaction->Connection() ||
mConnection == aHttpTransaction->Connection())) ||
(!mConnection && aHttpTransaction->Connection()));
if (!mConnection) {
mConnection = aHttpTransaction->Connection();
}
aHttpTransaction->SetConnection(this);
Http2Stream *stream = new Http2Stream(aHttpTransaction, this, aPriority);

View File

@ -38,7 +38,7 @@ public:
NS_DECL_NSAHTTPSEGMENTREADER
NS_DECL_NSAHTTPSEGMENTWRITER
Http2Session(nsAHttpTransaction *, nsISocketTransport *, int32_t);
Http2Session(nsISocketTransport *);
~Http2Session();
bool AddStream(nsAHttpTransaction *, int32_t);

View File

@ -44,9 +44,7 @@ NS_INTERFACE_MAP_BEGIN(SpdySession3)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsAHttpConnection)
NS_INTERFACE_MAP_END
SpdySession3::SpdySession3(nsAHttpTransaction *aHttpTransaction,
nsISocketTransport *aSocketTransport,
int32_t firstPriority)
SpdySession3::SpdySession3(nsISocketTransport *aSocketTransport)
: mSocketTransport(aSocketTransport)
, mSegmentReader(nullptr)
, mSegmentWriter(nullptr)
@ -79,10 +77,8 @@ SpdySession3::SpdySession3(nsAHttpTransaction *aHttpTransaction,
static uint64_t sSerial;
mSerial = ++sSerial;
LOG3(("SpdySession3::SpdySession3 %p transaction 1 = %p serial=0x%X\n",
this, aHttpTransaction, mSerial));
LOG3(("SpdySession3::SpdySession3 %p serial=0x%X\n", this, mSerial));
mConnection = aHttpTransaction->Connection();
mInputFrameBuffer = new char[mInputFrameBufferSize];
mOutputQueueBuffer = new char[mOutputQueueSize];
zlibInit();
@ -91,8 +87,6 @@ SpdySession3::SpdySession3(nsAHttpTransaction *aHttpTransaction,
mSendingChunkSize = gHttpHandler->SpdySendingChunkSize();
GenerateSettings();
if (!aHttpTransaction->IsNullTransaction())
AddStream(aHttpTransaction, firstPriority);
mLastDataReadEpoch = mLastReadEpoch;
mPingThreshold = gHttpHandler->SpdyPingThreshold();
@ -351,6 +345,18 @@ SpdySession3::AddStream(nsAHttpTransaction *aHttpTransaction,
return false;
}
// assert that
// a] in the case we have a connection, that the new transaction connection
// is either undefined or on the same connection
// b] in the case we don't have a connection, that the new transaction
// connection is defined so we can adopt it
MOZ_ASSERT((mConnection && (!aHttpTransaction->Connection() ||
mConnection == aHttpTransaction->Connection())) ||
(!mConnection && aHttpTransaction->Connection()));
if (!mConnection) {
mConnection = aHttpTransaction->Connection();
}
aHttpTransaction->SetConnection(this);
SpdyStream3 *stream = new SpdyStream3(aHttpTransaction, this, aPriority);

View File

@ -37,7 +37,7 @@ public:
NS_DECL_NSAHTTPSEGMENTREADER
NS_DECL_NSAHTTPSEGMENTWRITER
SpdySession3(nsAHttpTransaction *, nsISocketTransport *, int32_t);
SpdySession3(nsISocketTransport *);
~SpdySession3();
bool AddStream(nsAHttpTransaction *, int32_t);

View File

@ -45,9 +45,7 @@ NS_INTERFACE_MAP_BEGIN(SpdySession31)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsAHttpConnection)
NS_INTERFACE_MAP_END
SpdySession31::SpdySession31(nsAHttpTransaction *aHttpTransaction,
nsISocketTransport *aSocketTransport,
int32_t firstPriority)
SpdySession31::SpdySession31(nsISocketTransport *aSocketTransport)
: mSocketTransport(aSocketTransport)
, mSegmentReader(nullptr)
, mSegmentWriter(nullptr)
@ -82,10 +80,8 @@ SpdySession31::SpdySession31(nsAHttpTransaction *aHttpTransaction,
static uint64_t sSerial;
mSerial = ++sSerial;
LOG3(("SpdySession31::SpdySession31 %p transaction 1 = %p serial=0x%X\n",
this, aHttpTransaction, mSerial));
LOG3(("SpdySession31::SpdySession31 %p serial=0x%X\n", this, mSerial));
mConnection = aHttpTransaction->Connection();
mInputFrameBuffer = new char[mInputFrameBufferSize];
mOutputQueueBuffer = new char[mOutputQueueSize];
zlibInit();
@ -95,8 +91,6 @@ SpdySession31::SpdySession31(nsAHttpTransaction *aHttpTransaction,
mSendingChunkSize = gHttpHandler->SpdySendingChunkSize();
GenerateSettings();
if (!aHttpTransaction->IsNullTransaction())
AddStream(aHttpTransaction, firstPriority);
mLastDataReadEpoch = mLastReadEpoch;
mPingThreshold = gHttpHandler->SpdyPingThreshold();
@ -355,6 +349,18 @@ SpdySession31::AddStream(nsAHttpTransaction *aHttpTransaction,
return false;
}
// assert that
// a] in the case we have a connection, that the new transaction connection
// is either undefined or on the same connection
// b] in the case we don't have a connection, that the new transaction
// connection is defined so we can adopt it
MOZ_ASSERT((mConnection && (!aHttpTransaction->Connection() ||
mConnection == aHttpTransaction->Connection())) ||
(!mConnection && aHttpTransaction->Connection()));
if (!mConnection) {
mConnection = aHttpTransaction->Connection();
}
aHttpTransaction->SetConnection(this);
SpdyStream31 *stream = new SpdyStream31(aHttpTransaction, this, aPriority);

View File

@ -36,7 +36,7 @@ public:
NS_DECL_NSAHTTPSEGMENTREADER
NS_DECL_NSAHTTPSEGMENTWRITER
SpdySession31(nsAHttpTransaction *, nsISocketTransport *, int32_t);
SpdySession31(nsISocketTransport *);
~SpdySession31();
bool AddStream(nsAHttpTransaction *, int32_t);

View File

@ -197,15 +197,18 @@ nsHttpConnection::StartSpdy(uint8_t spdyVersion)
return;
}
mSpdySession = ASpdySession::NewSpdySession(spdyVersion, mSocketTransport);
if (NS_FAILED(rv)) { // includes NS_ERROR_NOT_IMPLEMENTED
MOZ_ASSERT(list.IsEmpty(), "sub transaction list not empty");
// This is ok - treat mTransaction as a single real request.
// Wrap the old http transaction into the new spdy session
// as the first stream.
mSpdySession = ASpdySession::NewSpdySession(spdyVersion,
mTransaction, mSocketTransport,
mPriority);
if (!mSpdySession->AddStream(mTransaction, mPriority)) {
MOZ_ASSERT(false); // this cannot happen!
mTransaction->Close(NS_ERROR_ABORT);
return;
}
LOG(("nsHttpConnection::StartSpdy moves single transaction %p "
"into SpdySession %p\n", mTransaction.get(), mSpdySession.get()));
}
@ -221,19 +224,12 @@ nsHttpConnection::StartSpdy(uint8_t spdyVersion)
}
for (int32_t index = 0; index < count; ++index) {
if (!mSpdySession) {
mSpdySession = ASpdySession::NewSpdySession(spdyVersion,
list[index], mSocketTransport,
mPriority);
}
else {
// AddStream() cannot fail
if (!mSpdySession->AddStream(list[index], mPriority)) {
MOZ_ASSERT(false, "SpdySession::AddStream failed");
LOG(("SpdySession::AddStream failed\n"));
mTransaction->Close(NS_ERROR_ABORT);
return;
}
// AddStream() cannot fail
if (!mSpdySession->AddStream(list[index], mPriority)) {
MOZ_ASSERT(false, "SpdySession::AddStream failed");
LOG(("SpdySession::AddStream failed\n"));
mTransaction->Close(NS_ERROR_ABORT);
return;
}
}
}