diff --git a/CHANGELOG.md b/CHANGELOG.md index e9df97d..e29f0dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # statsd-csharp-client Changelog +## v1.2.1.0 +* Fixed a bug in the tcp output channel's retry logic +* Skip DNS resolution on the UDP client if already an IP Address +* Fall back to the Null Output Channel if the client is created with an empty host name. + ## v1.2.0.0 * Support the Raw metric format * A few more unit tests diff --git a/StatsdClient/UdpOutputChannel.cs b/StatsdClient/UdpOutputChannel.cs index a82eaf1..0fad195 100644 --- a/StatsdClient/UdpOutputChannel.cs +++ b/StatsdClient/UdpOutputChannel.cs @@ -12,12 +12,17 @@ namespace StatsdClient private UdpClient _udpClient; public Socket ClientSocket { get { return _udpClient.Client; } } - public UdpOutputChannel(string host, int port) + public UdpOutputChannel(string hostOrIPAddress, int port) { - // Convert to ipv4 address - var ipv4Address = Dns.GetHostAddresses(host).First(p => p.AddressFamily == AddressFamily.InterNetwork); + IPAddress ipAddress; + // Is this an IP address already? + if (!IPAddress.TryParse(hostOrIPAddress, out ipAddress)) + { + // Convert to ipv4 address + ipAddress = Dns.GetHostAddresses(hostOrIPAddress).First(p => p.AddressFamily == AddressFamily.InterNetwork); + } _udpClient = new UdpClient(); - _udpClient.Connect(ipv4Address, port); + _udpClient.Connect(ipAddress, port); } public void Send(string line) diff --git a/StatsdClientTests/StatsdTests.cs b/StatsdClientTests/StatsdTests.cs index 7073838..a4f477d 100644 --- a/StatsdClientTests/StatsdTests.cs +++ b/StatsdClientTests/StatsdTests.cs @@ -168,5 +168,19 @@ namespace StatsdClientTests var statsd = new Statsd("nowhere.here.or.anywhere", 12000); statsd.LogCount("test.stat"); } + + [TestMethod] + public void CreateClient_WithIPAddress_DoesNotError() + { + var statsd = new Statsd("127.0.0.1", 12000); + statsd.LogCount("test.stat"); + } + + [TestMethod] + public void CreateClient_WithInvalidCharactersInHostName_DoesNotError() + { + var statsd = new Statsd("@%)(F(FSDLKDEQ423t0-vbdfb", 12000); + statsd.LogCount("test.foo"); + } } } diff --git a/nuget/StatsdClient.nuspec b/nuget/StatsdClient.nuspec index e6e7aba..1c9c6cc 100644 --- a/nuget/StatsdClient.nuspec +++ b/nuget/StatsdClient.nuspec @@ -2,7 +2,7 @@ StatsdCsharpClient - 1.2.0.0 + 1.2.1.0 Simple Statsd Client for .Net 3.5, 4.0 and 4.5 Luke Venediger Luke Venediger @@ -27,9 +27,9 @@ Licence: MIT - * Support the Raw metric format - * A few more unit tests - * Fixed a bug where you couldn't start up if the host could not be resolved + * Fixed a bug in the tcp output channel's retry logic + * Skip DNS resolution on the UDP client if already an IP Address + * Fall back to the Null Output Channel if the client is created with an empty host name. false Copyright 2013 Luke Venediger