Skip to content

Commit

Permalink
Add a non-blocking logout method to the NetworkManager
Browse files Browse the repository at this point in the history
  • Loading branch information
TechplexEngineer committed Jun 25, 2015
1 parent de0ce97 commit 962e292
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions OpenMetaverse/NetworkManager.cs
Expand Up @@ -646,6 +646,39 @@ public Simulator Connect(IPEndPoint endPoint, ulong handle, bool setDefault, str
}
}

/// <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>
Expand Down

0 comments on commit 962e292

Please sign in to comment.