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
This commit is contained in:
Jamie Doornbos
2009-08-05 22:12:16 +00:00
parent 4dc85174ba
commit 5d8a93632e
2 changed files with 30 additions and 7 deletions
@@ -243,6 +243,16 @@ public class Client extends EventDispatcher
return _comm != null && _comm.isConnected(); 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 <code>isLoggedOn() &&
* isConnected()</code>.
*/
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 * Requests that this client connect and logon to the server with which it was previously
* configured. * configured.
@@ -95,6 +95,21 @@ public class Communicator
return _writer != null; 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. * Attempts to logon on using the port at the specified index.
*/ */
@@ -287,13 +302,11 @@ public class Communicator
_portIdx = -1; _portIdx = -1;
// check for a logoff message // check for a logoff message
for each (var message :UpstreamMessage in _outq) { if (hasPendingLogoff()) {
if (message is LogoffRequest) { // don't bother authing, just bail
// don't bother authing, just bail log.info("Logged off prior to socket opening, shutting down");
log.info("Logged off prior to socket opening, shutting down"); shutdown(null);
shutdown(null); return;
return;
}
} }
// send our authentication request (do so directly rather than putting it on the outgoing // send our authentication request (do so directly rather than putting it on the outgoing