void Connection_OnClose(TcpXmppConnection e) { lock (this._connections) { this._connections.Remove(e); } }
void Connection_OnOpen(TcpXmppConnection e) { lock (this._connections) { this._connections.Add(e); } }
void AcceptCallback(IAsyncResult ar) { var result = true; try { var client = this._listener.EndAcceptTcpClient(ar); if (client != null) { Task.Factory.StartNew(() => { try { var connection = new TcpXmppConnection(this, client); connection.OnOpen += this.Connection_OnOpen; connection.OnClose += this.Connection_OnClose; connection.Open(); } catch (Exception ex) { _log.Error(ex, "AcceptCallback(): connection error.\n"); } }); } } catch (ObjectDisposedException ex) { result = false; this._log.Fatal(ex); } catch (Exception ex) { this._log.Warn(ex); } finally { if (!this._closed && result) { this._listener.BeginAcceptTcpClient(AcceptCallback, null); } } }