/// <summary> /// Closes this Socket.IO connection. /// </summary> void IManager.Close(bool removeSockets) { if (State == States.Closed || closing) { return; } closing = true; HTTPManager.Logger.Information("SocketManager", "Closing"); HTTPManager.Heartbeats.Unsubscribe(this); // Disconnect the sockets. The Disconnect function will call the Remove function to remove it from the Sockets list. if (removeSockets) { while (Sockets.Count > 0) { (Sockets[Sockets.Count - 1] as ISocket).Disconnect(removeSockets); } } else { for (int i = 0; i < Sockets.Count; ++i) { (Sockets[i] as ISocket).Disconnect(removeSockets); } } // Set to Closed after Socket's Disconnect. This way we can send the disconnect events to the server. State = States.Closed; LastHeartbeat = DateTime.MinValue; if (OfflinePackets != null) { OfflinePackets.Clear(); } // Remove the references from the dictionary too. if (removeSockets) { Namespaces.Clear(); } if (Handshake != null) { Handshake.Abort(); } Handshake = null; if (Transport != null) { Transport.Close(); } Transport = null; closing = false; }
void IManager.Close(bool removeSockets) { if (State != States.Closed && !closing) { closing = true; HTTPManager.Logger.Information("SocketManager", "Closing"); HTTPManager.Heartbeats.Unsubscribe(this); if (removeSockets) { while (Sockets.Count > 0) { ((ISocket)Sockets[Sockets.Count - 1]).Disconnect(removeSockets); } } else { for (int i = 0; i < Sockets.Count; i++) { ((ISocket)Sockets[i]).Disconnect(removeSockets); } } State = States.Closed; LastHeartbeat = DateTime.MinValue; if (OfflinePackets != null) { OfflinePackets.Clear(); } if (removeSockets) { Namespaces.Clear(); } if (Handshake != null) { Handshake.Abort(); } Handshake = null; if (Transport != null) { Transport.Close(); } Transport = null; closing = false; } }