From 285f985254950132b1c2d62f6915ba191ce84bda Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Mon, 14 May 2012 13:25:28 -0400 Subject: [PATCH] bug 752648 - fix regression with restarting due to tls intolerance r=honzab --HG-- extra : rebase_source : 8155ae4c221df4c5931816fb8773123cc37dd148 --- netwerk/protocol/http/SpdySession.h | 2 +- netwerk/protocol/http/nsAHttpConnection.h | 10 ++++++++-- netwerk/protocol/http/nsHttpConnection.cpp | 6 +++++- netwerk/protocol/http/nsHttpConnection.h | 3 +++ netwerk/protocol/http/nsHttpConnectionMgr.h | 2 +- netwerk/protocol/http/nsHttpPipeline.h | 2 +- netwerk/protocol/http/nsHttpTransaction.cpp | 10 +++++++++- 7 files changed, 28 insertions(+), 7 deletions(-) diff --git a/netwerk/protocol/http/SpdySession.h b/netwerk/protocol/http/SpdySession.h index 3ac43238d7c..6aa1ba48229 100644 --- a/netwerk/protocol/http/SpdySession.h +++ b/netwerk/protocol/http/SpdySession.h @@ -66,7 +66,7 @@ class SpdySession : public nsAHttpTransaction public: NS_DECL_ISUPPORTS NS_DECL_NSAHTTPTRANSACTION - NS_DECL_NSAHTTPCONNECTION + NS_DECL_NSAHTTPCONNECTION(mConnection) NS_DECL_NSAHTTPSEGMENTREADER NS_DECL_NSAHTTPSEGMENTWRITER diff --git a/netwerk/protocol/http/nsAHttpConnection.h b/netwerk/protocol/http/nsAHttpConnection.h index aeabb751a5c..f05447b848c 100644 --- a/netwerk/protocol/http/nsAHttpConnection.h +++ b/netwerk/protocol/http/nsAHttpConnection.h @@ -153,9 +153,13 @@ public: // Read and write class of transaction that is carried on this connection virtual nsAHttpTransaction::Classifier Classification() = 0; virtual void Classify(nsAHttpTransaction::Classifier newclass) = 0; + + // The number of transaction bytes written out on this HTTP Connection, does + // not count CONNECT tunnel setup + virtual PRInt64 BytesWritten() = 0; }; -#define NS_DECL_NSAHTTPCONNECTION \ +#define NS_DECL_NSAHTTPCONNECTION(fwdObject) \ nsresult OnHeadersAvailable(nsAHttpTransaction *, nsHttpRequestHead *, nsHttpResponseHead *, bool *reset); \ nsresult ResumeSend(); \ nsresult ResumeRecv(); \ @@ -176,6 +180,8 @@ public: nsISocketTransport *Transport(); \ PRUint32 CancelPipeline(nsresult originalReason); \ nsAHttpTransaction::Classifier Classification(); \ - void Classify(nsAHttpTransaction::Classifier); + void Classify(nsAHttpTransaction::Classifier); \ + PRInt64 BytesWritten() \ + { return fwdObject ? (fwdObject)->BytesWritten() : 0; } #endif // nsAHttpConnection_h__ diff --git a/netwerk/protocol/http/nsHttpConnection.cpp b/netwerk/protocol/http/nsHttpConnection.cpp index d81b9922993..ffc5c27f922 100644 --- a/netwerk/protocol/http/nsHttpConnection.cpp +++ b/netwerk/protocol/http/nsHttpConnection.cpp @@ -79,6 +79,7 @@ nsHttpConnection::nsHttpConnection() , mCurrentBytesRead(0) , mMaxBytesRead(0) , mTotalBytesRead(0) + , mTotalBytesWritten(0) , mKeepAlive(true) // assume to keep-alive by default , mKeepAliveMask(true) , mSupportsPipelining(false) // assume low-grade server @@ -1194,8 +1195,11 @@ nsHttpConnection::OnReadSegment(const char *buf, mSocketOutCondition = rv; else if (*countRead == 0) mSocketOutCondition = NS_BASE_STREAM_CLOSED; - else + else { mSocketOutCondition = NS_OK; // reset condition + if (!mProxyConnectInProgress) + mTotalBytesWritten += *countRead; + } return mSocketOutCondition; } diff --git a/netwerk/protocol/http/nsHttpConnection.h b/netwerk/protocol/http/nsHttpConnection.h index 1ef00530728..eced776916e 100644 --- a/netwerk/protocol/http/nsHttpConnection.h +++ b/netwerk/protocol/http/nsHttpConnection.h @@ -182,6 +182,8 @@ public: // When the connection is active this is called every second void ReadTimeoutTick(); + PRInt64 BytesWritten() { return mTotalBytesWritten; } + private: // called to cause the underlying socket to start speaking SSL nsresult ProxyStartSSL(); @@ -239,6 +241,7 @@ private: PRInt64 mCurrentBytesRead; // data read per activation PRInt64 mMaxBytesRead; // max read in 1 activation PRInt64 mTotalBytesRead; // total data read + PRInt64 mTotalBytesWritten; // does not include CONNECT tunnel nsRefPtr mInputOverflow; diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h index b4a8a26a787..8d24a6b1075 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -379,7 +379,7 @@ private: { public: NS_DECL_ISUPPORTS - NS_DECL_NSAHTTPCONNECTION + NS_DECL_NSAHTTPCONNECTION(mConn) nsConnectionHandle(nsHttpConnection *conn) { NS_ADDREF(mConn = conn); } virtual ~nsConnectionHandle(); diff --git a/netwerk/protocol/http/nsHttpPipeline.h b/netwerk/protocol/http/nsHttpPipeline.h index dd6b98acbfb..f7ce3064b63 100644 --- a/netwerk/protocol/http/nsHttpPipeline.h +++ b/netwerk/protocol/http/nsHttpPipeline.h @@ -53,7 +53,7 @@ class nsHttpPipeline : public nsAHttpConnection { public: NS_DECL_ISUPPORTS - NS_DECL_NSAHTTPCONNECTION + NS_DECL_NSAHTTPCONNECTION(mConnection) NS_DECL_NSAHTTPTRANSACTION NS_DECL_NSAHTTPSEGMENTREADER diff --git a/netwerk/protocol/http/nsHttpTransaction.cpp b/netwerk/protocol/http/nsHttpTransaction.cpp index 360434c09d4..cf8c2438bd5 100644 --- a/netwerk/protocol/http/nsHttpTransaction.cpp +++ b/netwerk/protocol/http/nsHttpTransaction.cpp @@ -725,7 +725,15 @@ nsHttpTransaction::Close(nsresult reason) // mReceivedData == FALSE. (see bug 203057 for more info.) // if (reason == NS_ERROR_NET_RESET || reason == NS_OK) { - if (!mReceivedData && (!mSentData || connReused || mPipelinePosition)) { + + // reallySentData is meant to separate the instances where data has + // been sent by this transaction but buffered at a higher level while + // a TLS session (perhaps via a tunnel) is setup. + bool reallySentData = + mSentData && (!mConnection || mConnection->BytesWritten()); + + if (!mReceivedData && + (!reallySentData || connReused || mPipelinePosition)) { // if restarting fails, then we must proceed to close the pipe, // which will notify the channel that the transaction failed.