meebey / SmartIrc4net

IRC C# Library
http://www.meebey.net/projects/smartirc4net/
Other
126 stars 52 forks source link

Use System.Diagnostics.Stopwatch to track ping timeouts #43

Closed RavuAlHemio closed 8 years ago

RavuAlHemio commented 8 years ago

Comparing local-time System.DateTime instances with each other is problematic if the UTC offset jumps forward between the two samples, e.g. due to summer time (CET/UTC+1 becomes CEST/UTC+2).

var before = new DateTime(2016, 3, 27, 1, 59, 0, DateTimeKind.Local);
var after = new DateTime(2016, 3, 27, 3, 0, 0, DateTimeKind.Local);
Console.WriteLine(after - before) // 01:01:00

While switching to UTC DateTimes is a possible solution, comparing System.DateTimes in general is problematic if the system date/time is adjusted between the two samples.

Stopwatch uses a monotonic time source which should be unaffected by either. In this PR, IrcConnection is modified to use it for ping timeout tracking.

meebey commented 8 years ago

Thank you for your contribution!