bug 739522 - allow parallelism for hosts that exhibit mixed spdy/http r=honzab a=akebyl
authorPatrick McManus <mcmanus@ducksong.com>
Mon, 07 May 2012 10:46:12 -0400
changeset 94157 cb4881f73296cb98880c545f7171d99781e22eee
parent 94156 d6a46f18cc6aaeaeab3233e19dd6f3cd989169e7
child 94158 e73465a6bfcb484df610af091eee29bf29d2058a
push idunknown
push userunknown
push dateunknown
reviewershonzab, akebyl
bugs739522
milestone14.0a2
bug 739522 - allow parallelism for hosts that exhibit mixed spdy/http r=honzab a=akebyl
netwerk/protocol/http/nsHttpConnection.h
netwerk/protocol/http/nsHttpConnectionMgr.cpp
--- a/netwerk/protocol/http/nsHttpConnection.h
+++ b/netwerk/protocol/http/nsHttpConnection.h
@@ -161,16 +161,20 @@ public:
     // connection pool, the nsHttpConnection still reads errors and hangups
     // on the socket so that it can be proactively released if the server
     // initiates a termination. Only call on socket thread.
     void BeginIdleMonitoring();
     void EndIdleMonitoring();
 
     bool UsingSpdy() { return mUsingSpdy; }
 
+    // true when connection SSL NPN phase is complete and we know
+    // authoritatively whether UsingSpdy() or not.
+    bool ReportedNPN() { return mReportedSpdy; }
+
     // When the connection is active this is called every 1 second
     void  ReadTimeoutTick(PRIntervalTime now);
 
     nsAHttpTransaction::Classifier Classification() { return mClassification; }
     void Classify(nsAHttpTransaction::Classifier newclass)
     {
         mClassification = newclass;
     }
--- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp
+++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp
@@ -1148,17 +1148,42 @@ nsHttpConnectionMgr::MakeNewConnection(n
     // negotiation is known.
 
     if (gHttpHandler->IsSpdyEnabled() &&
         ent->mConnInfo->UsingSSL() &&
         !ent->mConnInfo->UsingHttpProxy() &&
         !(trans->Caps() & NS_HTTP_DISALLOW_SPDY) &&
         (!ent->mTestedSpdy || ent->mUsingSpdy) &&
         (ent->mHalfOpens.Length() || ent->mActiveConns.Length())) {
-        return false;
+        bool restrictConnection = true;
+
+        // There is a concern that a host is using a mix of HTTP/1 and SPDY.
+        // In that case we don't want to restrict connections just because
+        // there is a single active HTTP/1 session in use. Confirm that the
+        // restriction is due to a handshake in progress or a live spdy
+        // session.
+        if (!ent->mHalfOpens.Length() &&
+            ent->mUsingSpdy && ent->mActiveConns.Length()) {
+            bool confirmedRestrict = false;
+
+            for (PRUint32 index = 0; index < ent->mActiveConns.Length(); ++index) {
+                nsHttpConnection *conn = ent->mActiveConns[index];
+                if (!conn->ReportedNPN() || conn->CanDirectlyActivate()) {
+                    confirmedRestrict = true;
+                    break; // confirmed;
+                }
+            }
+            if (!confirmedRestrict) {
+                LOG(("nsHttpConnectionMgr spdy connection restriction to "
+                     "%s bypassed.\n", ent->mConnInfo->Host()));
+                restrictConnection = false;
+            }
+        }
+        if (restrictConnection)
+            return false;
     }
 
     // We need to make a new connection. If that is going to exceed the
     // global connection limit then try and free up some room by closing
     // an idle connection to another host. We know it won't select "ent"
     // beacuse we have already determined there are no idle connections
     // to our destination