From 5d8a93632eee39b2073c96bb9bf83b337f27530a Mon Sep 17 00:00:00 2001 From: Jamie Doornbos Date: Wed, 5 Aug 2009 22:12:16 +0000 Subject: [PATCH] Allow callers to detect when a client is about to die even though it is connected and logged on. This allows handling of the edge case where a client is getting throttled. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5897 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/presents/client/Client.as | 10 +++++++ .../presents/client/Communicator.as | 27 ++++++++++++++----- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/as/com/threerings/presents/client/Client.as b/src/as/com/threerings/presents/client/Client.as index 9edc27cb2..5f890953e 100644 --- a/src/as/com/threerings/presents/client/Client.as +++ b/src/as/com/threerings/presents/client/Client.as @@ -243,6 +243,16 @@ public class Client extends EventDispatcher return _comm != null && _comm.isConnected(); } + /** + * Detects if we have an external logoff request waiting to go through. If the connection is + * being throttled, this may return true even though the client isLoggedOn() && + * isConnected(). + */ + public function isLogoffPending () :Boolean + { + return _switcher == null && _comm != null && _comm.hasPendingLogoff(); + } + /** * Requests that this client connect and logon to the server with which it was previously * configured. diff --git a/src/as/com/threerings/presents/client/Communicator.as b/src/as/com/threerings/presents/client/Communicator.as index fb191c241..1b2e32f9d 100644 --- a/src/as/com/threerings/presents/client/Communicator.as +++ b/src/as/com/threerings/presents/client/Communicator.as @@ -95,6 +95,21 @@ public class Communicator return _writer != null; } + /** + * Detects is the communicator has a logoff request pending, i.e. will logoff in the near + * future. + */ + public function hasPendingLogoff () :Boolean + { + // check for a logoff message + for each (var message :UpstreamMessage in _outq) { + if (message is LogoffRequest) { + return true; + } + } + return false; + } + /** * Attempts to logon on using the port at the specified index. */ @@ -287,13 +302,11 @@ public class Communicator _portIdx = -1; // check for a logoff message - for each (var message :UpstreamMessage in _outq) { - if (message is LogoffRequest) { - // don't bother authing, just bail - log.info("Logged off prior to socket opening, shutting down"); - shutdown(null); - return; - } + if (hasPendingLogoff()) { + // don't bother authing, just bail + log.info("Logged off prior to socket opening, shutting down"); + shutdown(null); + return; } // send our authentication request (do so directly rather than putting it on the outgoing