From 104748b59af2ff15b44c910340daffe9180e74f7 Mon Sep 17 00:00:00 2001
From: Dave Parks <davep@lindenlab.com>
Date: Tue, 12 Jul 2011 17:31:25 -0500
Subject: SH-1125 Retry when failing to get seed capability.

---
 indra/newview/llviewerregion.cpp | 34 +++++++++++++++++++++++++---------
 indra/newview/llviewerregion.h   |  2 +-
 2 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 8bb38e3e46..9c6c62053b 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -186,8 +186,8 @@ class BaseCapabilitiesComplete : public LLHTTPClient::Responder
 {
 	LOG_CLASS(BaseCapabilitiesComplete);
 public:
-    BaseCapabilitiesComplete(LLViewerRegion* region)
-		: mRegion(region)
+    BaseCapabilitiesComplete(LLViewerRegion* region, S32 retry = 0)
+		: mRegion(region), mRetry(retry)
     { }
 	virtual ~BaseCapabilitiesComplete()
 	{
@@ -206,9 +206,24 @@ public:
     {
 		LL_WARNS2("AppInit", "Capabilities") << statusNum << ": " << reason << LL_ENDL;
 		
-		if (STATE_SEED_GRANTED_WAIT == LLStartUp::getStartupState())
+		const S32 MAX_RETRIES = 5;
+
+		if (mRetry < MAX_RETRIES)
 		{
-			LLStartUp::setStartupState( STATE_SEED_CAP_GRANTED );
+			std::string url = mRegion->getCapability("Seed");
+
+			mRetry++;
+
+			llinfos << "retry " << mRetry << " posting to seed " << url << llendl;
+
+			mRegion->setSeedCapability(url, mRetry);
+		}
+		else
+		{
+			if (STATE_SEED_GRANTED_WAIT == LLStartUp::getStartupState())
+			{
+				LLStartUp::setStartupState( STATE_SEED_CAP_GRANTED );
+			}
 		}
     }
 
@@ -242,14 +257,15 @@ public:
 	}
 
     static boost::intrusive_ptr<BaseCapabilitiesComplete> build(
-								LLViewerRegion* region)
+								LLViewerRegion* region, S32 retry)
     {
 		return boost::intrusive_ptr<BaseCapabilitiesComplete>(
-							 new BaseCapabilitiesComplete(region));
+							 new BaseCapabilitiesComplete(region, retry));
     }
 
 private:
 	LLViewerRegion* mRegion;
+	S32 mRetry;
 };
 
 
@@ -1476,9 +1492,9 @@ void LLViewerRegion::unpackRegionHandshake()
 	msg->sendReliable(host);
 }
 
-void LLViewerRegion::setSeedCapability(const std::string& url)
+void LLViewerRegion::setSeedCapability(const std::string& url, S32 retry)
 {
-	if (getCapability("Seed") == url)
+	if (retry == 0 && getCapability("Seed") == url)
     {
 		// llwarns << "Ignoring duplicate seed capability" << llendl;
 		return;
@@ -1568,7 +1584,7 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
 
 	llinfos << "posting to seed " << url << llendl;
 
-	mImpl->mHttpResponderPtr = BaseCapabilitiesComplete::build(this) ;
+	mImpl->mHttpResponderPtr = BaseCapabilitiesComplete::build(this, retry) ;
 	LLHTTPClient::post(url, capabilityNames, mImpl->mHttpResponderPtr);
 }
 
diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h
index 00252b8897..0176969cea 100644
--- a/indra/newview/llviewerregion.h
+++ b/indra/newview/llviewerregion.h
@@ -230,7 +230,7 @@ public:
 	const LLHTTPClient::ResponderPtr getHttpResponderPtr() const;
 
 	// Get/set named capability URLs for this region.
-	void setSeedCapability(const std::string& url);
+	void setSeedCapability(const std::string& url, S32 retry = 0);
 	void setCapability(const std::string& name, const std::string& url);
 	// implements LLCapabilityProvider
     virtual std::string getCapability(const std::string& name) const;
-- 
cgit v1.2.3