From e7f03a77bfe4173cd33b5242eb27aa9469c4702c Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Mon, 18 Apr 2016 14:31:14 -0700 Subject: MAINT-6336: Better retry and timeout logic when logging in to the vivox server and connecting to a session. --- indra/newview/llvoicevivox.cpp | 123 ++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 45 deletions(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index c9661dfb11..e015d4fa5e 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -80,39 +80,49 @@ extern LLMenuBarGL* gMenuBarView; extern void handle_voice_morphing_subscribe(); -const F32 VOLUME_SCALE_VIVOX = 0.01f; +namespace { + const F32 VOLUME_SCALE_VIVOX = 0.01f; -const F32 SPEAKING_TIMEOUT = 1.f; + const F32 SPEAKING_TIMEOUT = 1.f; -static const std::string VOICE_SERVER_TYPE = "Vivox"; + static const std::string VOICE_SERVER_TYPE = "Vivox"; -// Don't retry connecting to the daemon more frequently than this: -const F32 CONNECT_THROTTLE_SECONDS = 1.0f; + // Don't retry connecting to the daemon more frequently than this: + const F32 CONNECT_THROTTLE_SECONDS = 1.0f; -// Don't send positional updates more frequently than this: -const F32 UPDATE_THROTTLE_SECONDS = 0.5f; + // Don't send positional updates more frequently than this: + const F32 UPDATE_THROTTLE_SECONDS = 0.5f; -const F32 LOGIN_RETRY_SECONDS = 10.0f; -const int MAX_LOGIN_RETRIES = 12; + const F32 LOGIN_ATTEMPT_TIMEOUT = 5.0f; + const int LOGIN_RETRY_MAX = 5; + const F32 LOGIN_RETRY_TIMEOUT = 4.0f; -// Cosine of a "trivially" small angle -const F32 MINUSCULE_ANGLE_COS = 0.999f; + const int PROVISION_RETRY_MAX = 5; + const F32 PROVISION_RETRY_TIMEOUT = 2.0; -// Defines the maximum number of times(in a row) "stateJoiningSession" case for spatial channel is reached in stateMachine() -// which is treated as normal. The is the number of frames to wait for a channel join before giving up. This was changed -// from the original count of 50 for two reason. Modern PCs have higher frame rates and sometimes the SLVoice process -// backs up processing join requests. There is a log statement that records when channel joins take longer than 100 frames. -const int MAX_NORMAL_JOINING_SPATIAL_NUM = 1500; + // Cosine of a "trivially" small angle + const F32 MINUSCULE_ANGLE_COS = 0.999f; -// How often to check for expired voice fonts in seconds -const F32 VOICE_FONT_EXPIRY_INTERVAL = 10.f; -// Time of day at which Vivox expires voice font subscriptions. -// Used to replace the time portion of received expiry timestamps. -static const std::string VOICE_FONT_EXPIRY_TIME = "T05:00:00Z"; + const F32 SESSION_JOIN_TIMEOUT = 10.0f; -// Maximum length of capture buffer recordings in seconds. -const F32 CAPTURE_BUFFER_MAX_TIME = 10.f; + // Defines the maximum number of times(in a row) "stateJoiningSession" case for spatial channel is reached in stateMachine() + // which is treated as normal. The is the number of frames to wait for a channel join before giving up. This was changed + // from the original count of 50 for two reason. Modern PCs have higher frame rates and sometimes the SLVoice process + // backs up processing join requests. There is a log statement that records when channel joins take longer than 100 frames. + const int MAX_NORMAL_JOINING_SPATIAL_NUM = 1500; + // How often to check for expired voice fonts in seconds + const F32 VOICE_FONT_EXPIRY_INTERVAL = 10.f; + // Time of day at which Vivox expires voice font subscriptions. + // Used to replace the time portion of received expiry timestamps. + static const std::string VOICE_FONT_EXPIRY_TIME = "T05:00:00Z"; + + // Maximum length of capture buffer recordings in seconds. + const F32 CAPTURE_BUFFER_MAX_TIME = 10.f; + + const int ERROR_VIVOX_OBJECT_NOT_FOUND = 1001; + const int ERROR_VIVOX_NOT_LOGGED_IN = 1007; +} static int scale_mic_volume(float volume) { @@ -129,8 +139,6 @@ static int scale_speaker_volume(float volume) } -const int ERROR_VIVOX_OBJECT_NOT_FOUND = 1001; -const int ERROR_VIVOX_NOT_LOGGED_IN = 1007; /////////////////////////////////////////////////////////////////////////////////////////////// @@ -546,7 +554,7 @@ void LLVivoxVoiceClient::voiceControlCoro() // if we hit this and mRelogRequested is true, that indicates // that we attempted to relog into Vivox and were rejected. // Rather than just quit out of voice, we will tear it down (above) - // and then reconstruct the voice connecino from scratch. + // and then reconstruct the voice connecion from scratch. if (mRelogRequested) { while (isGatewayRunning()) @@ -784,13 +792,15 @@ bool LLVivoxVoiceClient::provisionVoiceAccount() if (status == LLCore::HttpStatus(404)) { - if (++retryCount > 5) + if (++retryCount > PROVISION_RETRY_MAX) { - LL_WARNS("Voice") << "Could not access voice provision cap after 5 attempts." << LL_ENDL; + LL_WARNS("Voice") << "Could not access voice provision cap after " << PROVISION_RETRY_MAX << " attempts." << LL_ENDL; return false; } - LL_WARNS("Voice") << "Provision CAP 404. Retrying in 1.0" << LL_ENDL; - llcoro::suspendUntilTimeout(1.0); + + F32 timeout = pow(PROVISION_RETRY_TIMEOUT, static_cast(retryCount)); + LL_WARNS("Voice") << "Provision CAP 404. Retrying in " << timeout << " seconds." << LL_ENDL; + llcoro::suspendUntilTimeout(timeout); continue; } @@ -888,21 +898,29 @@ bool LLVivoxVoiceClient::breakVoiceConnection(bool corowait) bool LLVivoxVoiceClient::loginToVivox() { - int loginRetryCount(0); LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); + LLSD timeoutResult; + timeoutResult["login"] = LLSD::String("timeout"); + + LLEventTimeout voicePumpTimeout(voicePump); + + int loginRetryCount(0); + bool response_ok(false); bool account_login(false); bool send_login(true); do { + mIsLoggingIn = true; if (send_login) loginSendMessage(); send_login = false; + voicePumpTimeout.eventAfter(LOGIN_ATTEMPT_TIMEOUT, timeoutResult); LLSD result = llcoro::suspendUntilEventOn(voicePump); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; @@ -910,16 +928,16 @@ bool LLVivoxVoiceClient::loginToVivox() { std::string loginresp = result["login"]; - if (loginresp == "retry") + if ((loginresp == "retry") || (loginresp == "timeout")) { - if (!loginRetryCount) + if ((!loginRetryCount) && (loginresp != "timeout")) { // on first retry notify user notifyStatusObservers(LLVoiceClientStatusObserver::STATUS_LOGIN_RETRY); } - if ((++loginRetryCount > MAX_LOGIN_RETRIES) || (!result["login_retry"])) + if ((++loginRetryCount > LOGIN_RETRY_MAX) || (loginresp == "timeout")) { - LL_WARNS("Voice") << "too many login retries, giving up." << LL_ENDL; + LL_WARNS("Voice") << "too many login retries or timeout connecting, giving up." << LL_ENDL; LLSD args; std::stringstream errs; errs << mVoiceAccountServerURI << "\n:UDP: 3478, 3479, 5060, 5062, 12000-17000"; @@ -942,8 +960,10 @@ bool LLVivoxVoiceClient::loginToVivox() account_login = false; send_login = true; - LL_INFOS("Voice") << "will retry login in " << LOGIN_RETRY_SECONDS << " seconds." << LL_ENDL; - llcoro::suspendUntilTimeout(LOGIN_RETRY_SECONDS); + F32 timeout = pow(LOGIN_RETRY_TIMEOUT, static_cast(loginRetryCount)) - 1.0f; + + LL_INFOS("Voice") << "will retry login in " << timeout << " seconds." << LL_ENDL; + llcoro::suspendUntilTimeout(timeout); } else if (loginresp == "failed") { @@ -982,7 +1002,6 @@ bool LLVivoxVoiceClient::loginToVivox() void LLVivoxVoiceClient::logoutOfVivox(bool wait) { - LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); if (!mIsLoggedIn) return; @@ -995,7 +1014,14 @@ void LLVivoxVoiceClient::logoutOfVivox(bool wait) if (wait) { - LLSD result = llcoro::suspendUntilEventOn(voicePump); + LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); + LLSD timeoutResult; + timeoutResult["logout"] = LLSD::String("timeout"); + + LLEventTimeout voicePumpTimeout(voicePump); + + voicePumpTimeout.eventAfter(LOGIN_ATTEMPT_TIMEOUT, timeoutResult); + LLSD result = llcoro::suspendUntilEventOn(voicePumpTimeout); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; @@ -1194,13 +1220,20 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) bool added(true); bool joined(false); + LLSD timeoutResult; + timeoutResult["session"] = LLSD::String("timeout"); + + LLEventTimeout voicePumpTimeout(voicePump); + + // It appears that I need to wait for BOTH the SessionGroup.AddSession response and the SessionStateChangeEvent with state 4 // before continuing from this state. They can happen in either order, and if I don't wait for both, things can get stuck. // For now, the SessionGroup.AddSession response handler sets mSessionHandle and the SessionStateChangeEvent handler transitions to stateSessionJoined. // This is a cheap way to make sure both have happened before proceeding. do { - result = llcoro::suspendUntilEventOn(voicePump); + voicePumpTimeout.eventAfter(SESSION_JOIN_TIMEOUT, timeoutResult); + result = llcoro::suspendUntilEventOn(voicePumpTimeout); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; if (result.has("session")) @@ -1219,10 +1252,10 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) added = true; else if (message == "joined") joined = true; - else if ((message == "failed") || (message == "removed")) + else if ((message == "failed") || (message == "removed") || (message == "timeout")) { // we will get a removed message if a voice call is declined. - if (message == "failed") + if (message == "failed") { int reason = result["reason"].asInteger(); LL_WARNS("Voice") << "Add and join failed for reason " << reason << LL_ENDL; @@ -1638,8 +1671,8 @@ int LLVivoxVoiceClient::voiceRecordBuffer() LLSD result; captureBufferRecordStartSendMessage(); - notifyVoiceFontObservers(); + do { result = llcoro::suspendUntilEventOn(voicePump); @@ -1667,11 +1700,11 @@ int LLVivoxVoiceClient::voicePlaybackBuffer() LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); LLEventTimeout timeout(voicePump); - timeout.eventAfter(CAPTURE_BUFFER_MAX_TIME, timeoutResult); LLSD result; do { + timeout.eventAfter(CAPTURE_BUFFER_MAX_TIME, timeoutResult); captureBufferPlayStartSendMessage(mPreviewVoiceFont); // Store the voice font being previewed, so that we know to restart if it changes. @@ -1682,7 +1715,7 @@ int LLVivoxVoiceClient::voicePlaybackBuffer() // Update UI, should really use a separate callback. notifyVoiceFontObservers(); - result = llcoro::suspendUntilEventOn(voicePump); + result = llcoro::suspendUntilEventOn(timeout); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; } while (!result.has("recplay")); -- cgit v1.3 From 86a3e1a3dc59c964d78c509e99a59d52eea32b34 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Tue, 19 Apr 2016 14:10:57 -0700 Subject: MAINT-6336: Crasher on disconnect in DDoS. --- indra/newview/llvoicevivox.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index e015d4fa5e..518b5bdc65 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -1223,15 +1223,14 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) LLSD timeoutResult; timeoutResult["session"] = LLSD::String("timeout"); - LLEventTimeout voicePumpTimeout(voicePump); - - // It appears that I need to wait for BOTH the SessionGroup.AddSession response and the SessionStateChangeEvent with state 4 // before continuing from this state. They can happen in either order, and if I don't wait for both, things can get stuck. // For now, the SessionGroup.AddSession response handler sets mSessionHandle and the SessionStateChangeEvent handler transitions to stateSessionJoined. // This is a cheap way to make sure both have happened before proceeding. do { + LLEventTimeout voicePumpTimeout(voicePump); + voicePumpTimeout.eventAfter(SESSION_JOIN_TIMEOUT, timeoutResult); result = llcoro::suspendUntilEventOn(voicePumpTimeout); -- cgit v1.3 From 16e06b4b50af3f4f4e3c91f8db1e4f59a44d8422 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Tue, 19 Apr 2016 14:17:28 -0700 Subject: MAINT-6336: more loging for test build. --- indra/newview/llvoicevivox.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index 518b5bdc65..17e538fcfa 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -1161,6 +1161,8 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) // The old session may now need to be deleted. reapSession(oldSession); + LL_INFOS("Voice") << "Done reap test." << LL_ENDL; + if (!mAudioSession->mHandle.empty()) { // Connect to a session by session handle @@ -1175,6 +1177,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) notifyStatusObservers(LLVoiceClientStatusObserver::STATUS_JOINING); + LL_INFOS("Voice") << "suspend after notify STATUS_JOINING." << LL_ENDL; llcoro::suspend(); LLSD result; @@ -1195,6 +1198,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) if (!mVoiceEnabled && mIsInitialized) { + LL_INFOS("Voice") << "Voice no longer enabled. Exiting." << LL_ENDL; mIsJoiningSession = false; // User bailed out during connect -- jump straight to teardown. terminateAudioSession(true); @@ -1203,6 +1207,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) } else if (mSessionTerminateRequested) { + LL_INFOS("Voice") << "Terminate requested" << LL_ENDL; if (mAudioSession && !mAudioSession->mHandle.empty()) { // Only allow direct exits from this state in p2p calls (for cancelling an invite). @@ -1229,12 +1234,13 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) // This is a cheap way to make sure both have happened before proceeding. do { + LL_INFOS("Voice") << "Top of add join loop." << LL_ENDL; LLEventTimeout voicePumpTimeout(voicePump); voicePumpTimeout.eventAfter(SESSION_JOIN_TIMEOUT, timeoutResult); result = llcoro::suspendUntilEventOn(voicePumpTimeout); - LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; + LL_INFOS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; if (result.has("session")) { if (result.has("handle")) @@ -1275,6 +1281,9 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) } } while (!added || !joined); + + LL_INFOS("Voice") << "Left voice loop." << LL_ENDL; + mIsJoiningSession = false; if (mSpatialJoiningNum > 100) -- cgit v1.3 From 8f4be8bb869e3cde034607cbe0cb8272005f08b8 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Thu, 21 Apr 2016 09:16:50 -0700 Subject: MAINT-6336: Removed or demoted some of the chatty log messages I was using to track progress. --- indra/newview/llvoicevivox.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index 17e538fcfa..ca0509c524 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -1161,8 +1161,6 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) // The old session may now need to be deleted. reapSession(oldSession); - LL_INFOS("Voice") << "Done reap test." << LL_ENDL; - if (!mAudioSession->mHandle.empty()) { // Connect to a session by session handle @@ -1177,7 +1175,6 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) notifyStatusObservers(LLVoiceClientStatusObserver::STATUS_JOINING); - LL_INFOS("Voice") << "suspend after notify STATUS_JOINING." << LL_ENDL; llcoro::suspend(); LLSD result; @@ -1198,7 +1195,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) if (!mVoiceEnabled && mIsInitialized) { - LL_INFOS("Voice") << "Voice no longer enabled. Exiting." << LL_ENDL; + LL_DEBUGS("Voice") << "Voice no longer enabled. Exiting." << LL_ENDL; mIsJoiningSession = false; // User bailed out during connect -- jump straight to teardown. terminateAudioSession(true); @@ -1207,7 +1204,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) } else if (mSessionTerminateRequested) { - LL_INFOS("Voice") << "Terminate requested" << LL_ENDL; + LL_DEBUGS("Voice") << "Terminate requested" << LL_ENDL; if (mAudioSession && !mAudioSession->mHandle.empty()) { // Only allow direct exits from this state in p2p calls (for cancelling an invite). @@ -1234,13 +1231,12 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) // This is a cheap way to make sure both have happened before proceeding. do { - LL_INFOS("Voice") << "Top of add join loop." << LL_ENDL; LLEventTimeout voicePumpTimeout(voicePump); voicePumpTimeout.eventAfter(SESSION_JOIN_TIMEOUT, timeoutResult); result = llcoro::suspendUntilEventOn(voicePumpTimeout); - LL_INFOS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; + LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; if (result.has("session")) { if (result.has("handle")) @@ -1268,7 +1264,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) if ((reason == ERROR_VIVOX_NOT_LOGGED_IN) || (reason == ERROR_VIVOX_OBJECT_NOT_FOUND)) { - LL_INFOS("Voice") << "Requesting reprovision and login." << LL_ENDL; + LL_DEBUGS("Voice") << "Requesting reprovision and login." << LL_ENDL; requestRelog(); } @@ -1281,9 +1277,6 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) } } while (!added || !joined); - - LL_INFOS("Voice") << "Left voice loop." << LL_ENDL; - mIsJoiningSession = false; if (mSpatialJoiningNum > 100) -- cgit v1.3 From 899489ae0a4bc4eb187e7813e338b937384a1866 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 22 Apr 2016 12:07:27 -0700 Subject: MAINT-6336: Centralize waiting on event pump with a timeout. Shorten the lifespan of a timeout event pump lifespan to be no longer than necessary. Change all references to the LLEventTimer to instead uses the centralized version. --- indra/llcommon/lleventcoro.cpp | 9 +++++++++ indra/llcommon/lleventcoro.h | 2 ++ indra/llcommon/lleventfilter.cpp | 4 ++-- indra/llcommon/lleventfilter.h | 3 +++ indra/newview/llvoicevivox.cpp | 32 ++++++++++---------------------- 5 files changed, 26 insertions(+), 24 deletions(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/llcommon/lleventcoro.cpp b/indra/llcommon/lleventcoro.cpp index 578a2b62c8..44291eb711 100755 --- a/indra/llcommon/lleventcoro.cpp +++ b/indra/llcommon/lleventcoro.cpp @@ -229,6 +229,15 @@ LLSD llcoro::postAndSuspend(const LLSD& event, const LLEventPumpOrPumpName& requ return value; } +LLSD llcoro::suspendUntilEventOnWithTimeout(const LLEventPumpOrPumpName& pump, F32 timeoutin, const LLSD &timeoutResult) +{ + LLEventTimeout timeoutPump(pump); + + timeoutPump.eventAfter(timeoutin, timeoutResult); + return llcoro::suspendUntilEventOn(timeoutPump); + +} + namespace { diff --git a/indra/llcommon/lleventcoro.h b/indra/llcommon/lleventcoro.h index 2105faf861..19c68e1f35 100755 --- a/indra/llcommon/lleventcoro.h +++ b/indra/llcommon/lleventcoro.h @@ -147,6 +147,8 @@ LLSD suspendUntilEventOn(const LLEventPumpOrPumpName& pump) return postAndSuspend(LLSD(), LLEventPumpOrPumpName(), pump); } +LLSD suspendUntilEventOnWithTimeout(const LLEventPumpOrPumpName& pump, F32 timeoutin, const LLSD &timeoutResult); + } // namespace llcoro /// return type for two-pump variant of suspendUntilEventOn() diff --git a/indra/llcommon/lleventfilter.cpp b/indra/llcommon/lleventfilter.cpp index d36a107254..64ab58adcd 100755 --- a/indra/llcommon/lleventfilter.cpp +++ b/indra/llcommon/lleventfilter.cpp @@ -39,9 +39,9 @@ #include "llsdutil.h" // llsd_matches() LLEventFilter::LLEventFilter(LLEventPump& source, const std::string& name, bool tweak): - LLEventStream(name, tweak) + LLEventStream(name, tweak), + mSource(source.listen(getName(), boost::bind(&LLEventFilter::post, this, _1))) { - source.listen(getName(), boost::bind(&LLEventFilter::post, this, _1)); } LLEventMatching::LLEventMatching(const LLSD& pattern): diff --git a/indra/llcommon/lleventfilter.h b/indra/llcommon/lleventfilter.h index 8e01326823..15bac5fd73 100755 --- a/indra/llcommon/lleventfilter.h +++ b/indra/llcommon/lleventfilter.h @@ -49,6 +49,9 @@ public: /// Post an event to all listeners virtual bool post(const LLSD& event) = 0; + +private: + LLTempBoundListener mSource; }; /** diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index ca0509c524..043ddc904b 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -903,8 +903,6 @@ bool LLVivoxVoiceClient::loginToVivox() LLSD timeoutResult; timeoutResult["login"] = LLSD::String("timeout"); - LLEventTimeout voicePumpTimeout(voicePump); - int loginRetryCount(0); bool response_ok(false); @@ -920,8 +918,7 @@ bool LLVivoxVoiceClient::loginToVivox() send_login = false; - voicePumpTimeout.eventAfter(LOGIN_ATTEMPT_TIMEOUT, timeoutResult); - LLSD result = llcoro::suspendUntilEventOn(voicePump); + LLSD result = llcoro::suspendUntilEventOnWithTimeout(voicePump, LOGIN_ATTEMPT_TIMEOUT, timeoutResult); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; if (result.has("login")) @@ -1018,10 +1015,7 @@ void LLVivoxVoiceClient::logoutOfVivox(bool wait) LLSD timeoutResult; timeoutResult["logout"] = LLSD::String("timeout"); - LLEventTimeout voicePumpTimeout(voicePump); - - voicePumpTimeout.eventAfter(LOGIN_ATTEMPT_TIMEOUT, timeoutResult); - LLSD result = llcoro::suspendUntilEventOn(voicePumpTimeout); + LLSD result = llcoro::suspendUntilEventOnWithTimeout(voicePump, LOGIN_ATTEMPT_TIMEOUT, timeoutResult); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; @@ -1231,12 +1225,9 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) // This is a cheap way to make sure both have happened before proceeding. do { - LLEventTimeout voicePumpTimeout(voicePump); - - voicePumpTimeout.eventAfter(SESSION_JOIN_TIMEOUT, timeoutResult); - result = llcoro::suspendUntilEventOn(voicePumpTimeout); + result = llcoro::suspendUntilEventOnWithTimeout(voicePump, SESSION_JOIN_TIMEOUT, timeoutResult); - LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; + LL_INFOS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; if (result.has("session")) { if (result.has("handle")) @@ -1249,6 +1240,9 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) } std::string message = result["session"].asString(); +// if (message == "joined") +// message = "removed"; + if ((message == "added") || (message == "created")) added = true; else if (message == "joined") @@ -1510,7 +1504,6 @@ bool LLVivoxVoiceClient::runSession(const sessionStatePtr_t &session) timeoutEvent["timeout"] = LLSD::Boolean(true); LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); - LLEventTimeout timeout(voicePump); mIsInChannel = true; mMuteMicDirty = true; @@ -1562,8 +1555,7 @@ bool LLVivoxVoiceClient::runSession(const sessionStatePtr_t &session) sendLocalAudioUpdates(); mIsInitialized = true; - timeout.eventAfter(UPDATE_THROTTLE_SECONDS, timeoutEvent); - LLSD result = llcoro::suspendUntilEventOn(timeout); + LLSD result = llcoro::suspendUntilEventOnWithTimeout(voicePump, UPDATE_THROTTLE_SECONDS, timeoutEvent); if (!result.has("timeout")) // logging the timeout event spams the log LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; if (result.has("session")) @@ -1667,8 +1659,6 @@ int LLVivoxVoiceClient::voiceRecordBuffer() LL_INFOS("Voice") << "Recording voice buffer" << LL_ENDL; LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); - LLEventTimeout timeout(voicePump); - timeout.eventAfter(CAPTURE_BUFFER_MAX_TIME, timeoutResult); LLSD result; captureBufferRecordStartSendMessage(); @@ -1676,7 +1666,7 @@ int LLVivoxVoiceClient::voiceRecordBuffer() do { - result = llcoro::suspendUntilEventOn(voicePump); + result = llcoro::suspendUntilEventOnWithTimeout(voicePump, CAPTURE_BUFFER_MAX_TIME, timeoutResult); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; } while (!result.has("recplay")); @@ -1700,12 +1690,10 @@ int LLVivoxVoiceClient::voicePlaybackBuffer() LL_INFOS("Voice") << "Playing voice buffer" << LL_ENDL; LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); - LLEventTimeout timeout(voicePump); LLSD result; do { - timeout.eventAfter(CAPTURE_BUFFER_MAX_TIME, timeoutResult); captureBufferPlayStartSendMessage(mPreviewVoiceFont); // Store the voice font being previewed, so that we know to restart if it changes. @@ -1716,7 +1704,7 @@ int LLVivoxVoiceClient::voicePlaybackBuffer() // Update UI, should really use a separate callback. notifyVoiceFontObservers(); - result = llcoro::suspendUntilEventOn(timeout); + result = llcoro::suspendUntilEventOnWithTimeout(voicePump, CAPTURE_BUFFER_MAX_TIME, timeoutResult); LL_DEBUGS("Voice") << "event=" << ll_pretty_print_sd(result) << LL_ENDL; } while (!result.has("recplay")); -- cgit v1.3 From 1fa27575113a552ded77bf9f19989c77b677bb7f Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Fri, 22 Apr 2016 15:14:30 -0700 Subject: Debug code snuck in. --- indra/newview/llvoicevivox.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index 043ddc904b..4316db115e 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -1240,8 +1240,6 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) } std::string message = result["session"].asString(); -// if (message == "joined") -// message = "removed"; if ((message == "added") || (message == "created")) added = true; -- cgit v1.3 From dd2311b993d137c538ca57b4360669db6d7fbfa0 Mon Sep 17 00:00:00 2001 From: Rider Linden Date: Tue, 26 Apr 2016 11:56:25 -0700 Subject: MAINT-6336: Put the timeout upstream of the suspending pump and fire the timeout it. Also some cleanup on LLSD construction in vivox. --- indra/llcommon/lleventcoro.cpp | 21 +++++++++--- indra/llcommon/lleventcoro.h | 5 ++- indra/llcommon/lleventfilter.h | 14 +++++++- indra/llcommon/llevents.h | 6 ++++ indra/newview/llvoicevivox.cpp | 77 ++++++++++++++---------------------------- 5 files changed, 65 insertions(+), 58 deletions(-) (limited to 'indra/newview/llvoicevivox.cpp') diff --git a/indra/llcommon/lleventcoro.cpp b/indra/llcommon/lleventcoro.cpp index 44291eb711..c8c43dc334 100755 --- a/indra/llcommon/lleventcoro.cpp +++ b/indra/llcommon/lleventcoro.cpp @@ -229,13 +229,26 @@ LLSD llcoro::postAndSuspend(const LLSD& event, const LLEventPumpOrPumpName& requ return value; } -LLSD llcoro::suspendUntilEventOnWithTimeout(const LLEventPumpOrPumpName& pump, F32 timeoutin, const LLSD &timeoutResult) +LLSD llcoro::suspendUntilEventOnWithTimeout(const LLEventPumpOrPumpName& suspendPumpOrName, + F32 timeoutin, const LLSD &timeoutResult) { - LLEventTimeout timeoutPump(pump); + /** + * The timeout pump is attached upstream of of the waiting pump and will + * pass the timeout event through it. We CAN NOT attach downstream since + * doing so will cause the suspendPump to fire any waiting events immediately + * and they will be lost. This becomes especially problematic with the + * LLEventTimeout(pump) constructor which will also attempt to fire those + * events using the virtual listen_impl method in the not yet fully constructed + * timeoutPump. + */ + LLEventTimeout timeoutPump; + LLEventPump &suspendPump = suspendPumpOrName.getPump(); + + LLTempBoundListener timeoutListener = timeoutPump.listen(suspendPump.getName(), + boost::bind(&LLEventPump::post, &suspendPump, _1)); timeoutPump.eventAfter(timeoutin, timeoutResult); - return llcoro::suspendUntilEventOn(timeoutPump); - + return llcoro::suspendUntilEventOn(suspendPump); } namespace diff --git a/indra/llcommon/lleventcoro.h b/indra/llcommon/lleventcoro.h index 19c68e1f35..87926c692d 100755 --- a/indra/llcommon/lleventcoro.h +++ b/indra/llcommon/lleventcoro.h @@ -147,7 +147,10 @@ LLSD suspendUntilEventOn(const LLEventPumpOrPumpName& pump) return postAndSuspend(LLSD(), LLEventPumpOrPumpName(), pump); } -LLSD suspendUntilEventOnWithTimeout(const LLEventPumpOrPumpName& pump, F32 timeoutin, const LLSD &timeoutResult); +/// Suspend the coroutine until an event is fired on the identified pump +/// or the timeout duration has elapsed. If the timeout duration +/// elapses the specified LLSD is returned. +LLSD suspendUntilEventOnWithTimeout(const LLEventPumpOrPumpName& suspendPumpOrName, F32 timeoutin, const LLSD &timeoutResult); } // namespace llcoro diff --git a/indra/llcommon/lleventfilter.h b/indra/llcommon/lleventfilter.h index 15bac5fd73..66f3c14869 100755 --- a/indra/llcommon/lleventfilter.h +++ b/indra/llcommon/lleventfilter.h @@ -188,7 +188,19 @@ private: Action mAction; }; -/// Production implementation of LLEventTimoutBase +/** + * Production implementation of LLEventTimoutBase. + * + * @NOTE: Caution should be taken when using the LLEventTimeout(LLEventPump &) + * constructor to ensure that the upstream event pump is not an LLEventMaildrop + * or any other kind of store and forward pump which may have events outstanding. + * Using this constructor will cause the upstream event pump to fire any pending + * events and could result in the invocation of a virtual method before the timeout + * has been fully constructed. The timeout should instead be connected upstream + * from the event pump and attached using the listen method. + * See llcoro::suspendUntilEventOnWithTimeout() for an example. + */ + class LL_COMMON_API LLEventTimeout: public LLEventTimeoutBase { public: diff --git a/indra/llcommon/llevents.h b/indra/llcommon/llevents.h index 6175329a9d..ba4fcd766e 100755 --- a/indra/llcommon/llevents.h +++ b/indra/llcommon/llevents.h @@ -616,6 +616,12 @@ public: * a queue. Subsequent attaching listeners will receive stored events from the queue * until a listener indicates that the event has been handled. In order to receive * multiple events from a mail drop the listener must disconnect and reconnect. + * + * @NOTE: When using an LLEventMailDrop (or LLEventQueue) with a LLEventTimeout or + * LLEventFilter attaching the filter downstream using Timeout's constructor will + * cause the MailDrop to discharge any of it's stored events. The timeout should + * instead be connected upstream using its listen() method. + * See llcoro::suspendUntilEventOnWithTimeout() for an example. */ class LL_COMMON_API LLEventMailDrop : public LLEventStream { diff --git a/indra/newview/llvoicevivox.cpp b/indra/newview/llvoicevivox.cpp index 043ddc904b..2654666993 100755 --- a/indra/newview/llvoicevivox.cpp +++ b/indra/newview/llvoicevivox.cpp @@ -900,8 +900,7 @@ bool LLVivoxVoiceClient::loginToVivox() { LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); - LLSD timeoutResult; - timeoutResult["login"] = LLSD::String("timeout"); + LLSD timeoutResult(LLSDMap("login", "timeout")); int loginRetryCount(0); @@ -1012,8 +1011,7 @@ void LLVivoxVoiceClient::logoutOfVivox(bool wait) if (wait) { LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); - LLSD timeoutResult; - timeoutResult["logout"] = LLSD::String("timeout"); + LLSD timeoutResult(LLSDMap("lougout", "timeout")); LLSD result = llcoro::suspendUntilEventOnWithTimeout(voicePump, LOGIN_ATTEMPT_TIMEOUT, timeoutResult); @@ -1216,8 +1214,7 @@ bool LLVivoxVoiceClient::addAndJoinSession(const sessionStatePtr_t &nextSession) bool added(true); bool joined(false); - LLSD timeoutResult; - timeoutResult["session"] = LLSD::String("timeout"); + LLSD timeoutResult(LLSDMap("session", "timeout")); // It appears that I need to wait for BOTH the SessionGroup.AddSession response and the SessionStateChangeEvent with state 4 // before continuing from this state. They can happen in either order, and if I don't wait for both, things can get stuck. @@ -1500,8 +1497,7 @@ bool LLVivoxVoiceClient::runSession(const sessionStatePtr_t &session) notifyParticipantObservers(); notifyVoiceFontObservers(); - LLSD timeoutEvent = LLSD::emptyMap(); - timeoutEvent["timeout"] = LLSD::Boolean(true); + LLSD timeoutEvent(LLSDMap("timeout", LLSD::Boolean(true))); LLEventPump &voicePump = LLEventPumps::instance().obtain("vivoxClientPump"); mIsInChannel = true; @@ -1653,8 +1649,7 @@ void LLVivoxVoiceClient::recordingAndPlaybackMode() int LLVivoxVoiceClient::voiceRecordBuffer() { - LLSD timeoutResult; - timeoutResult["recplay"] = LLSD::String("stop"); + LLSD timeoutResult(LLSDMap("recplay", "stop")); LL_INFOS("Voice") << "Recording voice buffer" << LL_ENDL; @@ -1684,8 +1679,7 @@ int LLVivoxVoiceClient::voiceRecordBuffer() int LLVivoxVoiceClient::voicePlaybackBuffer() { - LLSD timeoutResult; - timeoutResult["recplay"] = LLSD::String("stop"); + LLSD timeoutResult(LLSDMap("recplay", "stop")); LL_INFOS("Voice") << "Playing voice buffer" << LL_ENDL; @@ -2924,11 +2918,9 @@ void LLVivoxVoiceClient::sessionCreateResponse(std::string &requestId, int statu session->mErrorStatusString = statusString; if(session == mAudioSession) { - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["handle"] = LLSD::String(sessionHandle); - vivoxevent["session"] = LLSD::String("failed"); - vivoxevent["reason"] = LLSD::Integer(statusCode); + LLSD vivoxevent(LLSDMap("handle", LLSD::String(sessionHandle)) + ("session", "failed") + ("reason", LLSD::Integer(statusCode))); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); } @@ -2945,10 +2937,8 @@ void LLVivoxVoiceClient::sessionCreateResponse(std::string &requestId, int statu { setSessionHandle(session, sessionHandle); } - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["handle"] = LLSD::String(sessionHandle); - vivoxevent["session"] = LLSD::String("created"); + LLSD vivoxevent(LLSDMap("handle", LLSD::String(sessionHandle)) + ("session", "created")); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); } @@ -2972,10 +2962,8 @@ void LLVivoxVoiceClient::sessionGroupAddSessionResponse(std::string &requestId, session->mErrorStatusString = statusString; if(session == mAudioSession) { - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["handle"] = LLSD::String(sessionHandle); - vivoxevent["session"] = LLSD::String("failed"); + LLSD vivoxevent(LLSDMap("handle", LLSD::String(sessionHandle)) + ("session", "failed")); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); } @@ -2993,10 +2981,8 @@ void LLVivoxVoiceClient::sessionGroupAddSessionResponse(std::string &requestId, setSessionHandle(session, sessionHandle); } - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["handle"] = LLSD::String(sessionHandle); - vivoxevent["session"] = LLSD::String("added"); + LLSD vivoxevent(LLSDMap("handle", LLSD::String(sessionHandle)) + ("session", "added")); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); @@ -3041,9 +3027,7 @@ void LLVivoxVoiceClient::logoutResponse(int statusCode, std::string &statusStrin LL_WARNS("Voice") << "Account.Logout response failure: " << statusString << LL_ENDL; // Should this ever fail? do we care if it does? } - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["logout"] = LLSD::Boolean(true); + LLSD vivoxevent(LLSDMap("logout", LLSD::Boolean(true))); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); } @@ -3058,9 +3042,7 @@ void LLVivoxVoiceClient::connectorShutdownResponse(int statusCode, std::string & mConnected = false; - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["connector"] = LLSD::Boolean(false); + LLSD vivoxevent(LLSDMap("connector", LLSD::Boolean(false))); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); } @@ -3168,10 +3150,8 @@ void LLVivoxVoiceClient::joinedAudioSession(const sessionStatePtr_t &session) // This is the session we're joining. if(mIsJoiningSession) { - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["handle"] = LLSD::String(session->mHandle); - vivoxevent["session"] = LLSD::String("joined"); + LLSD vivoxevent(LLSDMap("handle", LLSD::String(session->mHandle)) + ("session", "joined")); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); @@ -3314,10 +3294,8 @@ void LLVivoxVoiceClient::leftAudioSession(const sessionStatePtr_t &session) { if (mAudioSession == session) { - LLSD vivoxevent = LLSD::emptyMap(); - - vivoxevent["handle"] = LLSD::String(session->mHandle); - vivoxevent["session"] = LLSD::String("removed"); + LLSD vivoxevent(LLSDMap("handle", LLSD::String(session->mHandle)) + ("session", "removed")); LLEventPumps::instance().post("vivoxClientPump", vivoxevent); } @@ -6172,9 +6150,7 @@ void LLVivoxVoiceClient::accountGetSessionFontsResponse(int statusCode, const st { // *TODO: We seem to get multiple events of this type. Should figure a way to advance only after // receiving the last one. - LLSD result = LLSD::emptyMap(); - - result["voice_fonts"] = LLSD::Boolean(true); + LLSD result(LLSDMap("voice_fonts", LLSD::Boolean(true))); LLEventPumps::instance().post("vivoxClientPump", result); } @@ -6347,8 +6323,7 @@ void LLVivoxVoiceClient::recordPreviewBuffer() mCaptureBufferRecording = true; - LLSD result; - result["recplay"] = "record"; + LLSD result(LLSDMap("recplay", "record")); LLEventPumps::instance().post("vivoxClientPump", result); } @@ -6371,8 +6346,7 @@ void LLVivoxVoiceClient::playPreviewBuffer(const LLUUID& effect_id) mPreviewVoiceFont = effect_id; mCaptureBufferPlaying = true; - LLSD result; - result["recplay"] = "playback"; + LLSD result(LLSDMap("recplay", "playback")); LLEventPumps::instance().post("vivoxClientPump", result); } @@ -6381,8 +6355,7 @@ void LLVivoxVoiceClient::stopPreviewBuffer() mCaptureBufferRecording = false; mCaptureBufferPlaying = false; - LLSD result; - result["recplay"] = "quit"; + LLSD result(LLSDMap("recplay", "quit")); LLEventPumps::instance().post("vivoxClientPump", result); } -- cgit v1.3