# HG changeset patch # Parent 51f3fb236d0877a2b24b398eff68c65d6d9f6815 # User Patrick McManus bug 528288 spdy - when coalescing get ip from nsISocket instead of dns lookup r=honzab patch 11 diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -42,22 +42,20 @@ #include "nsHttpHandler.h" #include "nsNetCID.h" #include "nsCOMPtr.h" #include "nsNetUtil.h" #include "nsIServiceManager.h" #include "nsIObserverService.h" -#include "nsIDNSRecord.h" -#include "nsIDNSService.h" -#include "nsICancelable.h" #include "nsISSLStatusProvider.h" #include "nsISSLStatus.h" +#include "prnetdb.h" using namespace mozilla; // defined by the socket transport service while active extern PRThread *gSocketThread; static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); @@ -1814,37 +1812,16 @@ nsHalfOpenSocket::SetupStreams(nsISocket } nsresult nsHttpConnectionMgr::nsHalfOpenSocket::SetupPrimaryStreams() { NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread"); nsresult rv; - if (gHttpHandler->IsSpdyEnabled() && - gHttpHandler->CoalesceSpdy() && - mEnt->mConnInfo->UsingSSL() && - !mEnt->mConnInfo->UsingHttpProxy() && - !mEnt->mDidDNS) { - - // Grab the DNS resolution for this host for un-sharding purposes - // This lookup will no doubt be coalesced by the DNS sub system as it - // overlaps with the SocketTransport - - nsCOMPtr dns = do_GetService(NS_DNSSERVICE_CONTRACTID, - &rv); - mEnt->mDidDNS = true; - - if (NS_SUCCEEDED(rv)) { - nsCOMPtr cancelable; - dns->AsyncResolve(mEnt->mConnInfo->GetHost(), 0, this, - NS_GetCurrentThread(), - getter_AddRefs(cancelable)); - } - } rv = SetupStreams(getter_AddRefs(mSocketTransport), getter_AddRefs(mStreamIn), getter_AddRefs(mStreamOut), false); LOG(("nsHalfOpenSocket::SetupPrimaryStream [this=%p ent=%s rv=%x]", this, mEnt->mConnInfo->Host(), rv)); if (NS_FAILED(rv)) { @@ -1871,38 +1848,16 @@ nsHttpConnectionMgr::nsHalfOpenSocket::S mBackupStreamOut->AsyncWait(nsnull, 0, 0, nsnull); mBackupStreamOut = nsnull; mBackupStreamIn = nsnull; mBackupTransport = nsnull; } return rv; } - -NS_IMETHODIMP // nsIDNSListener -nsHttpConnectionMgr:: -nsHalfOpenSocket::OnLookupComplete(nsICancelable *aRequest, - nsIDNSRecord *aRecord, - nsresult aStatus) -{ - NS_ABORT_IF_FALSE(PR_GetCurrentThread() == gSocketThread, "wrong thread"); - - if (NS_SUCCEEDED(aStatus) && mEnt) { - aRecord->GetNextAddrAsString(mEnt->mCoalescingKey); - if (mEnt->mConnInfo->GetAnonymous()) - mEnt->mCoalescingKey.Append("~A:"); - else - mEnt->mCoalescingKey.Append("~.:"); - mEnt->mCoalescingKey.AppendInt(mEnt->mConnInfo->Port()); - - gHttpHandler->ConnMgr()->ProcessSpdyPendingQ(mEnt); - } - return NS_OK; -} - void nsHttpConnectionMgr::nsHalfOpenSocket::SetupBackupTimer() { PRUint16 timeout = gHttpHandler->GetIdleSynTimeout(); NS_ABORT_IF_FALSE(!mSynTimer, "timer already initd"); if (timeout) { // Setup the timer that will establish a backup socket @@ -2055,16 +2010,52 @@ nsHalfOpenSocket::OnOutputStreamReady(ns // method for nsITransportEventSink NS_IMETHODIMP nsHttpConnectionMgr::nsHalfOpenSocket::OnTransportStatus(nsITransport *trans, nsresult status, PRUint64 progress, PRUint64 progressMax) { + NS_ASSERTION(PR_GetCurrentThread() == gSocketThread, "wrong thread"); + + // if we are doing spdy coalescing and haven't recorded the ip address + // for this entry before then make the hash key if our dns lookup + // just completed + + if (gHttpHandler->IsSpdyEnabled() && + gHttpHandler->CoalesceSpdy() && + mEnt && mEnt->mConnInfo && mEnt->mConnInfo->UsingSSL() && + !mEnt->mConnInfo->UsingHttpProxy() && + mEnt->mCoalescingKey.IsEmpty() && + status == nsISocketTransport::STATUS_CONNECTED_TO) { + + PRNetAddr addr; + nsresult rv = mSocketTransport->GetPeerAddr(&addr); + if (NS_SUCCEEDED(rv)) { + mEnt->mCoalescingKey.SetCapacity(72); + PR_NetAddrToString(&addr, mEnt->mCoalescingKey.BeginWriting(), 64); + mEnt->mCoalescingKey.SetLength( + strlen(mEnt->mCoalescingKey.BeginReading())); + + if (mEnt->mConnInfo->GetAnonymous()) + mEnt->mCoalescingKey.AppendLiteral("~A:"); + else + mEnt->mCoalescingKey.AppendLiteral("~.:"); + mEnt->mCoalescingKey.AppendInt(mEnt->mConnInfo->Port()); + + LOG(("nsHttpConnectionMgr::nsHalfOpenSocket::OnTransportStatus " + "STATUS_CONNECTED_TO Established New Coalescing Key for host " + "%s [%s]", mEnt->mConnInfo->Host(), + mEnt->mCoalescingKey.get())); + + gHttpHandler->ConnMgr()->ProcessSpdyPendingQ(mEnt); + } + } + if (mTransaction) mTransaction->OnTransportStatus(trans, status, progress); return NS_OK; } // method for nsIInterfaceRequestor NS_IMETHODIMP nsHttpConnectionMgr::nsHalfOpenSocket::GetInterface(const nsIID &iid, diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -44,17 +44,16 @@ #include "nsHttpTransaction.h" #include "nsTArray.h" #include "nsThreadUtils.h" #include "nsClassHashtable.h" #include "nsDataHashtable.h" #include "nsAutoPtr.h" #include "mozilla/ReentrantMonitor.h" #include "nsISocketTransportService.h" -#include "nsIDNSListener.h" #include "nsHashSets.h" #include "nsIObserver.h" #include "nsITimer.h" #include "nsIX509Cert3.h" class nsHttpPipeline; @@ -174,17 +173,16 @@ private: // struct nsConnectionEntry { nsConnectionEntry(nsHttpConnectionInfo *ci) : mConnInfo(ci), mUsingSpdy(false), mTestedSpdy(false), mSpdyRedir(false), - mDidDNS(false), mSpdyPreferred(false) { NS_ADDREF(mConnInfo); } ~nsConnectionEntry(); nsHttpConnectionInfo *mConnInfo; nsTArray mPendingQ; // pending transaction queue @@ -201,17 +199,16 @@ private: // mSpdyPreferred, and the others are marked mSpdyRedir. The mapping is // maintained in the conection manager mSpdyPreferred hash. // nsCString mCoalescingKey; bool mUsingSpdy; bool mTestedSpdy; bool mSpdyRedir; - bool mDidDNS; bool mSpdyPreferred; nsCOMPtr mCert; }; // nsConnectionHandle // // thin wrapper around a real connection, used to keep track of references // to the connection to determine when the connection may be reused. the @@ -233,26 +230,24 @@ private: }; // nsHalfOpenSocket is used to hold the state of an opening TCP socket // while we wait for it to establish and bind it to a connection class nsHalfOpenSocket : public nsIOutputStreamCallback, public nsITransportEventSink, public nsIInterfaceRequestor, - public nsITimerCallback, - public nsIDNSListener + public nsITimerCallback { public: NS_DECL_ISUPPORTS NS_DECL_NSIOUTPUTSTREAMCALLBACK NS_DECL_NSITRANSPORTEVENTSINK NS_DECL_NSIINTERFACEREQUESTOR NS_DECL_NSITIMERCALLBACK - NS_DECL_NSIDNSLISTENER nsHalfOpenSocket(nsConnectionEntry *ent, nsHttpTransaction *trans); ~nsHalfOpenSocket(); nsresult SetupStreams(nsISocketTransport **, nsIAsyncInputStream **, nsIAsyncOutputStream **,