diff --git a/src/IrcClient/Channel.cs b/src/IrcClient/Channel.cs index 0ad08c1..2b2c8ab 100644 --- a/src/IrcClient/Channel.cs +++ b/src/IrcClient/Channel.cs @@ -41,9 +41,9 @@ public class Channel { private string _Name; private string _Key = String.Empty; - private Hashtable _Users = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); - private Hashtable _Ops = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); - private Hashtable _Voices = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); + private Hashtable _Users = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); + private Hashtable _Ops = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); + private Hashtable _Voices = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); private StringCollection _Bans = new StringCollection(); private List _BanExcepts = new List(); private List _InviteExcepts = new List(); diff --git a/src/IrcClient/IrcClient.cs b/src/IrcClient/IrcClient.cs index 3d6b7f1..65a788a 100644 --- a/src/IrcClient/IrcClient.cs +++ b/src/IrcClient/IrcClient.cs @@ -67,8 +67,8 @@ public class IrcClient : IrcCommands private bool _MotdReceived; private Array _ReplyCodes = Enum.GetValues(typeof(ReplyCode)); private StringCollection _JoinedChannels = new StringCollection(); - private Hashtable _Channels = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); - private Hashtable _IrcUsers = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); + private Hashtable _Channels = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); + private Hashtable _IrcUsers = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); private List _ChannelList; private Object _ChannelListSyncRoot = new Object(); private AutoResetEvent _ChannelListReceivedEvent; diff --git a/src/IrcClient/NonRfcChannel.cs b/src/IrcClient/NonRfcChannel.cs index 10d94d6..f52ad3f 100644 --- a/src/IrcClient/NonRfcChannel.cs +++ b/src/IrcClient/NonRfcChannel.cs @@ -26,6 +26,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +using System; using System.Collections; using System.Collections.Specialized; @@ -37,9 +38,9 @@ namespace Meebey.SmartIrc4net /// public class NonRfcChannel : Channel { - private Hashtable _Owners = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); - private Hashtable _ChannelAdmins = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); - private Hashtable _Halfops = Hashtable.Synchronized(new Hashtable(new CaseInsensitiveHashCodeProvider(), new CaseInsensitiveComparer())); + private Hashtable _Owners = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); + private Hashtable _ChannelAdmins = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); + private Hashtable _Halfops = Hashtable.Synchronized(new Hashtable(StringComparer.OrdinalIgnoreCase)); /// /// diff --git a/src/IrcConnection/IrcConnection.cs b/src/IrcConnection/IrcConnection.cs index 5efef9a..5f75b83 100644 --- a/src/IrcConnection/IrcConnection.cs +++ b/src/IrcConnection/IrcConnection.cs @@ -1051,54 +1051,54 @@ private void _OnConnectionError(object sender, EventArgs e) } } - /// - /// - /// - private abstract class FiniteThread - { - /// - /// - /// - public Thread Thread { get; internal set; } - - /// - /// - /// - public bool IsStopRequested { get; internal set; } - - /// - /// - /// - public string ThreadName { get; internal set; } - - /// - /// - /// - public void RequestStop() - { - IsStopRequested = true; - } - - protected FiniteThread() - { - IsStopRequested = false; - ThreadName = "(unnamed thread)"; - } - - protected abstract void PrepareStart(); - - protected abstract void Worker(); - - /// - /// - /// - public void Start() { - PrepareStart(); - - Thread = new Thread(Worker) { IsBackground = true, Name = ThreadName}; - Thread.Start(); - } - } + /// + /// + /// + private abstract class FiniteThread + { + /// + /// + /// + public Thread Thread { get; internal set; } + + /// + /// + /// + public bool IsStopRequested { get; internal set; } + + /// + /// + /// + public string ThreadName { get; internal set; } + + /// + /// + /// + public void RequestStop() + { + IsStopRequested = true; + } + + protected FiniteThread() + { + IsStopRequested = false; + ThreadName = "(unnamed thread)"; + } + + protected abstract void PrepareStart(); + + protected abstract void Worker(); + + /// + /// + /// + public void Start() { + PrepareStart(); + + Thread = new Thread(Worker) { IsBackground = true, Name = ThreadName}; + Thread.Start(); + } + } /// /// @@ -1127,15 +1127,15 @@ public ReadThread(IrcConnection connection) { _Connection = connection; QueuedEvent = new AutoResetEvent(false); - ThreadName = "ReadThread ("+_Connection.Address+":"+_Connection.Port+")"; + ThreadName = "ReadThread ("+_Connection.Address+":"+_Connection.Port+")"; } - protected override void PrepareStart() { } + protected override void PrepareStart() { } - protected override void Worker() + protected override void Worker() { #if LOG4NET - Logger.Socket.Debug("ReadThread started"); + Logger.Socket.Debug("ReadThread Worker(): starting"); #endif try { string data = ""; @@ -1148,8 +1148,15 @@ protected override void Worker() Logger.Socket.Debug("received: \""+data+"\""); #endif } +#if LOG4NET + Logger.Socket.Debug("ReadThread Worker(): loop ended"); + Logger.Socket.Debug("ReadThread Worker(): closing reader"); +#endif + _Connection._Reader.Close(); - _Queue.Clear(); + // clean up our receive queue else we continue processing old + // messages when the read thread is restarted! + _Queue.Clear(); } catch (IOException e) { #if LOG4NET Logger.Socket.Warn("IOException: "+e.Message); @@ -1164,11 +1171,6 @@ protected override void Worker() _Connection.IsConnectionError = true; } } - } catch (ThreadAbortException) { - Thread.ResetAbort(); -#if LOG4NET - Logger.Socket.Debug("ReadThread aborted"); -#endif } catch (Exception ex) { #if LOG4NET Logger.Socket.Error(ex); @@ -1206,15 +1208,15 @@ public WriteThread(IrcConnection connection) { _Connection = connection; QueuedEvent = new AutoResetEvent(false); - ThreadName = "WriteThread (" + _Connection.Address + ":" + _Connection.Port + ")"; + ThreadName = "WriteThread (" + _Connection.Address + ":" + _Connection.Port + ")"; } - protected override void PrepareStart() { } + protected override void PrepareStart() { } - protected override void Worker() + protected override void Worker() { #if LOG4NET - Logger.Socket.Debug("WriteThread started"); + Logger.Socket.Debug("WriteThread Worker(): starting"); #endif try { try { @@ -1226,8 +1228,11 @@ protected override void Worker() Thread.Sleep(_Connection._SendDelay); } while (!isBufferEmpty); } - - _Connection._Writer.Close(); +#if LOG4NET + Logger.Socket.Debug("WriteThread Worker(): loop ended"); + Logger.Socket.Debug("WriteThread Worker(): closing writer"); +#endif + _Connection._Writer.Close(); } catch (IOException e) { #if LOG4NET Logger.Socket.Warn("IOException: " + e.Message); @@ -1242,11 +1247,6 @@ protected override void Worker() _Connection.IsConnectionError = true; } } - } catch (ThreadAbortException) { - Thread.ResetAbort(); -#if LOG4NET - Logger.Socket.Debug("WriteThread aborted"); -#endif } catch (Exception ex) { #if LOG4NET Logger.Socket.Error(ex); @@ -1426,7 +1426,7 @@ private class IdleWorkerThread : FiniteThread public IdleWorkerThread(IrcConnection connection) { _Connection = connection; - ThreadName = "IdleWorkerThread ("+_Connection.Address+":"+_Connection.Port+")"; + ThreadName = "IdleWorkerThread ("+_Connection.Address+":"+_Connection.Port+")"; } /// @@ -1439,10 +1439,10 @@ protected override void PrepareStart() _Connection._LastPongReceived = now; } - protected override void Worker() + protected override void Worker() { #if LOG4NET - Logger.Socket.Debug("IdleWorkerThread started"); + Logger.Socket.Debug("IdleWorkerThread Worker(): starting"); #endif try { while (!IsStopRequested && _Connection.IsConnected ) { @@ -1482,10 +1482,8 @@ protected override void Worker() break; } } - } catch (ThreadAbortException) { - Thread.ResetAbort(); #if LOG4NET - Logger.Socket.Debug("IdleWorkerThread aborted"); + Logger.Socket.Debug("IdleWorkerThread Worker(): loop ended"); #endif } catch (Exception ex) { #if LOG4NET