diff options
Diffstat (limited to 'indra/newview/lleventpoll.cpp')
-rw-r--r-- | indra/newview/lleventpoll.cpp | 146 |
1 files changed, 117 insertions, 29 deletions
diff --git a/indra/newview/lleventpoll.cpp b/indra/newview/lleventpoll.cpp index 745d0f7be8..4f4d9a40b4 100644 --- a/indra/newview/lleventpoll.cpp +++ b/indra/newview/lleventpoll.cpp @@ -2,45 +2,51 @@ * @file lleventpoll.cpp * @brief Implementation of the LLEventPoll class. * - * $LicenseInfo:firstyear=2006&license=viewergpl$ - * - * Copyright (c) 2006-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2006&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ #include "llviewerprecompiledheaders.h" -#include "llagent.h" #include "lleventpoll.h" +#include "llappviewer.h" +#include "llagent.h" #include "llhttpclient.h" +#include "llhttpstatuscodes.h" #include "llsdserialize.h" +#include "lleventtimer.h" #include "llviewerregion.h" #include "message.h" +#include "lltrans.h" namespace { + // We will wait RETRY_SECONDS + (errorCount * RETRY_SECONDS_INC) before retrying after an error. + // This means we attempt to recover relatively quickly but back off giving more time to recover + // until we finally give up after MAX_EVENT_POLL_HTTP_ERRORS attempts. + const F32 EVENT_POLL_ERROR_RETRY_SECONDS = 15.f; // ~ half of a normal timeout. + const F32 EVENT_POLL_ERROR_RETRY_SECONDS_INC = 5.f; // ~ half of a normal timeout. + const S32 MAX_EVENT_POLL_HTTP_ERRORS = 10; // ~5 minutes, by the above rules. + class LLEventPollResponder : public LLHTTPClient::Responder { public: @@ -48,15 +54,21 @@ namespace static LLHTTPClient::ResponderPtr start(const std::string& pollURL, const LLHost& sender); void stop(); + void makeRequest(); + private: LLEventPollResponder(const std::string& pollURL, const LLHost& sender); ~LLEventPollResponder(); - void makeRequest(); + void handleMessage(const LLSD& content); virtual void error(U32 status, const std::string& reason); virtual void result(const LLSD& content); + virtual void completedRaw(U32 status, + const std::string& reason, + const LLChannelDescriptors& channels, + const LLIOPipe::buffer_ptr_t& buffer); private: bool mDone; @@ -69,6 +81,27 @@ namespace // these are only here for debugging so we can see which poller is which static int sCount; int mCount; + S32 mErrorCount; + }; + + class LLEventPollEventTimer : public LLEventTimer + { + typedef boost::intrusive_ptr<LLEventPollResponder> EventPollResponderPtr; + + public: + LLEventPollEventTimer(F32 period, EventPollResponderPtr responder) + : LLEventTimer(period), mResponder(responder) + { } + + virtual BOOL tick() + { + mResponder->makeRequest(); + return TRUE; // Causes this instance to be deleted. + } + + private: + + EventPollResponderPtr mResponder; }; //static @@ -94,7 +127,8 @@ namespace LLEventPollResponder::LLEventPollResponder(const std::string& pollURL, const LLHost& sender) : mDone(false), mPollURL(pollURL), - mCount(++sCount) + mCount(++sCount), + mErrorCount(0) { //extract host and port of simulator to set as sender LLViewerRegion *regionp = gAgent.getRegion(); @@ -114,6 +148,24 @@ namespace << mPollURL << llendl; } + // virtual + void LLEventPollResponder::completedRaw(U32 status, + const std::string& reason, + const LLChannelDescriptors& channels, + const LLIOPipe::buffer_ptr_t& buffer) + { + if (status == HTTP_BAD_GATEWAY) + { + // These errors are not parsable as LLSD, + // which LLHTTPClient::Responder::completedRaw will try to do. + completed(status, reason, LLSD()); + } + else + { + LLHTTPClient::Responder::completedRaw(status,reason,channels,buffer); + } + } + void LLEventPollResponder::makeRequest() { LLSD request; @@ -139,16 +191,46 @@ namespace { if (mDone) return; - if(status != 499) + // A HTTP_BAD_GATEWAY (502) error is our standard timeout response + // we get this when there are no events. + if ( status == HTTP_BAD_GATEWAY ) + { + mErrorCount = 0; + makeRequest(); + } + else if (mErrorCount < MAX_EVENT_POLL_HTTP_ERRORS) + { + ++mErrorCount; + + // The 'tick' will return TRUE causing the timer to delete this. + new LLEventPollEventTimer(EVENT_POLL_ERROR_RETRY_SECONDS + + mErrorCount * EVENT_POLL_ERROR_RETRY_SECONDS_INC + , this); + + llwarns << "Unexpected HTTP error. status: " << status << ", reason: " << reason << llendl; + } + else { llwarns << "LLEventPollResponder::error: <" << mCount << "> got " << status << ": " << reason << (mDone ? " -- done" : "") << llendl; stop(); - return; - } - makeRequest(); + // At this point we have given up and the viewer will not receive HTTP messages from the simulator. + // IMs, teleports, about land, selecing land, region crossing and more will all fail. + // They are essentially disconnected from the region even though some things may still work. + // Since things won't get better until they relog we force a disconnect now. + + // *NOTE:Mani - The following condition check to see if this failing event poll + // is attached to the Agent's main region. If so we disconnect the viewer. + // Else... its a child region and we just leave the dead event poll stopped and + // continue running. + if(gAgent.getRegion() && gAgent.getRegion()->getHost().getIPandPort() == mSender) + { + llwarns << "Forcing disconnect due to stalled main region event poll." << llendl; + LLAppViewer::instance()->forceDisconnect(LLTrans::getString("AgentLostConnection")); + } + } } //virtual @@ -159,10 +241,13 @@ namespace if (mDone) return; + mErrorCount = 0; + if (!content.get("events") || !content.get("id")) { llwarns << "received event poll with no events or id key" << llendl; + makeRequest(); return; } @@ -192,10 +277,13 @@ namespace } } -LLEventPoll::LLEventPoll(const std::string& pollURL, const LLHost& sender) - : mImpl(LLEventPollResponder::start(pollURL, sender)) +LLEventPoll::LLEventPoll(const std::string& poll_url, const LLHost& sender) + : mImpl(LLEventPollResponder::start(poll_url, sender)) { } LLEventPoll::~LLEventPoll() { + LLHTTPClient::Responder* responderp = mImpl.get(); + LLEventPollResponder* event_poll_responder = dynamic_cast<LLEventPollResponder*>(responderp); + if (event_poll_responder) event_poll_responder->stop(); } |