Add a non-blocking logout method to the NetworkManager

This commit is contained in:
Blake Bourque
2015-06-24 20:47:24 -04:00
parent bed881b279
commit 4dd88c5bd5
+33
View File
@@ -646,6 +646,39 @@ namespace OpenMetaverse
}
}
/// <summary>
/// Begins the non-blocking logout. Makes sure that the LoggedOut event is
/// called even if the server does not send a logout reply, and Shutdown()
/// is properly called.
/// </summary>
public void BeginLogout()
{
// Wait for a logout response (by way of the LoggedOut event. If the
// response is received, shutdown will be fired in the callback.
// Otherwise we fire it manually with a NetworkTimeout type after LOGOUT_TIMEOUT
System.Timers.Timer timeout = new System.Timers.Timer();
EventHandler<LoggedOutEventArgs> callback = delegate(object sender, LoggedOutEventArgs e) {
Shutdown(DisconnectType.ClientInitiated);
timeout.Stop();
};
LoggedOut += callback;
timeout.Interval = Client.Settings.LOGOUT_TIMEOUT;
timeout.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e) {
timeout.Stop();
Shutdown(DisconnectType.NetworkTimeout);
OnLoggedOut(new LoggedOutEventArgs(new List<UUID>()));
};
timeout.Start();
// Send the packet requesting a clean logout
RequestLogout();
LoggedOut -= callback;
}
/// <summary>
/// Initiate a blocking logout request. This will return when the logout
/// handshake has completed or when <code>Settings.LOGOUT_TIMEOUT</code>