private void Stop(Exception reason) { bool notify = false; lock (m_Sync) { if (m_Active) { Trace(string.Format("Stopping TFTP server '{0}'", m_ServerEndPoint)); m_Active = false; notify = true; m_Socket.Dispose(); // get shallow copy of running sessions var sessions = new List <ITFTPSession>(); lock (m_Sessions) { sessions.AddRange(m_Sessions.Values); } // stop all of them foreach (var session in sessions) { session.Stop(); } Trace("Stopped"); } } if (notify) { var data = new TFTPStopEventArgs(); data.Reason = reason; OnStatusChange(this, data); } }
protected void Stop(bool dally, Exception reason) { bool notify = false; lock (m_Lock) { if (!m_Disposed) { if (m_SessionLog != null) { m_SessionLog.Stop(reason); } m_Disposed = true; m_Timer.Change(Timeout.Infinite, Timeout.Infinite); m_Timer.Dispose(); if (m_OwnSocket) { if (m_Socket != null) { if (dally && m_Socket.SendPending) { DelayedDisposer.QueueDelayedDispose(m_Socket, m_SocketDisposeDelay); } else { m_Socket.Dispose(); } } } if (m_Stream != null) { if (m_Stream.CanWrite) { m_Stream.Flush(); } m_Stream.Close(); m_Stream = null; } notify = true; } } if (notify) { m_Parent.TransferComplete(this, reason); } }